sqlitex v1.2.0 Sqlitex

Sqlitex gives you a way to create and query sqlite databases.

Basic Example

iex> {:ok, db} = Sqlitex.open(":memory:")
iex> Sqlitex.exec(db, "CREATE TABLE t (a INTEGER, b INTEGER, c INTEGER)")
:ok
iex> Sqlitex.exec(db, "INSERT INTO t VALUES (1, 2, 3)")
:ok
iex> Sqlitex.query(db, "SELECT * FROM t")
{:ok, [[a: 1, b: 2, c: 3]]}
iex> Sqlitex.query(db, "SELECT * FROM t", into: %{})
{:ok, [%{a: 1, b: 2, c: 3}]}

Summary

Functions

Create a new table name where table_opts are a list of table constraints and cols are a keyword list of columns. The following table constraints are supported: :temp and :primary_key. Example

Types

connection()
connection() :: {:connection, reference, String.t}
sqlite_error()
sqlite_error() :: {:error, {:sqlite_error, charlist}}
string_or_charlist()
string_or_charlist() :: String.t | charlist

Functions

close(db)
close(connection) :: :ok
create_table(db, name, table_opts \\ [], cols)

Create a new table name where table_opts are a list of table constraints and cols are a keyword list of columns. The following table constraints are supported: :temp and :primary_key. Example:

[:temp, {:primary_key, [:id]}]

Columns can be passed as:

  • name: :type
  • name: {:type, constraints}

where constraints is a list of column constraints. The following column constraints are supported: :primary_key, :not_null and :autoincrement. Example:

id: :integer, name: {:text, [:not_null]}

exec(db, sql)
open(path)
open(String.t) :: {:ok, connection}
open(charlist) ::
  {:ok, connection} |
  {:error, {atom, charlist}}
query(db, sql, opts \\ [])
query!(db, sql, opts \\ [])
query_rows(db, sql, opts \\ [])
query_rows!(db, sql, opts \\ [])
with_db(path, fun)