Expand description
§About
This crate is intended to be easy to use for creating SQL-Queries dynamically as you need it.
§Usage
For creating a simple SELECT-Query you first need to add
query_builder = "*"
to your Cargo.toml
file (you may of cource replace * with any version)
In your code write extern crate query_builder
and use query_builder::*
to
import all structs and enums.
Finally creating the SelectQuery
looks like this:
use query_builder::SelectQuery;
let query = SelectQuery::select(&["*"]).from("users");
// make sure the query looks like expected
assert_eq!(query.as_string(), "SELECT * FROM users");
Creating a [`InsertQuery`] works similar:
use query_builder::{InsertQuery, Value};
// create the basic query
let mut query = InsertQuery::into("users");
// add values to the query
query.values.insert("name", Value::Varchar("george"));
// make sure that the query looks like expected
assert_eq!(query.as_string(), "INSERT INTO users(name) VALUES('george')");
More detailed explanations and examples can be found at the corresponding sections to the structs and enums
Structs§
- Delete
Query - Struct representing a SQL Delete Statement
- Insert
Query - Struct representing an SQL Insert Statement
- Select
Query - Struct representing a SQL-INSERT Query A simple query to select everything from a table can be created like this:
- Update
Query - Struct representing an SQL Update statement
- Where
Clause - Struct representing an WHERE-Clause