Ecto.Adapters.SQL.Query behaviour

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

Types

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

Callbacks

all/1

Specs

Receives a query and must return a SELECT query.

begin_transaction/0

Specs

begin_transaction :: String.t

Command to begin transaction.

commit/0

Specs

commit :: String.t

Command to commit transaction.

delete/4

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/1

Specs

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

Receives a query and must return a DELETE query.

execute_ddl/1

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

insert/4

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/4

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/0

Specs

rollback :: String.t

Command to rollback transaction.

rollback_to_savepoint/1

Specs

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

Command to rollback to savepoint.

savepoint/1

Specs

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

Command to emit savepoint.

to_constraints/1

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/5

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/1

Specs

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

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