depo v0.1.0 Depo
Depo is a library designed to provide an intuitive interface for working with SQLite databases in Elixir, inspired in spirit by the SQLite Tcl API.
Depo provides open/1
to create a new Depo.DB
object with which you can interact with the database.
Usage Example
# Open a new in-memory database.
db = Depo.open(:memory)
# Evaluate arbitrary SQL statements that don't return data.
Depo.eval(db, "CREATE TABLE a (n int, t text)")
# Prepare, cache, and register named statements.
Depo.teach(db,
new_b: "INSERT INTO a VALUES(?1, 'b')",
all_a: "SELECT * FROM a",
)
# Group multiple statements in nestable transactions.
Depo.transact(db, fn ->
# Evaluate named statements with bound variables.
for i <- 1..4, do: Depo.update(db, :new_b, i)
end)
Depo.eval(db, :all_a) == [
%{n: 1, t: "b"},
%{n: 2, t: "b"},
%{n: 3, t: "b"},
%{n: 4, t: "b"},
]
Depo.close(db)
Summary
Functions
Safely close the database connection
Evaluate arbitrary SQL statements on the database
Create a new Depo.DB
object to manage a connection
with a new or existing SQLite database
Prepare, cache, and register named SQL statements for more efficient repeated use
Wrap any operations within the given closure in a nestable transaction. If any error occurs within, the transaction will be automatically rolled back
Functions
Create a new Depo.DB
object to manage a connection
with a new or existing SQLite database.
- pass a
path
to open an existing on-disk database - pass
create: path
to create a new on-disk database at the given path - pass
:memory
to create a new in-memory database