14 releases

0.2.0 Jan 9, 2024
0.2.0-alpha.1 Jan 8, 2024
0.1.11 Sep 7, 2023
0.1.6 Jul 28, 2023
0.1.0 Nov 26, 2022

#4 in #contributions

Download history 238/week @ 2023-11-07 143/week @ 2023-11-14 185/week @ 2023-11-21 141/week @ 2023-11-28 142/week @ 2023-12-05 126/week @ 2023-12-12 159/week @ 2023-12-19 1592/week @ 2023-12-26 947/week @ 2024-01-02 548/week @ 2024-01-09 528/week @ 2024-01-16 528/week @ 2024-01-23 637/week @ 2024-01-30 539/week @ 2024-02-06 755/week @ 2024-02-13 829/week @ 2024-02-20

2,844 downloads per month
Used in 3 crates

MIT license

320KB
7.5K SLoC

libSQL API for Rust

Crates.io MIT licensed

This repository contains the libSQL API for Rust.

Developing

See DEVELOPING.md for more information.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in libSQL by you, shall be licensed as MIT, without any additional terms or conditions.


lib.rs:

libSQL API for Rust

libSQL is an embeddable SQL database engine based on SQLite. This Rust API is a batteries-included wrapper around the SQLite C API to support transparent replication while retaining compatibility with the SQLite ecosystem, such as the SQL dialect and extensions. If you are building an application in Rust, this is the crate you should use. There are also libSQL language bindings of this Rust crate to other languages such as JavaScript, Python, Go, and C.

Getting Started

To get started, you first need to create a Database object and then open a Connection to it, which you use to query:

use libsql::Database;

let db = Database::open_in_memory().unwrap();
let conn = db.connect().unwrap();
conn.execute("CREATE TABLE IF NOT EXISTS users (email TEXT)", ()).await.unwrap();
conn.execute("INSERT INTO users (email) VALUES ('alice@example.org')", ()).await.unwrap();

Embedded Replicas

Embedded replica is libSQL database that's running in your application process, which keeps a local copy of a remote database. They are useful if you want to move data in the memory space of your application for fast access.

You can open an embedded read-only replica by using the Database::open_with_local_sync constructor:

use libsql::{Database, Frames};

let mut db = Database::open_with_local_sync("/tmp/test.db").await.unwrap();

let frames = Frames::Vec(vec![]);
db.sync_frames(frames).await.unwrap();
let conn = db.connect().unwrap();
conn.execute("SELECT * FROM users", ()).await.unwrap();

WASM

Due to WASM requiring !Send support and the Database type supporting async and using async_trait to abstract between the different database types, we are unable to support WASM via the Database type. Instead, we have provided simpler parallel types in the wasm module that provide access to our remote HTTP protocol in WASM.

Examples

You can find more examples in the examples directory.

Dependencies

~0.7–18MB
~233K SLoC