Struct diesel::expression::SqlLiteral[][src]

pub struct SqlLiteral<ST, T = ()> { /* fields omitted */ }
Expand description

Returned by the sql() function.

Implementations

Bind a value for use with this SQL query.

Safety

This function should be used with care, as Diesel cannot validate that the value is of the right type nor can it validate that you have passed the correct number of parameters.

Examples

let seans_id = users
    .select(id)
    .filter(sql("name = ").bind::<Text, _>("Sean"))
    .get_result(&connection);
assert_eq!(Ok(1), seans_id);

let tess_id = sql::<Integer>("SELECT id FROM users WHERE name = ")
    .bind::<Text, _>("Tess")
    .get_result(&connection);
assert_eq!(Ok(2), tess_id);

Multiple Bind Params


let query = users
    .select(name)
    .filter(
        sql("id > ")
        .bind::<Integer,_>(1)
        .sql(" AND name <> ")
        .bind::<Text, _>("Ryan")
    )
    .get_results(&connection);
let expected = vec!["Tess".to_string()];
assert_eq!(Ok(expected), query);

Use literal SQL in the query builder

This function is intended for use when you need a small bit of raw SQL in your query. If you want to write the entire query using raw SQL, use sql_query instead.

Safety

This function should be used with care, as Diesel cannot validate that the value is of the right type nor can it validate that you have passed the correct number of parameters.

Examples


let query = users
    .select(name)
    .filter(
        sql("id > 1")
        .sql(" AND name <> 'Ryan'")
    )
    .get_results(&connection);
let expected = vec!["Tess".to_string()];
assert_eq!(Ok(expected), query);

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The type that this expression represents in SQL

The resulting type after applying the * operator.

Performs the * operation. Read more

The SQL type that this query represents. Read more

Walk over this QueryFragment for all passes. Read more

Converts this QueryFragment to its SQL representation. Read more

Serializes all bind parameters in this query. Read more

Is this query safe to store in the prepared statement cache? Read more

A type which uniquely represents Self in a SQL query. Read more

Can the SQL generated by Self be uniquely identified by its type? Read more

Returns the type id of Self::QueryId if Self::HAS_STATIC_QUERY_ID. Returns None otherwise. Read more

Executes the given command, returning the number of rows affected. Read more

Executes the given query, returning a Vec with the returned rows. Read more

Runs the command, and returns the affected row. Read more

Runs the command, returning an Vec with the affected rows. Read more

Attempts to load a single record. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The SQL type of Self::Query

What kind of query does this type represent?

Converts a type which semantically represents a SQL query into the actual query being executed. See the trait level docs for more. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Execute this command

Performs the conversion.

Performs the conversion.

Convert self to an expression for Diesel’s query builder. Read more

Convert &self to an expression for Diesel’s query builder. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. 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.