ryzz
ryzz is an automatic migration generator and query builder for sqlite in rust.
- Automatic append only migrations
- Sql-like syntax
- Query builder not an orm
Install
Declare your schema
use *;
Insert, update and delete
let db = new.await?;
let posts = table.await?;
let comments = table.await?;
let post = Post ;
// insert into posts (id, body) values (?, ?) returning *
let mut post: Post = db
.insert
.values?
.returning
.await?;
post.body = "post".into;
// update posts set body = ?, id = ? where id = ? returning *
let post: Post = db
.update
.set?
.where_
.returning
.await?;
// delete from posts where id = ? returning *
let post: Post = db
.delete_from
.where_
.returning
.await?;
Querying
// select ... from Comment
let rows: = db
.select
.from
.all
.await?;
// select ... from Comment
let rows: = db
.select
.from
.all
.await?;
Joins
// select ... from Comment inner join posts on posts.id = Comment.post_id
let rows = db
.select
.from
.inner_join
.
.await?;
Prepared Statements
let query = db
.select
.from;
let prepped = query.;
let rows: = prepped.all.await?;
Manage Indexes
let ix = index
.unique
.on;
// create unique index if not exists posts_id_body_ix on posts (id, body);
db.create.await?;
// drop index if exists posts_id_body_ix;
db.drop.await?;
Sqlite to rust type map
| Sqlite | Rust |
|---|---|
| Text | String |
| Integer | i64 |
| Real | f64 |
| Null | None |
| Blob | Vec<u8> |
Automatic migrations
- Schema migrations only ever
create tableoralter table add column. Inspired by trevyn/turbosql - When
<Your Table>::table(&db).await?is called, the migrations are run.