depo v1.0.0 Depo
Depo provides lightweight storage and querying capabilities in Elixir by providing a minimal and polished API that builds on the unique advantages of SQLite.
You can read about SQLite’s architecture to learn about the SQLite bytecode compiler and other modules within SQLite that you can utilize.
Depo provides create/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.create(:memory)
Depo.write(db, "CREATE TABLE a (n, t)")
# Prepare, cache, and register named statements.
Depo.teach(db,
new_b: "INSERT INTO a VALUES(?1, 'b')",
n2: "SELECT * FROM a WHERE n = 2",
)
# Group multiple statements in nestable transactions.
Depo.transact(db, fn ->
# Write a named statement with bound variables.
for i <- 1..4, do: Depo.write(db, :new_b, i)
end)
Depo.read(db, :n2) == [%{n: 2, t: "b"}]
Depo.close(db)
Summary
Functions
Safely close the database connection
Create a new database and return a new Depo.DB
object to manage the database connection
Open an existing database at path
and return a new
Depo.DB
object to manage the database connection
Synchronously read SQL queries from the 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
Asynchronously write SQL statements to the database. You can pass an atom registered to a cached statement or a string of valid SQL
Write an SQL statement to the database after binding the values to the variables in the statement
Functions
Create a new database and return a new Depo.DB
object to manage the database connection.
You can either:
- pass a
path
to open an existing on-disk database - pass
:memory
to create a new in-memory database
Open an existing database at path
and return a new
Depo.DB
object to manage the database connection.
Prepare, cache, and register named SQL statements for more efficient repeated use.
statements
should be a keyword list, where the keys
are atoms and the values are SQL statements.
Wrap any operations within the given closure in a nestable transaction. If any error occurs within, the transaction will be automatically rolled back.
You can read about SQLite’s transactions in depth in its documentation.
Asynchronously write SQL statements to the database. You can pass an atom registered to a cached statement or a string of valid SQL.