pub struct InsertBuilder<'a> { /* private fields */ }
Expand description

Builder to contruct a insert command

Implementations

Gets the current state of the InsertBuilder and returns it as string

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

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

Create InsertBuilder’s instance

The overriding clause

Prints the current state of the InsertBuilder into console output similar to debug method, the difference is that this method prints in one line.

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 = true

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

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

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

The values clause

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.