27 releases

0.5.0-alpha.1 Nov 27, 2024
0.3.0-alpha.6 Sep 20, 2024
0.2.1 Jan 30, 2023
0.2.0-beta.9 Dec 25, 2022
0.0.0 May 10, 2022

#746 in Database interfaces

Download history 319/week @ 2024-08-26 47/week @ 2024-09-02 220/week @ 2024-09-16 44/week @ 2024-09-23 263/week @ 2024-09-30 38/week @ 2024-10-07 120/week @ 2024-11-25 21/week @ 2024-12-02

141 downloads per month

MIT license

235KB
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–21MB
~318K SLoC