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 aTeil-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 macrosserde: Implements Serialize and Deserialize for the Serial, BigSerial, SmallSerial, and the Update associated type when using the derive macrosfs: 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
Teiltrait. - destroy
- Eliminates all the tables created by the structs that derived from the
Teiltrait. - sync_
create - Creates all necessary database objects to use the structures that derive from the
SyncTeiltrait. - sync_
destroy - Eliminates all the tables created by the structs that derived from the
SyncTeiltrait.
Structs§
- Connection
- Wrapper structure around a postgres connection to allow for connection re-use
- Sync
Connection - Wrapper structure around a rusqlite connection (inside a Mutex) to allow for connection re-use
- Sync
Teil Query - Simple wrapper around the query_vec function
- Sync
Transaction - Wrapper structure around a rusqlite transaction
- Teil
Query - Simple wrapper around the query_vec function
- Transaction
- Wrapper structure around a postgres transaction
Enums§
- Connection
Type - Inner structure to help execute inner code with less functions
- Connection
Type Mut - Inner structure to help execute inner code with less functions
- Error
- Error from this library
- Sync
Connection Type - Inner structure to help execute inner code with less functions
- Sync
Connection Type Mut - Inner structure to help execute inner code with less functions
Traits§
- Filter
- SQL filter functions
- Sort
- SQL sort functions
- Sync
Filter - SQLite filter functions
- Sync
Teil - Sync version of the main trait
- Sync
Update - Guide trait for
Updateassociated types - Sync
VecFilter - Allows multiple filters to be applied at once
- Teil
- Main trait
- Update
- Guide trait for
Updateassociated 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
Filtertrait to an enum - Sort
- Implements the
Sorttrait to an enum - Sync
Filter - Implements the
SyncFiltertrait to an enum - Sync
Teil - Implements the
SyncTeiltrait to a structure - Teil
- Implements the
Teiltrait to a structure