6 releases
0.1.5 | Aug 27, 2024 |
---|---|
0.1.4 | Mar 22, 2024 |
0.1.3 | Feb 7, 2024 |
0.1.2 | Jan 25, 2024 |
#1618 in Database interfaces
29 downloads per month
20KB
492 lines
tokio-sqlite
Usage
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()));
}
License
tokio-sqlite is distributed under the terms of both the MIT license and the Apache 2.0 License.
Dependencies
~30MB
~471K SLoC