Sqlcx.Query (sqlcx v1.2.0) View Source

Functions for running queries against a SQLCipher database.

These query functions handle details such as preparing a statement, binding values, etc. If you need to deal with these details on your own, please take a look at the Sqlcx.Statement module.

Link to this section Summary

Functions

Runs a query and returns the results.

Same as query/3 but raises a Sqlcx.QueryError on error.

Runs a query and returns the results as a list of rows each represented as a list of column values.

Same as query_rows/3 but raises a Sqlcx.QueryError on error.

Link to this section Types

Specs

query_option() ::
  {:bind, [term()]}
  | {:into, Enum.t()}
  | {:db_timeout, pos_integer()}
  | {:db_chunk_size, pos_integer()}

Link to this section Functions

Link to this function

query(db, sql, opts \\ [])

View Source

Specs

query(Sqlcx.connection(), String.t() | charlist(), [query_option()]) ::
  {:ok, [keyword()]} | {:error, term()}

Runs a query and returns the results.

Parameters

  • db - An SQLCipher database.
  • sql - The query to run as a string.
  • opts - Options to pass into the query. See below for details.

Options

  • bind - If your query has parameters in it, you should provide the options to bind as a list.
  • into - The collection to put results into. This defaults to a list.
  • db_timeout - The timeout (in ms) to apply to each of the underlying SQLCipher operations. Defaults to Application.get_env(:sqlcx, :db_timeout) or 5000 ms if not configured.
  • db_chunk_size - The number of rows to read from native sqlite and send to erlang process in one bulk. Defaults to Application.get_env(:sqlcx, :db_chunk_size) or 5000 ms if not configured.

Returns

  • on success
  • on failure.
Link to this function

query!(db, sql, opts \\ [])

View Source

Specs

query!(Sqlcx.connection(), String.t() | charlist(), [query_option()]) :: [
  Enum.t()
]

Same as query/3 but raises a Sqlcx.QueryError on error.

Returns the results otherwise.

Link to this function

query_rows(db, sql, opts \\ [])

View Source

Specs

query_rows(Sqlcx.connection(), String.t() | charlist(), [query_option()]) ::
  {:ok, %{}} | Sqlcx.sqlite_error()

Runs a query and returns the results as a list of rows each represented as a list of column values.

Parameters

  • db - An SQLCipher database.
  • sql - The query to run as a string.
  • opts - Options to pass into the query. See below for details.

Options

  • bind - If your query has parameters in it, you should provide the options to bind as a list.
  • db_timeout - The timeout (in ms) to apply to each of the underlying SQLCipher operations. Defaults to Application.get_env(:sqlcx, :db_timeout) or 5000 ms if not configured.
  • db_chunk_size - The number of rows to read from native sqlite and send to erlang process in one bulk. Defaults to Application.get_env(:sqlcx, :db_chunk_size) or 5000 ms if not configured.

Returns

  • } on success
  • on failure.
Link to this function

query_rows!(db, sql, opts \\ [])

View Source

Specs

query_rows!(Sqlcx.connection(), String.t() | charlist(), [query_option()]) ::
  %{}

Same as query_rows/3 but raises a Sqlcx.QueryError on error.

Returns the results otherwise.