Moebius.Query
The main query interface for Moebius. Import this module into your code and query like a champ
Summary
Functions
The main starting point. Currently you specify a table here but, possibly, in the future you can override connection settings
Deletes a record based on your filter
Executes a pass-through query and returns a single result
A basic “WHERE” statement builder that builds an inclusive AND-based where statement
A basic “WHERE” statement builder that builds an IN statement
Executes a function with the given name, passed as an atom
A simple insert. Create your list of data and send it on in
Sets the limit of the return
Offsets the limit - so would produce SQL like “select * from users limit 10 offset 2;”
Executes a given pipeline and returns a list of mapped results
Executes a raw SQL query with paramters
Full text search using Postgres’ built in indexing
Builds the select statement based on what was piped together
Executes a given pipeline and returns a single result as a map
Sets the order by. Ascending using :asc
is the default, you can send in :desc
if you like
Executes the SQL in a given SQL file. Specify this by setting the scripts
directive in the config. Pass the file name as an atom, without extension
A simple update based on the criteria you specify
Functions
The main starting point. Currently you specify a table here but, possibly, in the future you can override connection settings
Deletes a record based on your filter.
Example:
db(:users)
|> filter("id > $1", 1)
|> delete
|> execute
A basic “WHERE” statement builder that builds an inclusive AND-based where statement
Example:
{:ok, res} = db(:users)
|> filter(name: "Mike")
|> select
|> run
A basic “WHERE” statement builder that builds an IN statement
Example:
{:ok, res} = db(:users)
|> filter(:name, in: ["mark", "biff", "skip"])
|> select
|> run
Executes a function with the given name, passed as an atom.
Example:
{:ok, res} = db(:users)
|> function(:all_users, name: "steve")
|> run
A simple insert. Create your list of data and send it on in.
Example:
{:ok, res} = db(:users)
|> insert(email: "test@test.com", first: "Test", last: "User")
|> execute
Sets the limit of the return.
Example:
{:ok, res} = db(:users)
|> limit(20)
|> select
|> run
Offsets the limit - so would produce SQL like “select * from users limit 10 offset 2;”
Example:
{:ok, res} = db(:users)
|> limit(20)
|> offset(2)
|> select
|> run
Full text search using Postgres’ built in indexing.
Example:
{:ok, res} = db(:users)
|> search("Mike", [:first, :last, :email])
|> run
Builds the select statement based on what was piped together
Example:
{:ok, res} = db(:users)
|> limit(20)
|> offset(2)
|> select
|> run
Sets the order by. Ascending using :asc
is the default, you can send in :desc
if you like.
Example:
{:ok, res} = db(:users)
|> filter(id: 1, name: "Steve")
|> sort(:name, :desc)
|> select
|> run
Executes the SQL in a given SQL file. Specify this by setting the scripts
directive in the config. Pass the file name as an atom, without extension.
{:ok, res} = sql_file(:simple, 1)
|> run