All Projects → elixir-sqlite → Sqlitex

elixir-sqlite / Sqlitex

An Elixir wrapper around esqlite. Allows access to sqlite3 databases.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Sqlitex

Sqlite ecto2
Sqlite3 adapter for Ecto 2.2.x
Stars: ✭ 117 (+5.41%)
Mutual labels:  database, sqlite3, hex
Qb
The database toolkit for go
Stars: ✭ 524 (+372.07%)
Mutual labels:  database, sqlite3
Denodb
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Stars: ✭ 498 (+348.65%)
Mutual labels:  database, sqlite3
Perfect Sqlite
A stand-alone Swift wrapper around the SQLite 3 client library.
Stars: ✭ 42 (-62.16%)
Mutual labels:  database, sqlite3
Squeal
A Swift wrapper for SQLite databases
Stars: ✭ 303 (+172.97%)
Mutual labels:  database, sqlite3
Sqlboiler
Generate a Go ORM tailored to your database schema.
Stars: ✭ 4,497 (+3951.35%)
Mutual labels:  database, sqlite3
Android dbinspector
Android library for viewing and sharing in app databases.
Stars: ✭ 881 (+693.69%)
Mutual labels:  database, sqlite3
Pydbgen
Random dataframe and database table generator
Stars: ✭ 191 (+72.07%)
Mutual labels:  database, sqlite3
D2sqlite3
A small wrapper around SQLite for the D programming language
Stars: ✭ 67 (-39.64%)
Mutual labels:  database, sqlite3
Sqlite3 Ocaml
OCaml bindings to the SQLite3 database
Stars: ✭ 77 (-30.63%)
Mutual labels:  database, sqlite3
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+1041.44%)
Mutual labels:  database, sqlite3
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+3390.09%)
Mutual labels:  database, sqlite3
Rsqlite
R interface for SQLite
Stars: ✭ 225 (+102.7%)
Mutual labels:  database, sqlite3
Edge Sql
Cloudflare Workers providing a SQL API
Stars: ✭ 429 (+286.49%)
Mutual labels:  database, sqlite3
Better Sqlite3
The fastest and simplest library for SQLite3 in Node.js.
Stars: ✭ 2,778 (+2402.7%)
Mutual labels:  database, sqlite3
Database rewinder
minimalist's tiny and ultra-fast database cleaner
Stars: ✭ 685 (+517.12%)
Mutual labels:  database, sqlite3
Litetree
SQLite with Branches
Stars: ✭ 1,357 (+1122.52%)
Mutual labels:  database, sqlite3
Quick.db
An easy, open-sourced, Node.js database designed for complete beginners getting into the concept of coding.
Stars: ✭ 177 (+59.46%)
Mutual labels:  database, sqlite3
Choochoo
Training Diary
Stars: ✭ 186 (+67.57%)
Mutual labels:  database, sqlite3
Fluent Sqlite Driver
Fluent driver for SQLite
Stars: ✭ 51 (-54.05%)
Mutual labels:  database, sqlite3

CircleCI Coverage Status Hex.pm Hex.pm

Notice

This library is sparsely maintined. If you are starting a new project, you will probably want to look into using exqlite or it's matching Ecto Adatper ecto_sqlite3

Sqlitex

An Elixir wrapper around esqlite. The main aim here is to provide convenient usage of SQLite databases.

Updated to 1.0

With the 1.0 release, we made just a single breaking change. Sqlitex.Query.query previously returned just the raw query results on success and {:error, reason} on failure. This has been bothering us for a while, so we changed it in 1.0 to return {:ok, results} on success and {:error, reason} on failure. This should make it easier to pattern match on. The Sqlitex.Query.query! function has kept its same functionality of returning bare results on success and raising an error on failure.

Usage

The simple way to use sqlitex is just to open a database and run a query:

Sqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) ->
  Sqlitex.query(db, "SELECT * FROM players ORDER BY id LIMIT 1")
end)
# => [[id: 1, name: "Mikey", created_at: {{2012,10,14},{05,46,28}}, updated_at: {{2013,09,06},{22,29,36}}, type: nil]]

Sqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) ->
  Sqlitex.query(db, "SELECT * FROM players ORDER BY id LIMIT 1", into: %{})
end)
# => [%{id: 1, name: "Mikey", created_at: {{2012,10,14},{05,46,28}}, updated_at: {{2013,09,06},{22,29,36}}, type: nil}]

Pass the bind option to bind parameterized queries.

Sqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) ->
  Sqlitex.query(
    db,
    "INSERT INTO players (name, created_at, updated_at) VALUES (?1, ?2, ?3, ?4)",
    bind: ['Mikey', '2012-10-14 05:46:28.318107', '2013-09-06 22:29:36.610911']
  )
end)
# => [[id: 1, name: "Mikey", created_at: {{2012,10,14},{05,46,28}}, updated_at: {{2013,09,06},{22,29,36}}, type: nil]]

If you want to keep the database open during the lifetime of your project, you can use the Sqlitex.Server GenServer module. Here's a sample from a phoenix projects main supervisor definition.

children = [
  # Start the endpoint when the application starts
  worker(Golf.Endpoint, []),
  worker(Sqlitex.Server, ['golf.sqlite3', [name: Golf.DB]])
]

Now that the GenServer is running you can make queries via

Sqlitex.Server.query(Golf.DB,
                     "SELECT g.id, g.course_id, g.played_at, c.name AS course
                      FROM games AS g
                      INNER JOIN courses AS c ON g.course_id = c.id
                      ORDER BY g.played_at DESC LIMIT 10")

Configuration

Sqlitex uses the Erlang library esqlite which accepts a timeout parameter for almost all interactions with the database. The default value for this timeout is 5000 ms. Many functions in Sqlitex accept a :db_timeout option that is passed on to the esqlite calls and also defaults to 5000 ms. If required, this default value can be overridden globally with the following in your config.exs:

config :sqlitex, db_timeout: 10_000 # or other positive integer number of ms

Another esqlite parameter is :db_chunk_size. This is a count of rows to read from native sqlite and send to erlang process in one bulk. For example, the table mytable has 1000 rows. We make the query to get all rows with db_chunk_size: 500 parameter:

Sqlitex.query(db, "select * from mytable", db_chunk_size: 500)

in this case all rows will be passed from native sqlite OS thread to the erlang process in two passes. Each pass will contain 500 rows.
This parameter decrease overhead of transmitting rows from native OS sqlite thread to the erlang process by chunking list of result rows.
Please, decrease this value if rows are heavy. Default value is 5000.
If you in doubt what to do with this parameter, please, do nothing. Default value is ok.

config :sqlitex, db_chunk_size: 500 # if most of the database rows are heavy

Looking for Ecto?

Check out the SQLite Ecto2 adapter

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].