0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-05-17 01:57:30 +00:00
Files
libsql/libsql
Piotr Sarna 0db03d50a3 query_analysis: allow defer_foreign_keys pragma on primary (#980)
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
```
2024-02-07 14:05:55 -05:00
..
2023-10-16 09:06:25 -07:00
2023-10-16 09:06:25 -07:00
2023-10-16 09:06:25 -07:00

libSQL API for Rust

Crates.io MIT licensed

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.