mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-05-17 01:57:30 +00:00
This pragma is useful for turning off foreign keys as a oneshot operation within current transaction. Example from turso shell: ``` → create table t(id); → create table t2(id, v references t(id)); ``` ``` -- First insert to t2 fails, because t has no row with value (6) → pragma foreign_keys=on; begin; insert into t2 values(5,6); insert into t values (6); commit; Error: SQLite error: FOREIGN KEY constraint failed ``` ``` -- First insert doesn't fail, because checking foreign keys is deferred -- until the transaction finishes → pragma foreign_keys=on; begin; pragma defer_foreign_keys=true; insert into t2 values(5,6); insert into t values (6); commit; OK ```
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.