https://github.com/danawanb/libsqlex
Elixir database adapter for libsql/turso
https://github.com/danawanb/libsqlex
Last synced: 14 days ago
JSON representation
Elixir database adapter for libsql/turso
- Host: GitHub
- URL: https://github.com/danawanb/libsqlex
- Owner: danawanb
- Created: 2025-06-08T14:37:24.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-06-10T05:19:59.000Z (9 months ago)
- Last Synced: 2025-12-26T08:54:45.559Z (3 months ago)
- Language: Elixir
- Homepage:
- Size: 10 MB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- trackawesomelist - libsqlex (⭐2) - Libsql driver for Elixir. (Recently Updated / [Jul 29, 2025](/content/2025/07/29/README.md))
- fucking-awesome-elixir - libsqlex - Libsql driver for Elixir. (ORM and Datamapping)
- awesome-elixir - libsqlex - Libsql driver for Elixir. (ORM and Datamapping)
README
# Libsqlex
LibSqlEx is an unofficial Elixir database adapter built on top of Rust NIFs, providing a native driver connection to libSQL/Turso. It supports Local, Remote Replica, and Remote Only modes via configuration options.
⚠️ Currently, it does not support cursor operations such as fetch, declare, and deallocate.
## Installation
the package can be installed
by adding `libsqlex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:libsqlex, "~> 0.1.1"}
]
end
```
## Usage
```elixir
defmodule Example do
alias LibSqlEx.State
def run_query do
# Connect to the database via remote replica
opts = [
uri: System.get_env("LIBSQL_URI"),
auth_token: System.get_env("LIBSQL_TOKEN"),
database: "bar.db",
# false if disable auto sync local and remote
sync: true,
]
case LibSqlEx.connect(opts) do
{:ok, state} ->
# Example: Execute a simple query without transaction
{:ok, result, _state} = LibSqlEx.handle_execute("SELECT 1", [], [], state)
IO.inspect(result, label: "Query Result")
query= "CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT);"
{:ok, create, _state} = LibSqlEx.handle_execute(query, [], [], state)
IO.inspect(create, label: "Create Table Result")
{:ok, insert, _state} = LibSqlEx.handle_execute("INSERT INTO users (name) VALUES (?)", ["Alice"], [], state)
IO.inspect(insert, label: "Insert Table Result")
{:ok, select, _state} = LibSqlEx.handle_execute("SELECT * FROM USERS;", [], [], state)
IO.inspect(select, label: "Select Result")
{:error, reason} ->
IO.puts("Failed to connect: #{inspect(reason)}")
end
end
end
```
## Local Opts
```elixir
opts = [
database: "bar.db",
]
```
## Remote Only Opts
```elixir
opts = [
uri: System.get_env("LIBSQL_URI"),
auth_token: System.get_env("LIBSQL_TOKEN"),
]
```
### Manual Sync
```elixir
defmodule Example do
alias LibSqlEx.State
def run_query do
# Connect to the database via remote replica
opts = [
uri: System.get_env("LIBSQL_URI"),
auth_token: System.get_env("LIBSQL_TOKEN"),
database: "bar.db",
sync: false,
]
case LibSqlEx.connect(opts) do
{:ok, state} ->
{:ok, insert, _state} = LibSqlEx.handle_execute("INSERT INTO users (name) VALUES (?)", ["Alice"], [], state)
IO.inspect(insert, label: "Insert Table Result")
{:ok, _} = LibSqlEx.Native.sync(state);
{:error, reason} ->
IO.puts("Failed to connect: #{inspect(reason)}")
end
end
end
```
.