sqlitex v1.7.1 Sqlitex.Query View Source

Functions for running queries against a SQLite 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 Sqlitex.Statement module.

Link to this section Summary

Functions

Runs a query and returns the results.

Same as query/3 but raises a Sqlitex.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 Sqlitex.QueryError on error.

Link to this section Functions

Link to this function

query(db, sql, opts \\ []) View Source
query(Sqlitex.connection(), String.t() | charlist(), [{atom(), term()}]) ::
  {:ok, [keyword()]} | {:error, term()}

Runs a query and returns the results.

Parameters

  • db - A SQLite 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 SQLite operations. Defaults to Application.get_env(:sqlitex, :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(:sqlitex, :db_chunk_size) or 5000 ms if not configured.

Returns

  • {:ok, [results...]} on success
  • {:error, _} on failure.
Link to this function

query!(db, sql, opts \\ []) View Source
query!(Sqlitex.connection(), String.t() | charlist(),
  bind: [],
  into: Enum.t(),
  db_timeout: integer()
) :: [Enum.t()]

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

Returns the results otherwise.

Link to this function

query_rows(db, sql, opts \\ []) View Source
query_rows(Sqlitex.connection(), String.t() | charlist(),
  bind: [],
  db_timeout: integer()
) :: {:ok, %{}} | Sqlitex.sqlite_error()

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

Parameters

  • db - A SQLite 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 SQLite operations. Defaults to Application.get_env(:sqlitex, :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(:sqlitex, :db_chunk_size) or 5000 ms if not configured.

Returns

  • {:ok, %{rows: [[1, 2], [2, 3]], columns: [:a, :b], types: [:INTEGER, :INTEGER]}} on success
  • {:error, _} on failure.
Link to this function

query_rows!(db, sql, opts \\ []) View Source
query_rows!(Sqlitex.connection(), String.t() | charlist(),
  bind: [],
  db_timeout: integer()
) :: %{}

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

Returns the results otherwise.