Module backends

Source
Expand description

§Backend Module for GeekORM

Example:

Here is an example of how to use GeekORM with a mock connection.

use geekorm::prelude::*;


#[derive(Table, Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct Users {
    #[geekorm(primary_key, auto_increment)]
    pub id: PrimaryKey<i32>,
    #[geekorm(unique)]
    pub username: String,
}

#[tokio::main]
async fn main() -> Result<()> {
    // Create a new connection (this is a mock connection)
    let connection = Connection {};

    Users::create_table(&connection).await?;

    let users = vec!["geekmasher", "bob", "alice", "eve", "mallory", "trent"];
    for user in users {
        let mut new_user = Users::new(user);
        new_user.save(&connection).await?;
    }

    // Fetch or create a user
    let mut geek = Users::new("geekmasher");
    geek.fetch_or_create(&connection).await?;
     
    // Fetch a user by their username (exact match)
    let geekmasher = Users::fetch_by_username(&connection, "geekmasher").await?;

    // Search for a user (partial match)
    let search = Users::search(&connection, "geek").await?;

    // Fetch first and last user
    let first_user = Users::first(&connection).await?;
    let last_user = Users::last(&connection).await?;

    // Delete the user
    geek.delete(&connection).await?;

    Ok(())
}

Modules§

connect
Connection
libsql
libsql
rusqlite
RuSQLite Backend

Structs§

TableInfo
Table Info

Traits§

GeekConnection
GeekConnection is the trait that all backends must implement to be able to interact with the database.
GeekConnector
GeekConnection is the trait used for models to interact with the database.