Ecto v1.1.0 Ecto.Adapters.SQL.Query behaviour

Specifies the behaviour to be implemented by the connection for handling all SQL queries.

Summary

Callbacks

Receives a query and must return a SELECT query

Command to begin transaction

Command to commit transaction

Returns a DELETE for the filters returning the given returning

Receives a query and must return a DELETE query

Receives a DDL command and returns a query that executes it

Returns an INSERT for the given fields in table returning the given returning

Executes the given query with params in connection

Command to rollback transaction

Command to rollback to savepoint

Command to emit savepoint

Receives the exception returned by query/4

Returns an UPDATE for the given fields in table filtered by filters returning the given returning

Receives a query and values to update and must return an UPDATE query

Types

result ::
  {:ok, %{rows: nil | [tuple], num_rows: non_neg_integer}} |
  {:error, Exception.t}

Callbacks

all(arg0)

Specs

Receives a query and must return a SELECT query.

begin_transaction()

Specs

begin_transaction :: String.t

Command to begin transaction.

commit()

Specs

commit :: String.t

Command to commit transaction.

delete(prefix, table, filters, returning)

Specs

delete(prefix :: String.t, table :: String.t, filters :: [atom], returning :: [atom]) :: String.t

Returns a DELETE for the filters returning the given returning.

delete_all(arg0)

Specs

delete_all(Ecto.Query.t) :: String.t

Receives a query and must return a DELETE query.

execute_ddl(arg0)

Receives a DDL command and returns a query that executes it.

insert(prefix, table, fields, returning)

Specs

insert(prefix :: String.t, table :: String.t, fields :: [atom], returning :: [atom]) :: String.t

Returns an INSERT for the given fields in table returning the given returning.

query(pid, query, params, opts)

Specs

query(pid, query :: binary, params :: list, opts :: Keyword.t) :: result

Executes the given query with params in connection.

In case of success, it must return an :ok tuple containing a map with at least two keys:

  • :num_rows - the number of rows affected

  • :rows - the result set as a list. nil may be returned instead of the list if the command does not yield any row as result (but still yields the number of affected rows, like a delete command without returning would)
rollback()

Specs

rollback :: String.t

Command to rollback transaction.

rollback_to_savepoint(savepoint)

Specs

rollback_to_savepoint(savepoint :: String.t) :: String.t

Command to rollback to savepoint.

savepoint(savepoint)

Specs

savepoint(savepoint :: String.t) :: String.t

Command to emit savepoint.

to_constraints(arg0)

Specs

to_constraints(Exception.t) :: Keyword.t

Receives the exception returned by query/4.

The constraints are in the keyword list and must return the constraint type, like :unique, and the constraint name as a string, for example:

[unique: "posts_title_index"]

Must return an empty list if the error does not come from any constraint.

update(prefix, table, fields, filters, returning)

Specs

update(prefix :: String.t, table :: String.t, fields :: [atom], filters :: [atom], returning :: [atom]) :: String.t

Returns an UPDATE for the given fields in table filtered by filters returning the given returning.

update_all(arg0)

Specs

update_all(Ecto.Query.t) :: String.t

Receives a query and values to update and must return an UPDATE query.