View Source Exqlite.Connection (Exqlite v0.11.8)
This module implements connection details as defined in DBProtocol.
attributes
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
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
@type auto_vacuum() :: :none | :full | :incremental
@type connection_opt() :: {:database, String.t()} | {:journal_mode, journal_mode()} | {:temp_store, temp_store()} | {:synchronous, synchronous()} | {:foreign_keys, :on | :off} | {:cache_size, integer()} | {:cache_spill, :on | :off} | {:case_sensitive_like, boolean()} | {:auto_vacuum, auto_vacuum()} | {:locking_mode, locking_mode()} | {:secure_delete, :on | :off} | {:wal_auto_check_point, integer()} | {:busy_timeout, integer()} | {:chunk_size, integer()} | {:journal_size_limit, integer()} | {:soft_heap_limit, integer()} | {:hard_heap_limit, integer()} | {:key, String.t()}
@type journal_mode() :: :delete | :truncate | :persist | :memory | :wal | :off
@type locking_mode() :: :normal | :exclusive
@type synchronous() :: :extra | :full | :normal | :off
@type t() :: %Exqlite.Connection{ chunk_size: term(), db: Exqlite.Sqlite3.db(), path: String.t(), status: :idle | :busy, transaction_status: :idle | :transaction }
@type temp_store() :: :default | :file | :memory
Link to this section Functions
@spec connect([connection_opt()]) :: {:ok, t()} | {:error, Exception.t()}
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.: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
.: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 documentation 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 is1000
. 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 is2000
.:chunk_size
- The chunk size for bulk fetching. Defaults to50
.:key
- Optional key to set during database initialization. This PRAGMA is often used to set up database level encryption.:journal_size_limit
- The size limit in bytes of the journal.:soft_heap_limit
- The size limit in bytes for the heap limit.:hard_heap_limit
- The size limit in bytes for the heap.
For more information about the options above, see sqlite documentation
Begin a transaction.
For full info refer to sqlite docs: https://sqlite.org/lang_transaction.html
Note: default transaction mode is DEFERRED.
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.