🎯 Hesoyam ORM

MIT License Version Version

Just another one ORM for for Postgres and Clickhouse. If you found it useful please give us a ⭐ :)

Examples

Let's custom model at first. If we won't pass table_name as macro argument default will be generated. It assumed that tables already created in db.

model.rs be like: ```rust

[model(dialect = "postgres", table_name = "users")]

pub struct User { pub name: String, pub age: i32, pub weight: f32, } ```

Now we should provide database config to start work:

```rust let pg_conf = PostgresConfig::new(). host("loclahost"). user("postgres"). password("qwerty"). port(5432). database("postgres");

let ch_conf = ClickhouseConfig::new(). schema("http"). hostname("localhost"). port(8123);

let mut cm = ClientManager::new(). addclient(&pgconf)?. addclient(&chconf)?; ```

Insert one and multiple entries

```rust use hesoyam::prelude::*

// insert one entry let name = String::from("Thomas"); let age = 20;

User::save(name, age).exec(&mut cm)?;

// do the same with multiple users let users = vec![ User { name: "John".toowned(), age: 20 }, User { name: "Tom".toowned(), age: 30 }, User { name: "Guido".toowned(), age: 99 }, User { name: "Rob".toowned(), age: 199 }, User { name: "Michael".toowned(), age: 25 }, User { name: "Jordan".toowned(), age: 25 }, User { name: "Raphael".to_owned(), age: 25 }, ];

users.save().exec(&mut cm)?; ```

Select entries

Pay attention that From trait is implemented by #[model] macro:

```rust let res = User::select().filter(vec![ User::fieldage.gte(&20), User::fieldage.lte(&40), ]).exec(&mut cm)?;

for r in res { let u: User = r.into();

println!("{:#?}", u);

} ```

Raw queries

Also there are #[query_result] macro to simplify converting raw query result to struct:

```rust let rawquery = r#" select entityid, max(high) as maxhigh from marketquote group by entityid order by entityid; "#;

[query_result]

[derive(Debug)]

struct Result { entityid: i32, avghigh: f32, }

let res = cm. getclient("clickhouse")?. query(rawquery)?;

for row in res { let res: Result = row.into();

println!("{:#?}", res);

} ```

For more (update/delete) please go to examples 🙂