Crates.io | tokio-sqlite |
lib.rs | tokio-sqlite |
version | 0.1.5 |
source | src |
created_at | 2024-01-24 15:23:05.388783 |
updated_at | 2024-08-27 23:52:37.471374 |
description | Asynchronous SQLite client |
homepage | |
repository | https://github.com/udovin/tokio-sqlite |
max_upload_size | |
id | 1112440 |
size | 44,944 |
use tokio_sqlite::{Connection, Value};
struct Post {
id: i32,
title: String,
author: Option<i64>,
}
#[tokio::main]
async fn main() {
let mut conn = Connection::open(":memory:").await.unwrap();
conn.execute(
"CREATE TABLE post (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
author BIGINT
)",
[],
)
.await
.unwrap();
let post = Post {
id: 1,
title: "tokio-sqlite".into(),
author: None,
};
let mut rows = conn
.query(
"INSERT INTO post (title, author) VALUES ($1, $2) RETURNING id",
[post.title.into(), post.author.into()],
)
.await
.unwrap();
let row = rows.next().await.unwrap().unwrap();
assert_eq!(row.values()[0], Value::Integer(post.id.into()));
}
tokio-sqlite is distributed under the terms of both the MIT license and the Apache 2.0 License.