All Projects → elixir-sqlite → exqlite

elixir-sqlite / exqlite

Licence: MIT license
An SQLite3 driver for Elixir

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to exqlite

Python-Course
🐍 This is the most complete course in Python, completely practical and all the lessons are explained with examples, so that they can be easily understood. 🍫
Stars: ✭ 18 (-85.94%)
Mutual labels:  sqlite3
migration
Simple library writen in PHP without framework dependancy for database version control. Supports Sqlite, MySql, Sql Server and Postgres
Stars: ✭ 142 (+10.94%)
Mutual labels:  sqlite3
turkiye-il-ilce-sokak-mahalle-veri-tabani
https://adres.nvi.gov.tr/ adresinde yer alan tüm İl - İlçe - Mahalle / Köy / Mezra / Mevki - CSBM bilgilerini içeren veri tabanları (PostgreSQL, MariaDB / MySQL, MongoDB, Sqlite ve Redis)
Stars: ✭ 71 (-44.53%)
Mutual labels:  sqlite3
TIWAP
Totally Insecure Web Application Project (TIWAP)
Stars: ✭ 137 (+7.03%)
Mutual labels:  sqlite3
elixir-revisionair ecto
A Revisionair adapter based on Ecto. Allows you to persist and keep track of revisions of your data structures in any of Ecto's supported databases.
Stars: ✭ 18 (-85.94%)
Mutual labels:  ecto
watchdb
Keeping SQLite databases in sync
Stars: ✭ 72 (-43.75%)
Mutual labels:  sqlite3
sqxx
Lightweight C++ 11 library for SQLite
Stars: ✭ 33 (-74.22%)
Mutual labels:  sqlite3
Proffy
👥 Plataforma de estudos online, onde é possível conectar alunos com professores. Este é um projeto que foi desenvolvido durante a Next Level Week #2 da @Rocketseat, durante os dias 3 à 7 de agosto de 2020.
Stars: ✭ 12 (-90.62%)
Mutual labels:  sqlite3
ecto nested changeset
Helpers for manipulating nested Ecto changesets
Stars: ✭ 23 (-82.03%)
Mutual labels:  ecto
Malicious-Urlv5
A multi-layered and multi-tiered Machine Learning security solution, it supports always on detection system, Django REST framework used, equipped with a web-browser extension that uses a REST API call.
Stars: ✭ 35 (-72.66%)
Mutual labels:  sqlite3
embedio-extras
Additional Modules showing how to extend EmbedIO.
Stars: ✭ 43 (-66.41%)
Mutual labels:  sqlite3
sqlite3
pure-Go sqlite3 file reader
Stars: ✭ 120 (-6.25%)
Mutual labels:  sqlite3
roundup
un-official mirror of http://hg.code.sf.net/p/roundup/code -- used for CI. Please visit https://issues.roundup-tracker.org for finding starter issues or log new issues.
Stars: ✭ 20 (-84.37%)
Mutual labels:  sqlite3
etiquette
WIP tag-based file organizer & search
Stars: ✭ 27 (-78.91%)
Mutual labels:  sqlite3
hierarch
Tree structure & hierarchy for ecto models with ltree(Postgres)
Stars: ✭ 30 (-76.56%)
Mutual labels:  ecto
Clerk
Personal finance application based on double entry system.
Stars: ✭ 12 (-90.62%)
Mutual labels:  sqlite3
doclite
PHP NoSQL database and document store
Stars: ✭ 57 (-55.47%)
Mutual labels:  sqlite3
sqlite-gui
Lightweight SQLite editor for Windows
Stars: ✭ 151 (+17.97%)
Mutual labels:  sqlite3
dreamy-db
🔥 Dreamy-db - A Powerful database for storing, accessing, and managing multiple database.
Stars: ✭ 25 (-80.47%)
Mutual labels:  sqlite3
bftdb
Tendermint + Sqlite3 = BFT Database Replication
Stars: ✭ 35 (-72.66%)
Mutual labels:  sqlite3

Exqlite

Build Status Hex Package Hex Docs

An Elixir SQLite3 library.

If you are looking for the Ecto adapater, take a look at the Ecto SQLite3 library.

Documentation: https://hexdocs.pm/exqlite Package: https://hex.pm/packages/exqlite

Caveats

  • Prepared statements are not cached.
  • Prepared statements are not immutable. You must be careful when manipulating statements and binding values to statements. Do not try to manipulate the statements concurrently. Keep it isolated to one process.
  • Simultaneous writing is not supported by SQLite3 and will not be supported here.
  • All native calls are run through the Dirty NIF scheduler.
  • Datetimes are stored without offsets. This is due to how SQLite3 handles date and times. If you would like to store a timezone, you will need to create a second column somewhere storing the timezone name and shifting it when you get it from the database. This is more reliable than storing the offset as +03:00 as it does not respect daylight savings time.

Installation

defp deps do
  [
    {:exqlite, "~> 0.11.3"}
  ]
end

Configuration

config :exqlite, default_chunk_size: 100
  • default_chunk_size - The chunk size that is used when multi-stepping when not specifying the chunk size explicitly.

Advanced Configuration

Using System Installed Libraries

This will vary depending on the operating system.

# tell exqlite that we wish to use some other sqlite installation. this will prevent sqlite3.c and friends from compiling
export EXQLITE_USE_SYSTEM=1

# Tell exqlite where to find the `sqlite3.h` file
export EXQLITE_SYSTEM_CFLAGS=-I/usr/include

# tell exqlite which sqlite implementation to use
export EXQLITE_SYSTEM_LDFLAGS=-L/lib -lsqlite3

After exporting those variables you can then invoke mix deps.compile. Note if you re-export those values, you will need to recompile the exqlite dependency in order to pickup those changes.

Database Encryption

As of version 0.9, exqlite supports loading database engines at runtime rather than compiling sqlite3.c itself. This can be used to support database level encryption via alternate engines such as SQLCipher or the Official SEE extension. Once you have either of those projects installed on your system, use the following environment variables during compilation:

# tell exqlite that we wish to use some other sqlite installation. this will prevent sqlite3.c and friends from compiling
export EXQLITE_USE_SYSTEM=1

# Tell exqlite where to find the `sqlite3.h` file
export EXQLITE_SYSTEM_CFLAGS=-I/usr/local/include/sqlcipher

# tell exqlite which sqlite implementation to use
export EXQLITE_SYSTEM_LDFLAGS=-L/usr/local/lib -lsqlcipher

Once you have exqlite configured, you can use the :key option in the database config to enable encryption:

config :exqlite, key: "super-secret'

Usage

The Exqlite.Sqlite3 module usage is fairly straight forward.

# We'll just keep it in memory right now
{:ok, conn} = Exqlite.Sqlite3.open(":memory:")

# Create the table
:ok = Exqlite.Sqlite3.execute(conn, "create table test (id integer primary key, stuff text)")

# Prepare a statement
{:ok, statement} = Exqlite.Sqlite3.prepare(conn, "insert into test (stuff) values (?1)")
:ok = Exqlite.Sqlite3.bind(conn, statement, ["Hello world"])

# Step is used to run statements
:done = Exqlite.Sqlite3.step(conn, statement)

# Prepare a select statement
{:ok, statement} = Exqlite.Sqlite3.prepare(conn, "select id, stuff from test")

# Get the results
{:row, [1, "Hello world"]} = Exqlite.Sqlite3.step(conn, statement)

# No more results
:done = Exqlite.Sqlite3.step(conn, statement)

# Release the statement.
#
# It is recommended you release the statement after using it to reclaim the memory
# asap, instead of letting the garbage collector eventually releasing the statement.
#
# If you are operating at a high load issuing thousands of statements, it would be
# possible to run out of memory or cause a lot of pressure on memory.
:ok = Exqlite.Sqlite3.release(conn, statement)

Using SQLite3 native extensions

Exqlite supports loading run-time loadable SQLite3 extensions. A selection of precompiled extensions for popular CPU types / architectures is available by installing the ExSqlean package. This package wraps SQLean: all the missing SQLite functions.

alias Exqlite.Basic
{:ok, conn} = Basic.open("db.sqlite3")
:ok = Basic.enable_load_extension(conn)

# load the regexp extension - https://github.com/nalgeon/sqlean/blob/main/docs/re.md
Basic.load_extension(conn, ExSqlean.path_for("re"))

# run some queries to test the new `regexp_like` function
{:ok, [[1]], ["value"]} = Basic.exec(conn, "select regexp_like('the year is 2021', ?) as value", ["2021"]) |> Basic.rows()
{:ok, [[0]], ["value"]} = Basic.exec(conn, "select regexp_like('the year is 2021', ?) as value", ["2020"]) |> Basic.rows()

# prevent loading further extensions
:ok = Basic.disable_load_extension(conn)
{:error, %Exqlite.Error{message: "not authorized"}, _} = Basic.load_extension(conn, ExSqlean.path_for("re"))

# close connection
Basic.close(conn)

Why SQLite3

I needed an Ecto3 adapter to store time series data for a personal project. I didn't want to go through the hassle of trying to setup a postgres database or mysql database when I was just wanting to explore data ingestion and some map reduce problems.

I also noticed that other SQLite3 implementations didn't really fit my needs. At some point I also wanted to use this with a nerves project on an embedded device that would be resiliant to power outages and still maintain some state that ets can not afford.

Under The Hood

We are using the Dirty NIF scheduler to execute the sqlite calls. The rationale behind this is that maintaining each sqlite's connection command pool is complicated and error prone.

Contributing

Feel free to check the project out and submit pull requests.

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].