26 releases

0.4.0-alpha.2 Oct 4, 2024
0.3.0-alpha.3 Aug 30, 2024
0.2.1 Jan 30, 2023
0.2.0-beta.9 Dec 25, 2022
0.0.0 May 10, 2022

#488 in Database interfaces

Download history 254/week @ 2024-08-25 108/week @ 2024-09-01 4/week @ 2024-09-08 197/week @ 2024-09-15 67/week @ 2024-09-22 237/week @ 2024-09-29 62/week @ 2024-10-06 2/week @ 2024-10-13

115 downloads per month

MIT license

230KB
2.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

~8–22MB
~318K SLoC