A Rust library for building queries in an eloquent way.
ini
[dependencies]
eloquent = "0.2"
```rust use eloquent_core::{Direction, GenericVar};
let query = Eloquent::query() .table("flights") .select("id") .select("flightnumber") .r#where("destination", GenericVar::Str("SIN")) .tosql() .unwrap();
assert_eq!(query, "SELECT `id`, `flight_number` FROM flights WHERE `destination` = \"SIN\";");
```
```rust use eloquent_core::{Direction, GenericVar, Clause};
let query = Eloquent::query() .insert("flights", vec![ Clause { column: "id".tostring(), value: GenericVar::Int(1), }, Clause { column: "flightcode".tostring(), value: GenericVar::Str("KL0803"), }, ]) .tosql() .unwrap();
assert_eq!(query, "INSERT INTO flights (`id`, `flight_code`) VALUES (1, \"KL0803\");");
```
```rust use eloquent_core::{Direction, GenericVar, Clause};
let query = Eloquent::query() .update("flights", vec![ Clause { column: "flightcode".tostring(), value: GenericVar::Str("KL0803"), }, Clause { column: "destination".tostring(), value: GenericVar::Str("Bangkok"), }, ]) .r#where("id", GenericVar::Int(1)) .tosql() .unwrap();
assert_eq!(query, "INSERT INTO flights (`id`, `flight_code`) VALUES (1, \"KL0803\") WHERE `id` = 1;");
```
```rust use eloquent_core::{Direction, GenericVar};
let query = Eloquent::query() .delete("flights") .r#where("id", GenericVar::Int(1)) .to_sql() .unwrap();
assert_eq!(query, "DELETE FROM flights WHERE id
= 1;");
```