sequelite

Crates.iosequelite
lib.rssequelite
version0.2.3
sourcesrc
created_at2023-04-14 22:16:16.504841
updated_at2023-04-14 22:56:08.9622
descriptionA simple SQLite ORM for Rust
homepage
repositoryhttps://github.com/olix3001/sequelite
max_upload_size
id839542
size93,481
olix3001 (olix3001)

documentation

https://docs.rs/sequelite

README

Sequelite :rocket:

Sequelite is a simple, lightweight, and fast SQLite ORM for rust.

It is built on top of rusqlite

Features

  • Simple and easy to use
  • Lightweight
  • Fast
  • Automatic schema migration

Usage

Add this to your Cargo.toml:

[dependencies]
sequelite = "0.2"

You can find the documentation here

Example

use sequelite::prelude::*;

#[derive(Debug, Model)]
struct User {
    id: Option<i32>,
    #[default_value(&"Unknown name")]
    name: Option<String>,
    age: i32,
}

fn main() {
    // Create new database connection
    let mut conn = Connection::new("example.db").unwrap();

    // Ensure database schema is up to date
    conn.register::<User>().unwrap();
    conn.migrate();

    // Create a new users
    conn.insert(&[
        User { id: None, name: Some("John".to_string()), age: 20 },
        User { id: None, name: Some("Jane".to_string()), age: 21 },
    ]);

    // Get all users whose name is "John"
    let users = User::select()
        .filter(User::name.eq("John"))
        .exec(&conn).unwrap();

    // Print all users
    println!("{:#?}", users);
}
Commit count: 19

cargo fmt