View Source Exqlite.Sqlite3 (Exqlite v0.11.8)

The interface to the NIF implementation.

Link to this section Summary

Functions

Get the number of changes recently.

Closes the database and releases any underlying resources.

Disconnect from database and then reopen as an in-memory database based on the serialized binary.

Allow loading native extensions.

Executes an sql script. Multiple stanzas can be passed at once.

Opens a new sqlite database at the Path provided.

Once finished with the prepared statement, call this to release the underlying resources.

Serialize the contents of the database to a binary.

Causes the database connection to free as much memory as it can. This is useful if you are on a memory restricted system.

Link to this section Types

@type db() :: reference()
@type open_opt() :: {:mode, :readwrite | :readonly}
@type reason() :: atom() | String.t()
@type row() :: list()
@type statement() :: reference()

Link to this section Functions

Link to this function

bind(conn, statement, args)

View Source
@spec bind(db(), statement(), nil) :: :ok | {:error, reason()}
@spec bind(db(), statement(), list()) :: :ok | {:error, reason()}
@spec changes(db()) :: {:ok, integer()} | {:error, reason()}

Get the number of changes recently.

Note: If triggers are used, the count may be larger than expected.

See: https://sqlite.org/c3ref/changes.html

@spec close(db() | nil) :: :ok | {:error, reason()}

Closes the database and releases any underlying resources.

Link to this function

columns(conn, statement)

View Source
@spec columns(db(), statement()) :: {:ok, [binary()]} | {:error, reason()}
Link to this function

deserialize(conn, database \\ "main", serialized)

View Source
@spec deserialize(db(), String.t(), binary()) :: :ok | {:error, reason()}

Disconnect from database and then reopen as an in-memory database based on the serialized binary.

Link to this function

enable_load_extension(conn, flag)

View Source
@spec enable_load_extension(db(), boolean()) :: :ok | {:error, reason()}

Allow loading native extensions.

@spec execute(db(), String.t()) :: :ok | {:error, reason()}

Executes an sql script. Multiple stanzas can be passed at once.

Link to this function

fetch_all(conn, statement)

View Source
@spec fetch_all(db(), statement()) :: {:ok, [row()]} | {:error, reason()}
Link to this function

fetch_all(conn, statement, chunk_size)

View Source
@spec fetch_all(db(), statement(), integer()) :: {:ok, [row()]} | {:error, reason()}
@spec last_insert_rowid(db()) :: {:ok, integer()}
Link to this function

multi_step(conn, statement)

View Source
@spec multi_step(db(), statement()) ::
  :busy | {:rows, [row()]} | {:done, [row()]} | {:error, reason()}
Link to this function

multi_step(conn, statement, chunk_size)

View Source
@spec multi_step(db(), statement(), integer()) ::
  :busy | {:rows, [row()]} | {:done, [row()]} | {:error, reason()}
@spec open(String.t(), [open_opt()]) :: {:ok, db()} | {:error, reason()}

Opens a new sqlite database at the Path provided.

path can be ":memory" to keep the sqlite database in memory.

options

Options

  • :mode - use :readwrite to open the database for reading and writing or :readonly to open it in read-only mode. :readwrite will also create the database if it doesn't already exist. Defaults to :readwrite.
@spec prepare(db(), String.t()) :: {:ok, statement()} | {:error, reason()}
Link to this function

release(conn, statement)

View Source
@spec release(db(), statement()) :: :ok | {:error, reason()}

Once finished with the prepared statement, call this to release the underlying resources.

This should be called whenever you are done operating with the prepared statement. If the system has a high load the garbage collector may not clean up the prepared statements in a timely manner and causing higher than normal levels of memory pressure.

If you are operating on limited memory capacity systems, definitely call this.

Link to this function

serialize(conn, database \\ "main")

View Source
@spec serialize(db(), String.t()) :: {:ok, binary()} | {:error, reason()}

Serialize the contents of the database to a binary.

@spec shrink_memory(db()) :: :ok | {:error, reason()}

Causes the database connection to free as much memory as it can. This is useful if you are on a memory restricted system.

@spec step(db(), statement()) :: :done | :busy | {:row, [row()]} | {:error, reason()}
Link to this function

transaction_status(conn)

View Source
@spec transaction_status(db()) :: {:ok, :idle | :transaction}