sqlitex v1.6.0 Sqlitex.Query View Source

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, [[]]} | {: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.

Returns

  • [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.

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.