Crate teil

source ·
Expand description

Teil, basic data mapper for Postgres/Sqlite

Teil (pronounced /tail/)is a library that intends to make a connection to postgres (or sqlite) as simple as possible (with the limitations that this implies). Teil means part, portion or piece in german.

use teil::{Teil, fields::Serial};

#[derive(Teil, Debug)]
struct Account {
    #[teil(auto, primary_key)]
    id: Serial,
    #[teil(unique)]
    owner: String,
    #[teil(rename = "account_balance")]
    balance: f64
}

teil::config()
    .user("example")
    .password("password")
    .dbname("example_db")
    .host("127.0.0.1")
    .port(5432)
    .set().unwrap();

teil::create!(Account);

(Account {id: Serial::new(), owner: "Carlos".into(), balance: 420.00}).save().await.unwrap();
let account = Account::retrieve(1).await.unwrap();
println!("{:?}", account);

teil::destroy!(Account);

Features available for this crate

  • sync: Enables the use of the sync version of the library (that is, the SyncTeil and SyncFilter traits and derive macros)
  • iter: Allows a transaction-based multiple-save function to be used (see save_iter and the sync version of save_iter)
  • chrono: Allows some chrono fields to be used as fields in a Teil-deriving structure. See TeilField and SyncTeilField for more information.
  • partial: Enables partial updating fields of a row in the database. See the update method for more information (or the sync version, update)
  • uuid: Allows the use of the Uuid type with the derive macros
  • serde: Implements Serialize and Deserialize for the Serial, BigSerial, SmallSerial, and the Update associated type when using the derive macros
  • fs: Enables some filesystem manager functionality in order to store files locally with the help of a metadata table.

Modules

Contains the singleton instances for database connections
Contains the per-field traits required for teil to work
Filesystem functionality that might be useful

Macros

Creates all necessary database objects to use the structures that derive from the Teil trait.
Eliminates all the tables created by the structs that derived from the Teil trait.
Creates all necessary database objects to use the structures that derive from the SyncTeil trait.
Eliminates all the tables created by the structs that derived from the SyncTeil trait.

Structs

Wrapper structure around a postgres connection to allow for connection re-use
Wrapper structure around a rusqlite connection (inside a Mutex) to allow for connection re-use
Simple wrapper around the query_vec function
Wrapper structure around a rusqlite transaction
Simple wrapper around the query_vec function
Wrapper structure around a postgres transaction

Enums

Inner structure to help execute inner code with less functions
Inner structure to help execute inner code with less functions
Error from this library
Inner structure to help execute inner code with less functions
Inner structure to help execute inner code with less functions

Traits

SQL filter functions
SQL sort functions
SQLite filter functions
Sync version of the main trait
Guide trait for Update associated types
Allows multiple filters to be applied at once
Main trait
Guide trait for Update associated types
Allows multiple filters to be applied at once
Allows multiple filters to be applied at once

Functions

Provides a builder to configure the postgres database
Provides a builder to configure the sqlite database

Derive Macros

Implements the Filter trait to an enum
Implements the Sort trait to an enum
Implements the SyncFilter trait to an enum
Implements the SyncTeil trait to a structure
Implements the Teil trait to a structure