Skip to content

Nareshix/sqlitex

Repository files navigation

Sqlitex

Sqlitex is a sqlite library for rust which aims to be simple and powerful. It offers

  • Compile time guarantees
  • Ergonomic with excellent IDE support
  • Very Fast
    • Automatically caches and reuses prepared statements for you
    • Automatically applies optimal PRAGMA settings for performance and reliability

TOC

Quickstart

Install it via

cargo add sqlitex

Simple usage example:

use sqlitex::{Connection, sqlitex};

#[sqlitex]
struct App {
    init: sql!("
        CREATE TABLE IF NOT EXISTS users (
            id INTEGER PRIMARY KEY NOT NULL,
            username TEXT NOT NULL,
            is_active BOOL NOT NULL
        )
    "),

    add_user: sql!("INSERT INTO users (id, username, is_active) VALUES (?, ?, ?);"),

    get_active_users: sql!("SELECT id, username, is_active as active FROM users WHERE is_active = ?"),
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let conn = Connection::open_memory()?;
    let mut db = App::new(conn);

    db.init()?;
    db.add_user(0, "Alice", true)?;
    db.add_user(1, "Bob", false)?;

    let active_users = db.get_active_users(true)?;

    for user in active_users {
        let user = user?;
        println!("{}, {}, {}", user.id, user.username, user.active);
    }

    Ok(())
    // prints out "0, Alice, true"
}

A more detailed version of this exact quickstart can be found here

For more examples and features, look at the examples folder or read the documentations.

Feature showcase

  1. Auto generate method signatures with correct types and Hover over to see sql code

    usage

(Note: LazyConnection has been renamed to Connection in newer version. library name was previously called LazySql which has now been renamed to Sqlitex)

  1. Compile time errors with good error messages

    error_1

    error_2

    error_3

Comparison with other libraries

Look here

About

sqlitex is a rust sqlite library with great DX

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages