18 releases

0.2.1 Jan 30, 2023
0.2.0-beta.9 Dec 25, 2022
0.2.0-beta.8 Nov 8, 2022
0.0.0 May 10, 2022

#1241 in Database interfaces

Download history 7/week @ 2024-02-27 2/week @ 2024-03-12 12/week @ 2024-04-02 249/week @ 2024-04-09

261 downloads per month

MIT license

170KB
1.5K SLoC

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.

Dependencies

~9–23MB
~400K SLoC