Crate teil

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§

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

Macros§

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

Structs§

Connection
Wrapper structure around a postgres connection to allow for connection re-use
SyncConnection
Wrapper structure around a rusqlite connection (inside a Mutex) to allow for connection re-use
SyncTeilQuery
Simple wrapper around the query_vec function
SyncTransaction
Wrapper structure around a rusqlite transaction
TeilQuery
Simple wrapper around the query_vec function
Transaction
Wrapper structure around a postgres transaction

Enums§

ConnectionType
Inner structure to help execute inner code with less functions
ConnectionTypeMut
Inner structure to help execute inner code with less functions
Error
Error from this library
SyncConnectionType
Inner structure to help execute inner code with less functions
SyncConnectionTypeMut
Inner structure to help execute inner code with less functions

Traits§

Filter
SQL filter functions
Sort
SQL sort functions
SyncFilter
SQLite filter functions
SyncTeil
Sync version of the main trait
SyncUpdate
Guide trait for Update associated types
SyncVecFilter
Allows multiple filters to be applied at once
Teil
Main trait
Update
Guide trait for Update associated types
VecFilter
Allows multiple filters to be applied at once
VecSort
Allows multiple filters to be applied at once

Functions§

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

Derive Macros§

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