28 releases (14 stable)

Uses new Rust 2021

3.0.0 Apr 27, 2022
3.0.0-beta.4 Mar 3, 2022
3.0.0-beta.3 Dec 15, 2021
3.0.0-beta.2 Oct 28, 2021
0.4.0 Jun 10, 2020

#45 in Database interfaces

Download history 5/week @ 2022-01-24 9/week @ 2022-01-31 18/week @ 2022-02-07 7/week @ 2022-02-14 32/week @ 2022-02-21 30/week @ 2022-02-28 13/week @ 2022-03-07 98/week @ 2022-03-14 83/week @ 2022-03-21 6/week @ 2022-03-28 12/week @ 2022-04-04 4/week @ 2022-04-11 31/week @ 2022-04-18 150/week @ 2022-04-25 180/week @ 2022-05-02 38/week @ 2022-05-09

400 downloads per month
Used in elephantry-cli

MIT license

250KB
6.5K SLoC

Elephantry

Crates.io docs.rs Github actions pipeline status

When Rust meets PostgreSQL.

Getting Started

See quickstart and examples.

Quick overview

Elephantry is an OMM (object model manager) dedicated to PostgreSQL design to handle from simple to complex queries.

let database_url = std::env::var("DATABASE_URL")
    .unwrap_or_else(|_| "postgres://localhost".to_string());

// Connect
let elephantry = elephantry::Pool::new(&database_url)?;

// Simple query
let rows = elephantry.execute("select id from entity")?;

for row in &rows {
    let id: i32 = row.get("id");
    println!("{}", id);
}

// Define entity
#[derive(elephantry::Entity)]
#[elephantry(model = "Model", structure = "Structure")]
struct Entity {
    #[elephantry(pk)]
    id: u16,
    deleted: bool,
}

// Read entities
let entity = elephantry.find_by_pk::<Model>(&elephantry::pk!(id))?;
let entities = elephantry.find_all::<Model>(None)?;
let entities = elephantry.find_where::<Model>("deleted = $1", &[&false], None)?;

// Write entities
elephantry.insert_one::<Model>(&entity)?;
elephantry.update_one::<Model>(&elephantry::pk!{id => entity.id}, &entity)?;
elephantry.delete_one::<Model>(&entity)?;
elephantry.delete_where::<Model>("deleted = $1", &[&true])?;

Features

  • all-types — enables all type features (see below);
  • arbitrary — add support for arbitrary crate;
  • config — adds support for config layered configuration system;
  • r2d2 — adds support for r2d2 generic connection pool;
  • rocket — adds support for rocket web framewok;
  • serde — adds support for de/serialization via serde.

Types

  • bit — adds support for bit type;
  • date — adds support for date type;
  • geo — adds support for geometric type;
  • json — adds support for json type;
  • multirange — adds support for multirange type (postgresql >= 14);
  • money — adds support for money type;
  • net — adds support for network type;
  • numeric — adds support for numeric type;
  • time — adds support for time type;
  • uuid — adds support for uuid type;
  • xml — adds support for xml type.

Projects using Elephantry

  • todo — Todo rocket example app;
  • explain — A CLI tool transforms postgresql explain to a graph;
  • sav — A simple CRUD application to archive bought item waranty build with rocket;
  • out of gafam — Generate RSS feed for GAFAM (youtube, facebook, instagram and twitter) using actix.
  • captainstat — Another simple application builds with actix to display statitics;
  • oxfeed — A feed reader with an actix API and yew front.

If you want to add your project here, please create a pull request.

Dependencies

~2.3–6.5MB
~147K SLoC