Eloquent

Test Status Crate API Minimum rustc version

A Rust library for building queries in an eloquent way.

Usage

Add this to your Cargo.toml:

ini [dependencies] eloquent = "0.1.4"

Select Query

```rust use eloquent_core::{Direction, GenericVar};

let query = Eloquent::query() .table("flights".tostring()) .select("id".tostring()) .select("flightnumber".tostring()) .r#where("destination".tostring(), GenericVar::Str("SIN".tostring())) .to_sql() .unwrap();

assert_eq!(query, "SELECT `id`, `flight_number` FROM flights WHERE `destination` = \"SIN\";");

```

Insert Query

```rust use eloquent_core::{Direction, GenericVar, Clause};

let query = Eloquent::query() .insert("flights".tostring(), vec![ Clause { column: "id".tostring(), value: GenericVar::Int(1), }, Clause { column: "flightcode".tostring(), value: GenericVar::Str("KL0803".tostring()), }, ]) .tosql() .unwrap();

assert_eq!(query, "INSERT INTO flights (`id`, `flight_code`) VALUES (1, \"KL0803\");");

```

Update Query

```rust use eloquent_core::{Direction, GenericVar, Clause};

let query = Eloquent::query() .update("flights".tostring(), vec![ Clause { column: "flightcode".tostring(), value: GenericVar::Str("KL0803".tostring()), }, Clause { column: "destination".tostring(), value: GenericVar::Str("Bangkok".tostring()), }, ]) .r#where("id".tostring(), GenericVar::Int(1)) .tosql() .unwrap();

assert_eq!(query, "INSERT INTO flights (`id`, `flight_code`) VALUES (1, \"KL0803\") WHERE `id` = 1;");

```

Delete Query

```rust use eloquent_core::{Direction, GenericVar};

let query = Eloquent::query() .delete("flights".tostring()) .r#where("id".tostring(), GenericVar::Int(1)) .to_sql() .unwrap();

assert_eq!(query, "DELETE FROM flights WHERE id = 1;"); ```