Skip to content

Releases: swlkr/ryzz

No hashtags, more rizz

31 Jan 16:21
a1c8a83
Compare
Choose a tag to compare

Deprecated

  • r#where
  • r#in

Added

  • where_
  • in_
  • default_
  • as_
  • default_values fn to Query

Changed

  • the default field macro attribute no longer wraps default values in parens, you gotta bring your own parens

Full Changelog: https://github.com/swlkr/ryzz/commits/0.2.0

Initial release!

30 Jan 01:52
796debe
Compare
Choose a tag to compare
  • Automatic append only migrations
  • Sql-like syntax
  • Query builder not an orm
  • It's just rust!
  • Easy to use tuples in select queries!
  • Fast-ish async on top of sqlite

Declare your schema

use ryzz::*;

#[table("posts")]
struct Post {
    #[ryzz(pk)]
    id: i64,
    title: Option<String>,
    body: String
}

#[table]
struct Comment {
    #[ryzz(pk)]
    id: i64,
    body: String,
    #[ryzz(fk = "posts(id)")]
    post_id: i64,
}

Insert, update and delete

let db = Database::new("db.sqlite3").await?;
let posts = Post::table(&db).await?;
let comments = Comment::table(&db).await?;

let post = Post {
    id: 1,
    title: None,
    body: "".into()
};

// insert into posts (id, body) values (?, ?) returning *
let mut post: Post = db
    .insert(posts)
    .values(post)?
    .returning()
    .await?;

post.body = "post".into();

// update posts set body = ?, id = ? where id = ? returning *
let post: Post = db
    .update(posts)
    .set(post)?
    .r#where(and(eq(posts.id, 1), eq(posts.title, Value::Null)))
    .returning()
    .await?;

// delete from posts where id = ? returning *
let post: Post = db
    .delete_from(posts)
    .r#where(eq(posts.id, 1))
    .returning()
    .await?;```

# Queries

```rust
// select ... from Comment
let rows: Vec<Comment> = db
    .select(())
    .from(comments)
    .all()
    .await?;

// select ... from Comment
let rows: Vec<Comment> = db
    .select((comments.id, comments.body))
    .from(comments)
    .all()
    .await?;

Joins

#[row]
struct CommentWithPost {
    comment: Comment,
    post: Post
}

// select ... from Comment inner join posts on posts.id = Comment.post_id
let rows = db
    .select(())
    .from(comments)
    .inner_join(posts, eq(posts.id, comments.post_id))
    .all::<CommentWithPost>()
    .await?;