liteql 0.1.2

LiteQL is a lightweight wrapper for Rusqlite and Eloquent, designed to make working with SQLite in Rust easier and more intuitive.
Documentation
  • Coverage
  • 0%
    0 out of 7 items documented0 out of 0 items with examples
  • Size
  • Source code size: 10.29 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.63 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 25s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • georgiyozhegov

LiteQL

LiteQL is a lightweight wrapper for Rusqlite and Eloquent, designed to make working with SQLite in Rust easier and more intuitive.

Usage

Here's a simple example demonstrating its usage.

use std::sync::LazyLock;

use eloquent::Eloquent;
use rusqlite::{Connection, Error, Row};
use liteql::{Execute, FromRow, Query};

#[derive(Debug)]
pub struct User {
    pub id: String,
    pub name: String,
    pub age: u8,
}

impl FromRow for User {
    fn from_row(row: &Row) -> Result<Self, Error>
    where
        Self: Sized,
    {
        Ok(Self {
            id: row.get(0)?,
            name: row.get(1)?,
            age: row.get(2)?,
        })
    }
}

const DATABASE: LazyLock<Connection> =
    LazyLock::new(|| Connection::open("database.sqlite").unwrap());

fn main() {
    "DROP TABLE IF EXISTS user".execute(&DATABASE).unwrap();

    "
    CREATE TABLE user (
        id VARCHAR(20) PRIMARY KEY,
        name VARCHAR(40) NOT NULL,
        age INTEGER NOT NULL
    )"
    .execute(&DATABASE)
    .unwrap();

    let george = User {
        id: "georgiyozhegov".into(),
        name: "George".into(),
        age: 99,
    };

    Eloquent::query()
        .table("user")
        .insert("id", george.id)
        .insert("name", george.name)
        .insert("age", george.age as u32)
        .execute(&DATABASE)
        .unwrap();

    let other = User {
        id: "otheruser".into(),
        name: "User".into(),
        age: 21,
    };

    Eloquent::query()
        .table("user")
        .insert("id", other.id)
        .insert("name", other.name)
        .insert("age", other.age as u32)
        .execute(&DATABASE)
        .unwrap();

    let users: Vec<User> = Eloquent::query()
        .table("user")
        .select("*")
        .where_gt("age", 30)
        .query(&DATABASE)
        .unwrap();

    for user in users {
        dbg!(user);
    }
}