mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-15 14:30:49 +00:00
1.9 KiB
1.9 KiB
SQLite

The package provides an interface to SQLite.
Documentation
Example
Create a table, insert a couple of rows, and fetch one:
let connection = sqlite::open(":memory:").unwrap();
connection.execute("
CREATE TABLE users (name TEXT, age INTEGER);
INSERT INTO users (name, age) VALUES ('Alice', 42);
INSERT INTO users (name, age) VALUES ('Bob', 69);
").unwrap();
connection.process("SELECT * FROM users WHERE age > 50", |pairs| {
for &(column, value) in pairs.iter() {
println!("{} = {}", column, value.unwrap());
}
true
}).unwrap();
The same example using prepared statements:
let connection = sqlite::open(":memory:").unwrap();
connection.execute("
CREATE TABLE users (name TEXT, age INTEGER)
").unwrap();
let mut statement = connection.prepare("
INSERT INTO users (name, age) VALUES (?, ?)
").unwrap();
statement.bind(1, "Alice").unwrap();
statement.bind(2, 42).unwrap();
assert_eq!(statement.step().unwrap(), sqlite::State::Done);
statement.reset().unwrap();
statement.bind(1, "Bob").unwrap();
statement.bind(2, 69).unwrap();
assert_eq!(statement.step().unwrap(), sqlite::State::Done);
let mut statement = connection.prepare("
SELECT * FROM users WHERE age > 50
").unwrap();
while let sqlite::State::Row = statement.step().unwrap() {
println!("id = {}", statement.read::<i64>(0).unwrap());
println!("name = {}", statement.read::<String>(1).unwrap());
}
Contributing
- Fork the project.
- Implement your idea.
- Open a pull request.