mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-05-19 14:28:14 +00:00
libSQL API for Rust
This repository contains the libSQL API for Rust.
Installation
The library is available on crates.io. To use it in your application, add the following to the Cargo.toml
of your project:
[dependencies]
libsql = "0.1.1"
Getting Started
Connecting to a database
use libsql::Database;
fn main() {
let db = Database::open("hello.db");
let conn = db.connect().unwrap();
let rows = conn.execute("SELECT 'hello, world!'", ()).unwrap().unwrap();
let row = rows.next().unwrap().unwrap();
println!("{}", row.get::<&str>(0).unwrap());
}
Creating a table
conn.execute("CREATE TABLE IF NOT EXISTS users (email TEXT)", ()).unwrap();
Inserting rows into a table
conn.execute("INSERT INTO users (email) VALUES ('alice@example.org')", ()).unwrap();
Querying rows from a table
let rows = conn.execute("SELECT * FROM users WHERE email = ?", params!["alice@example.org"]).unwrap().unwrap();
let row = rows.next().unwrap().unwrap();
println!("{}", row.get::<&str>(0).unwrap());
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.