Exqlite.Connection (Exqlite v0.7.2) View Source

This module imlements connection details as defined in DBProtocol.

Attributes

  • db - The sqlite3 database reference.
  • path - The path that was used to open.
  • transaction_status - The status of the connection. Can be :idle or :transaction.

Unknowns

  • How are pooled connections going to work? Since sqlite3 doesn't allow for simultaneous access. We would need to check if the write ahead log is enabled on the database. We can't assume and set the WAL pragma because the database may be stored on a network volume which would cause potential issues.

Notes:

  • we try to closely follow structure and naming convention of myxql.
  • sqlite thrives when there are many small conventions, so we may not implement some strategies employed by other adapters. See https://sqlite.org/np1queryprob.html

Link to this section Summary

Functions

Initializes the Ecto Exqlite adapter.

Begin a transaction.

Close a query prepared by c:handle_prepare/3 with the database. Return {:ok, result, state} on success and to continue, {:error, exception, state} to return an error and continue, or {:disconnect, exception, state} to return an error and disconnect.

Link to this section Types

Specs

t() :: %Exqlite.Connection{
  chunk_size: term(),
  db: Exqlite.Sqlite3.db(),
  path: String.t(),
  status: :idle | :busy,
  transaction_status: :idle | :transaction
}

Link to this section Functions

Initializes the Ecto Exqlite adapter.

For connection configurations we use the defaults that come with SQLite3, but we recommend which options to choose. We do not default to the recommended because we don't know what your environment is like.

Allowed options:

  • :database - The path to the database. In memory is allowed. You can use :memory or ":memory:" to designate that.
  • :journal_mode - Sets the journal mode for the sqlite connection. Can be one of the following :delete, :truncate, :persist, :memory, :wal, or :off. Defaults to :delete. It is recommended that you use :wal due to support for concurrent reads. Note: :wal does not mean concurrent writes.
  • :temp_store - Sets the storage used for temporary tables. Default is :default. Allowed values are :default, :file, :memory. It is recommended that you use :memory for storage.
  • :synchronous - Can be :extra, :full, :normal, or :off. Defaults to :normal.
  • :foreign_keys - Sets if foreign key checks should be enforced or not. Can be :on or :off. Default is :on.
  • :cache_size - Sets the cache size to be used for the connection. This is an odd setting as a positive value is the number of pages in memory to use and a negative value is the size in kilobytes to use. Default is -2000. It is recommended that you use -64000.
  • :cache_spill - The cache_spill pragma enables or disables the ability of the pager to spill dirty cache pages to the database file in the middle of a transaction. By default it is :on, and for most applications, it should remain so.
  • :case_sensitive_like
  • :auto_vacuum - Defaults to :none. Can be :none, :full or :incremental. Depending on the database size, :incremental may be beneficial.
  • :locking_mode - Defaults to :normal. Allowed values are :normal or :exclusive. See sqlite documenation for more information.
  • :secure_delete - Defaults to :off. If enabled, it will cause SQLite3 to overwrite records that were deleted with zeros.
  • :wal_auto_check_point - Sets the write-ahead log auto-checkpoint interval. Default is 1000. Setting the auto-checkpoint size to zero or a negative value turns auto-checkpointing off.
  • :busy_timeout - Sets the busy timeout in milliseconds for a connection. Default is 2000.
  • :chunk_size - The chunk size for bulk fetching. Defaults to 50.

For more information about the options above, see sqlite documenation

Link to this function

handle_begin(options, state)

View Source

Begin a transaction.

For full info refer to sqlite docs: https://sqlite.org/lang_transaction.html

Note: default transaction mode is DEFERRED.

Link to this function

handle_close(query, opts, state)

View Source

Close a query prepared by c:handle_prepare/3 with the database. Return {:ok, result, state} on success and to continue, {:error, exception, state} to return an error and continue, or {:disconnect, exception, state} to return an error and disconnect.

This callback is called in the client process.

Link to this function

maybe_put_command(query, options)

View Source