Crate parsql_sqlite

Source
Expand description

§parsql-sqlite

SQLite integration for parsql. This crate provides synchronous APIs for working with SQLite databases.

§Features

  • Synchronous SQLite operations
  • Automatic SQL query generation
  • Secure parameter management
  • Generic CRUD operations
  • Transaction support

§Usage

use rusqlite::{Connection, Result};
use parsql::sqlite::{get, insert};
 
#[derive(Insertable, SqlParams)]
#[table("users")]
pub struct InsertUser {
    pub name: String,
    pub email: String,
}
 
#[derive(Queryable, SqlParams, FromRow)]
#[table("users")]
#[where_clause("id = ?")]
pub struct GetUser {
    pub id: i32,
    pub name: String,
    pub email: String,
}
 
fn main() -> Result<()> {
    let conn = Connection::open("test.db")?;
     
    // Insert a new user
    let insert_user = InsertUser {
        name: "John".to_string(),
        email: "john@example.com".to_string(),
    };
     
    let id = insert(&conn, insert_user)?;
     
    // Get the user back
    let get_user = GetUser::new(id as i32);
    let user = get(&conn, &get_user)?;
     
    println!("User: {:?}", user);
    Ok(())
}

Re-exports§

pub use crud_ops::insert;
pub use crud_ops::select;
pub use crud_ops::select_all;
pub use crud_ops::update;
pub use crud_ops::delete;
pub use crud_ops::get;
pub use crud_ops::get_all;
pub use parsql_macros as macros;

Modules§

crud_ops

Structs§

Connection
A connection to a SQLite database.
Row
A single result row of a query.

Enums§

Error
Enum listing possible errors from rusqlite.

Traits§

FromRow
Trait for converting database rows to Rust structs. This trait is implemented by the derive macro FromRow.
SqlParams
Trait for providing SQL parameters. This trait is implemented by the derive macro SqlParams.
SqlQuery
Trait for generating SQL queries. This trait is implemented by the derive macro Queryable, Insertable, Updateable, and Deletable.
ToSql
A trait for types that can be converted into SQLite values. Returns Error::ToSqlConversionFailure if the conversion fails.
UpdateParams
Trait for providing UPDATE parameters. This trait is implemented by the derive macro UpdateParams.