Struct sql_query_builder::InsertBuilder
source · [−]pub struct InsertBuilder<'a> { /* private fields */ }Expand description
Builder to contruct a insert command
Implementations
sourceimpl<'a> InsertBuilder<'a>
impl<'a> InsertBuilder<'a>
sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Gets the current state of the InsertBuilder and returns it as string
sourcepub fn debug(self) -> Self
pub fn debug(self) -> Self
Prints the current state of the InsertBuilder into console output in a more ease to read version. This method is useful to debug complex queries or just to print the generated SQL while you type
use sql_query_builder::InsertBuilder;
let insert_query = InsertBuilder::new()
.insert_into("users (login, name)")
.values("('foo', 'Foo')")
.debug()
.values("('bar', 'Bar')")
.as_string();Output
INSERT INTO users (login, name)
VALUES ('foo', 'Foo')sourcepub fn insert_into(self, table_name: &'a str) -> Self
pub fn insert_into(self, table_name: &'a str) -> Self
The insert into clause. This method overrides the previous value
use sql_query_builder::InsertBuilder;
let insert = InsertBuilder::new()
.insert_into("users (login, name)");
let insert = InsertBuilder::new()
.insert_into("address (state, country)")
.insert_into("users (login, name)");sourcepub fn overriding(self, option: &'a str) -> Self
pub fn overriding(self, option: &'a str) -> Self
The overriding clause
sourcepub fn print(self) -> Self
pub fn print(self) -> Self
Prints the current state of the InsertBuilder into console output similar to debug method, the difference is that this method prints in one line.
sourcepub fn select(self, select: SelectBuilder<'a>) -> Self
pub fn select(self, select: SelectBuilder<'a>) -> Self
The select clause. This method overrides the previous value
use sql_query_builder::{InsertClause, InsertBuilder, SelectBuilder};
let insert_query = InsertBuilder::new()
.insert_into("users (login, name)")
.select(
SelectBuilder::new()
.select("login, name")
.from("users_bk")
.where_clause("active = true"),
)
.as_string();Output
INSERT INTO users (login, name)
SELECT login, name
FROM users_bk
WHERE active = truesourcepub fn raw(self, raw_sql: &'a str) -> Self
pub fn raw(self, raw_sql: &'a str) -> Self
Adds at the beginning a raw SQL query.
use sql_query_builder::InsertBuilder;
let raw_query = "insert into users (login, name)";
let insert_query = InsertBuilder::new()
.raw(raw_query)
.values("('foo', 'Foo')")
.as_string();Output
insert into users (login, name)
VALUES ('bar', 'Bar')sourcepub fn raw_after(self, clause: InsertClause, raw_sql: &'a str) -> Self
pub fn raw_after(self, clause: InsertClause, raw_sql: &'a str) -> Self
Adds a raw SQL query after a specified clause.
use sql_query_builder::{InsertClause, InsertBuilder};
let raw = "values ('foo', 'Foo')";
let insert_query = InsertBuilder::new()
.insert_into("users (login, name)")
.raw_after(InsertClause::InsertInto, raw)
.as_string();Output
INSERT INTO users (login, name)
values ('foo', 'Foo')sourcepub fn raw_before(self, clause: InsertClause, raw_sql: &'a str) -> Self
pub fn raw_before(self, clause: InsertClause, raw_sql: &'a str) -> Self
Adds a raw SQL query before a specified clause.
use sql_query_builder::{InsertClause, InsertBuilder};
let raw = "insert into users (login, name)";
let insert_query = InsertBuilder::new()
.raw_before(InsertClause::Values, raw)
.values("('bar', 'Bar')")
.as_string();Output
insert into users (login, name)
VALUES ('bar', 'Bar')Trait Implementations
sourceimpl<'a> Clone for InsertBuilder<'a>
impl<'a> Clone for InsertBuilder<'a>
sourcefn clone(&self) -> InsertBuilder<'a>
fn clone(&self) -> InsertBuilder<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<'a> Debug for InsertBuilder<'a>
impl<'a> Debug for InsertBuilder<'a>
sourceimpl<'a> Default for InsertBuilder<'a>
impl<'a> Default for InsertBuilder<'a>
sourcefn default() -> InsertBuilder<'a>
fn default() -> InsertBuilder<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl<'a> RefUnwindSafe for InsertBuilder<'a>
impl<'a> Send for InsertBuilder<'a>
impl<'a> Sync for InsertBuilder<'a>
impl<'a> Unpin for InsertBuilder<'a>
impl<'a> UnwindSafe for InsertBuilder<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more