plasm v0.4.0 Plasm

Summary

Functions

Builds an avg query for a given field

Builds a count query

Builds a distinct count query for a given field

Builds a distinct query for a given field

Builds a query that finds all records matching any of the primary key values in the provided list or value

Builds a query that finds the first record after sorting by inserted_at ascending

Builds a query that finds all records inserted after a specified %Ecto.DateTime{}

Builds a query that finds all records inserted on or after a specified %Ecto.DateTime{}

Builds a query that finds all records inserted before a specified %Ecto.DateTime{}

Builds a query that finds all records inserted on or before a specified %Ecto.DateTime{}

Builds a query that finds the last record after sorting by inserted_at ascending

Builds a max query for a given field

Builds a min query for a given field

Builds a query that grabs a random record

Builds a sum query for a given field

Builds a query that finds all records updated after a specified %Ecto.DateTime{}

Builds a query that finds all records updated on or after a specified %Ecto.DateTime{}

Builds a query that finds all records updated before a specified %Ecto.DateTime{}

Builds a query that finds all records updated on or before a specified %Ecto.DateTime{}

Builds a query that finds all records matching all specified field names and values

Builds a query that finds all records matching none of the specified field names and values

Functions

avg(query, field_name)

Specs

avg(Ecto.Queryable, atom) :: Ecto.Queryable
avg(Ecto.Queryable, String.t) :: Ecto.Queryable

Builds an avg query for a given field.

Puppy |> Plasm.avg(:age) |> Repo.one

Puppy |> Plasm.avg("age") |> Repo.one
count(query)

Specs

count(Ecto.Queryable) :: Ecto.Queryable

Builds a count query.

Puppy |> Plasm.count |> Repo.one
count_distinct(query, field_name)

Specs

count_distinct(Ecto.Queryable, atom) :: Ecto.Queryable
count_distinct(Ecto.Queryable, String.t) :: Ecto.Queryable

Builds a distinct count query for a given field.

Puppy |> Plasm.count_distinct(:name) |> Repo.one

Puppy |> Plasm.count_distinct("age") |> Repo.one
distinct_by(query, field_name)

Specs

distinct_by(Ecto.Queryable, atom) :: Ecto.Queryable
distinct_by(Ecto.Queryable, String.t) :: Ecto.Queryable

Builds a distinct query for a given field.

Puppy |> Plasm.distinct_by(:age) |> Repo.all

Puppy |> Plasm.distinct_by("name") |> Repo.all
find(query, primary_key_values)

Specs

find(Ecto.Queryable, any) :: Ecto.Queryable
find(Ecto.Queryable, list) :: Ecto.Queryable

Builds a query that finds all records matching any of the primary key values in the provided list or value.

Puppy |> Plasm.find([1,2,3]) |> Repo.all

Puppy |> Plasm.find(10) |> Repo.one

Puppy |> Plasm.find("748192739812839") |> Repo.one
first_inserted(query)

Specs

first_inserted(Ecto.Queryable) :: Ecto.Queryable

Builds a query that finds the first record after sorting by inserted_at ascending.

Optionally, provide an integer n to find only the first n records.

Puppy |> Plasm.first |> Repo.one

Puppy |> Plasm.first(20) |> Repo.all
first_inserted(query, n)

Specs

first_inserted(Ecto.Queryable, integer) :: Ecto.Queryable
inserted_after(query, ecto_date_time)

Specs

inserted_after(Ecto.Queryable, any) :: Ecto.Queryable
inserted_after(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable
inserted_after(Ecto.Queryable, any) :: Ecto.Queryable
inserted_after(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable

Builds a query that finds all records inserted after a specified %Ecto.DateTime{}.

Puppy |> Plasm.inserted_after(ecto_date_time) |> Repo.all

Puppy |> Plasm.inserted_after("2014-04-17T14:00:00Z") |> Repo.all
inserted_after_incl(query, ecto_date_time)

Builds a query that finds all records inserted on or after a specified %Ecto.DateTime{}.

Puppy |> Plasm.inserted_after_incl(ecto_date_time) |> Repo.all

Puppy |> Plasm.inserted_after_incl("2014-04-17T14:00:00Z") |> Repo.all
inserted_before(query, ecto_date_time)

Specs

inserted_before(Ecto.Queryable, any) :: Ecto.Queryable
inserted_before(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable

Builds a query that finds all records inserted before a specified %Ecto.DateTime{}.

Puppy |> Plasm.inserted_before(ecto_date_time) |> Repo.all

Puppy |> Plasm.inserted_before("2014-04-17T14:00:00Z") |> Repo.all
inserted_before_incl(query, ecto_date_time)

Specs

inserted_before_incl(Ecto.Queryable, any) :: Ecto.Queryable
inserted_before_incl(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable

Builds a query that finds all records inserted on or before a specified %Ecto.DateTime{}.

Puppy |> Plasm.inserted_before_incl(ecto_date_time) |> Repo.all

Puppy |> Plasm.inserted_before_incl("2014-04-17T14:00:00Z") |> Repo.all
last_inserted(query)

Specs

last_inserted(Ecto.Queryable) :: Ecto.Queryable

Builds a query that finds the last record after sorting by inserted_at ascending.

Optionally, provide an integer n to find only the last n records.

Puppy |> Plasm.last |> Repo.one

Puppy |> Plasm.last(20) |> Repo.all
last_inserted(query, n)

Specs

last_inserted(Ecto.Queryable, integer) :: Ecto.Queryable
max(query, field_name)

Specs

max(Ecto.Queryable, atom) :: Ecto.Queryable
max(Ecto.Queryable, String.t) :: Ecto.Queryable

Builds a max query for a given field.

Puppy |> Plasm.max(:age) |> Repo.one

Puppy |> Plasm.max("age") |> Repo.one
min(query, field_name)

Specs

min(Ecto.Queryable, atom) :: Ecto.Queryable
min(Ecto.Queryable, String.t) :: Ecto.Queryable

Builds a min query for a given field.

Puppy |> Plasm.min(:age) |> Repo.one

Puppy |> Plasm.min("age") |> Repo.one
random(query)

Specs

random(Ecto.Queryable) :: Ecto.Queryable

Builds a query that grabs a random record.

Optionally, provide an integer n to fetch n random records.

Puppy |> Plasm.random |> Repo.one

Puppy |> Plasm.random(20) |> Repo.all
random(query, n)

Specs

random(Ecto.Queryable, integer) :: Ecto.Queryable
sum(query, field_name)

Specs

sum(Ecto.Queryable, atom) :: Ecto.Queryable
sum(Ecto.Queryable, String.t) :: Ecto.Queryable

Builds a sum query for a given field.

Puppy |> Plasm.sum(:age) |> Repo.one

Puppy |> Plasm.sum("age") |> Repo.one
updated_after(query, ecto_date_time)

Specs

updated_after(Ecto.Queryable, any) :: Ecto.Queryable
updated_after(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable

Builds a query that finds all records updated after a specified %Ecto.DateTime{}.

Puppy |> Plasm.updated_after(ecto_date_time) |> Repo.all

Puppy |> Plasm.updated_after("2014-04-17T14:00:00Z") |> Repo.all
updated_after_incl(query, ecto_date_time)

Specs

updated_after_incl(Ecto.Queryable, any) :: Ecto.Queryable
updated_after_incl(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable

Builds a query that finds all records updated on or after a specified %Ecto.DateTime{}.

Puppy |> Plasm.updated_after_incl(ecto_date_time) |> Repo.all

Puppy |> Plasm.updated_after_incl("2014-04-17T14:00:00Z") |> Repo.all
updated_before(query, ecto_date_time)

Specs

updated_before(Ecto.Queryable, any) :: Ecto.Queryable
updated_before(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable

Builds a query that finds all records updated before a specified %Ecto.DateTime{}.

Puppy |> Plasm.updated_before(ecto_date_time) |> Repo.all

Puppy |> Plasm.updated_before("2014-04-17T14:00:00Z") |> Repo.all
updated_before_incl(query, ecto_date_time)

Specs

updated_before_incl(Ecto.Queryable, any) :: Ecto.Queryable
updated_before_incl(Ecto.Queryable, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}) :: Ecto.Queryable

Builds a query that finds all records updated on or before a specified %Ecto.DateTime{}.

Puppy |> Plasm.updated_before_incl(ecto_date_time) |> Repo.all

Puppy |> Plasm.updated_before_incl("2014-04-17T14:00:00Z") |> Repo.all
where_all(query, field_names_and_values)

Specs

where_all(Ecto.Queryable, list) :: Ecto.Queryable
where_all(Ecto.Queryable, list) :: Ecto.Queryable

Builds a query that finds all records matching all specified field names and values.

Values can be lists or non-lists.

When the values are all non-lists, it simply delegates to Ecto.Query.where.

When there is at least one list value, it builds the query itself, using in for lists.

Puppy |> Plasm.where_all(name: "Fluffy", age: 3) |> Repo.all

Puppy |> Plasm.where_all(name: "Fluffy", age: [3,5,10]) |> Repo.all
where_none(query, field_names_and_values)

Builds a query that finds all records matching none of the specified field names and values.

Values can be lists or non-lists.

Non-list expressions result in a != comparison.

List expressions result in a not in comparison.

Puppy |> Plasm.where_none(name: "Fluffy", age: 3) |> Repo.all

Puppy |> Plasm.where_none(name: "Fluffy", age: [3,5,10]) |> Repo.all