[][src]Trait sql_builder::bind::Bind

pub trait Bind {
    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; }

Required methods

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);

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);

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);

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);
Loading content...

Implementations on Foreign Types

impl<'_> Bind for &'_ str[src]

fn bind(&self, arg: &dyn SqlArg) -> String[src]

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);

fn binds(&self, args: &[&dyn SqlArg]) -> String[src]

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);

fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String[src]

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);

fn bind_nums(&self, args: &[&dyn SqlArg]) -> String[src]

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);

impl Bind for String[src]

fn bind(&self, arg: &dyn SqlArg) -> String[src]

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);

fn binds(&self, args: &[&dyn SqlArg]) -> String[src]

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);

fn bind_num(&self, num: u16, arg: &dyn SqlArg) -> String[src]

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);

fn bind_nums(&self, args: &[&dyn SqlArg]) -> String[src]

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);
Loading content...

Implementors

Loading content...