Crate query_builder

Source
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§

  • Struct representing a SQL Delete Statement
  • Struct representing an SQL Insert Statement
  • Struct representing a SQL-INSERT Query A simple query to select everything from a table can be created like this:
  • Struct representing an SQL Update statement
  • Struct representing an WHERE-Clause

Enums§

  • Enum representing the ways to combine conditional parts of a query
  • Representing the way to format the ORDER BY clause of some queries
  • Enum representing common SQL-datatypes