1
0
mirror of https://github.com/fluencelabs/sqlite-wasm-connector synced 2025-04-06 00:11:04 +00:00

29 lines
674 B
Rust
Raw Normal View History

2015-05-29 09:25:39 -04:00
extern crate sqlite;
use std::path::PathBuf;
fn main() {
let path = setup();
let database = sqlite::open(&path).unwrap();
2015-05-29 09:25:39 -04:00
database.instruct(r#"
2015-05-29 09:25:39 -04:00
CREATE TABLE `users` (id INTEGER, name VARCHAR(255));
INSERT INTO `users` (id, name) VALUES (1, 'Alice');
"#).unwrap();
2015-05-29 09:25:39 -04:00
database.iterate("SELECT * FROM `users`;", |pairs| {
2015-05-29 09:25:39 -04:00
for (ref column, ref value) in pairs {
println!("{} = {}", column, value);
}
true
}).unwrap();
2015-05-29 09:25:39 -04:00
}
fn setup() -> PathBuf {
let path = PathBuf::from("database.sqlite3");
if std::fs::metadata(&path).is_ok() {
std::fs::remove_file(&path).unwrap();
}
path
}