pub trait Bind {
// Required methods
fn bind(&self, arg: &dyn SqlArg) -> String;
fn binds(&self, args: &[&dyn SqlArg]) -> String;
fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String;
fn bind_nums(&self, args: &[&dyn SqlArg]) -> String;
fn bind_name(&self, name: &dyn ToString, arg: &dyn SqlArg) -> String;
fn bind_names(&self, names: &dyn BindNames<'_>) -> String;
}
Required Methods§
Sourcefn bind(&self, arg: &dyn SqlArg) -> String
fn bind(&self, arg: &dyn SqlArg) -> String
Replace first ? with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price BETWEEN ? AND ?".bind(&100).bind(&200))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price BETWEEN 100 AND 200;", &sql);
Sourcefn binds(&self, args: &[&dyn SqlArg]) -> String
fn binds(&self, args: &[&dyn SqlArg]) -> String
Cyclic bindings of values.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > ? AND title LIKE ?".binds(&[&100, &"Harry Potter%"]))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND title LIKE 'Harry Potter%';", &sql);
Sourcefn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String
fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String
Replace all $N with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1 AND price < $1 + $2"
.bind_num(1, &100)
.bind_num(2, &200))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND price < 100 + 200;", &sql);
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1")
.and_where("price < $1 + $2")
.sql()?
.bind_num(1, &100)
.bind_num(2, &200);
assert_eq!("SELECT title, price FROM books WHERE (price > 100) AND (price < 100 + 200);", &sql);
Sourcefn bind_nums(&self, args: &[&dyn SqlArg]) -> String
fn bind_nums(&self, args: &[&dyn SqlArg]) -> String
Replace $1, $2, … with elements of array. Escape the $ symbol with another $ symbol.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1 AND price < $1 + $2".bind_nums(&[&100, &200]))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND price < 100 + 200;", &sql);
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1")
.and_where("price < $1 + $2")
.sql()?
.bind_nums(&[&100, &200]);
assert_eq!("SELECT title, price FROM books WHERE (price > 100) AND (price < 100 + 200);", &sql);
Sourcefn bind_name(&self, name: &dyn ToString, arg: &dyn SqlArg) -> String
fn bind_name(&self, name: &dyn ToString, arg: &dyn SqlArg) -> String
Replace all :name: with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::insert_into("books")
.fields(&["title", "price"])
.values(&[":name:, :costs:"])
.sql()?
.bind_name(&"name", &"Harry Potter and the Philosopher's Stone")
.bind_name(&"costs", &150);
assert_eq!("INSERT INTO books (title, price) VALUES ('Harry Potter and the Philosopher''s Stone', 150);", &sql);
Sourcefn bind_names(&self, names: &dyn BindNames<'_>) -> String
fn bind_names(&self, names: &dyn BindNames<'_>) -> String
Replace each :name: from map. Escape the : symbol with another : symbol.
use sql_builder::prelude::*;
use std::collections::HashMap;
let mut names: HashMap<&str, &dyn SqlArg> = HashMap::new();
names.insert("name", &"Harry Potter and the Philosopher's Stone");
names.insert("costs", &150);
let sql = SqlBuilder::insert_into("books")
.fields(&["title", "price"])
.values(&[":name:, :costs:"])
.sql()?
.bind_names(&names);
assert_eq!("INSERT INTO books (title, price) VALUES ('Harry Potter and the Philosopher''s Stone', 150);", &sql);
Implementations on Foreign Types§
Source§impl Bind for &str
impl Bind for &str
Source§fn bind(&self, arg: &dyn SqlArg) -> String
fn bind(&self, arg: &dyn SqlArg) -> String
Replace first ? with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price BETWEEN ? AND ?".bind(&100).bind(&200))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price BETWEEN 100 AND 200;", &sql);
Source§fn binds(&self, args: &[&dyn SqlArg]) -> String
fn binds(&self, args: &[&dyn SqlArg]) -> String
Cyclic bindings of values.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > ? AND title LIKE ?".binds(&[&100, &"Harry Potter%"]))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND title LIKE 'Harry Potter%';", &sql);
Source§fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String
fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String
Replace all $N with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1 AND price < $1 + $2"
.bind_num(1, &100)
.bind_num(2, &200))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND price < 100 + 200;", &sql);
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1")
.and_where("price < $1 + $2")
.sql()?
.bind_num(1, &100)
.bind_num(2, &200);
assert_eq!("SELECT title, price FROM books WHERE (price > 100) AND (price < 100 + 200);", &sql);
Source§fn bind_nums(&self, args: &[&dyn SqlArg]) -> String
fn bind_nums(&self, args: &[&dyn SqlArg]) -> String
Replace $1, $2, … with elements of array. Escape the $ symbol with another $ symbol.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1 AND price < $1 + $2".bind_nums(&[&100, &200]))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND price < 100 + 200;", &sql);
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1")
.and_where("price < $1 + $2")
.sql()?
.bind_nums(&[&100, &200]);
assert_eq!("SELECT title, price FROM books WHERE (price > 100) AND (price < 100 + 200);", &sql);
Source§fn bind_name(&self, name: &dyn ToString, arg: &dyn SqlArg) -> String
fn bind_name(&self, name: &dyn ToString, arg: &dyn SqlArg) -> String
Replace all :name: with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::insert_into("books")
.fields(&["title", "price"])
.values(&[":name:, :costs:"])
.sql()?
.bind_name(&"name", &"Harry Potter and the Philosopher's Stone")
.bind_name(&"costs", &150);
assert_eq!("INSERT INTO books (title, price) VALUES ('Harry Potter and the Philosopher''s Stone', 150);", &sql);
Source§fn bind_names<'a>(&self, names: &dyn BindNames<'_>) -> String
fn bind_names<'a>(&self, names: &dyn BindNames<'_>) -> String
Replace each :name: from map. Escape the : symbol with another : symbol.
use sql_builder::prelude::*;
use std::collections::HashMap;
let mut names: HashMap<&str, &dyn SqlArg> = HashMap::new();
names.insert("name", &"Harry Potter and the Philosopher's Stone");
names.insert("costs", &150);
let sql = SqlBuilder::insert_into("books")
.fields(&["title", "price"])
.values(&[":name:, :costs:"])
.sql()?
.bind_names(&names);
assert_eq!("INSERT INTO books (title, price) VALUES ('Harry Potter and the Philosopher''s Stone', 150);", &sql);
Source§impl Bind for String
impl Bind for String
Source§fn bind(&self, arg: &dyn SqlArg) -> String
fn bind(&self, arg: &dyn SqlArg) -> String
Replace first ? with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price BETWEEN ? AND ?".bind(&100).bind(&200))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price BETWEEN 100 AND 200;", &sql);
Source§fn binds(&self, args: &[&dyn SqlArg]) -> String
fn binds(&self, args: &[&dyn SqlArg]) -> String
Cyclic bindings of values.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > ? AND title LIKE ?".binds(&[&100, &"Harry Potter%"]))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND title LIKE 'Harry Potter%';", &sql);
Source§fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String
fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String
Replace all $N with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1 AND price < $1 + $2"
.bind_num(1, &100)
.bind_num(2, &200))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND price < 100 + 200;", &sql);
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1")
.and_where("price < $1 + $2")
.sql()?
.bind_num(1, &100)
.bind_num(2, &200);
assert_eq!("SELECT title, price FROM books WHERE (price > 100) AND (price < 100 + 200);", &sql);
Source§fn bind_nums(&self, args: &[&dyn SqlArg]) -> String
fn bind_nums(&self, args: &[&dyn SqlArg]) -> String
Replace $1, $2, … with elements of array. Escape the $ symbol with another $ symbol.
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1 AND price < $1 + $2".bind_nums(&[&100, &200]))
.sql()?;
assert_eq!("SELECT title, price FROM books WHERE price > 100 AND price < 100 + 200;", &sql);
use sql_builder::prelude::*;
let sql = SqlBuilder::select_from("books")
.fields(&["title", "price"])
.and_where("price > $1")
.and_where("price < $1 + $2")
.sql()?
.bind_nums(&[&100, &200]);
assert_eq!("SELECT title, price FROM books WHERE (price > 100) AND (price < 100 + 200);", &sql);
Source§fn bind_name(&self, name: &dyn ToString, arg: &dyn SqlArg) -> String
fn bind_name(&self, name: &dyn ToString, arg: &dyn SqlArg) -> String
Replace all :name: with a value.
use sql_builder::prelude::*;
let sql = SqlBuilder::insert_into("books")
.fields(&["title", "price"])
.values(&[":name:, :costs:"])
.sql()?
.bind_name(&"name", &"Harry Potter and the Philosopher's Stone")
.bind_name(&"costs", &150);
assert_eq!("INSERT INTO books (title, price) VALUES ('Harry Potter and the Philosopher''s Stone', 150);", &sql);
Source§fn bind_names<'a>(&self, names: &dyn BindNames<'_>) -> String
fn bind_names<'a>(&self, names: &dyn BindNames<'_>) -> String
Replace each :name: from map. Escape the : symbol with another : symbol.
use sql_builder::prelude::*;
use std::collections::HashMap;
let mut names: HashMap<&str, &dyn SqlArg> = HashMap::new();
names.insert("name", &"Harry Potter and the Philosopher's Stone");
names.insert("costs", &150);
let sql = SqlBuilder::insert_into("books")
.fields(&["title", "price"])
.values(&[":name:, :costs:"])
.sql()?
.bind_names(&names);
assert_eq!("INSERT INTO books (title, price) VALUES ('Harry Potter and the Philosopher''s Stone', 150);", &sql);