pub struct MysqlConnection { /* private fields */ }
Available on crate features mysql and mysql_backend only.
Expand description

A connection to a MySQL database. Connection URLs should be in the form mysql://[user[:password]@]host/database_name

Supported loading model implementations

As MysqlConnection only supports a single loading mode implementation it is not required to explicitly specify a loading mode when calling RunQueryDsl::load_iter() or LoadConnection::load

DefaultLoadingMode

MysqlConnection only supports a single loading mode, which loads values row by row from the result set.

use diesel::connection::DefaultLoadingMode;
{ // scope to restrict the lifetime of the iterator
    let iter1 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;

    for r in iter1 {
        let (id, name) = r?;
        println!("Id: {} Name: {}", id, name);
    }
}

// works without specifying the loading mode
let iter2 = users::table.load_iter::<(i32, String), _>(connection)?;

for r in iter2 {
    let (id, name) = r?;
    println!("Id: {} Name: {}", id, name);
}

This mode does not support creating multiple iterators using the same connection.

use diesel::connection::DefaultLoadingMode;

let iter1 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;
let iter2 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;

for r in iter1 {
    let (id, name) = r?;
    println!("Id: {} Name: {}", id, name);
}

for r in iter2 {
    let (id, name) = r?;
    println!("Id: {} Name: {}", id, name);
}

Trait Implementations

Establishes a new connection to the MySQL database database_url may be enhanced by GET parameters mysql://[user[:password]@]host/database_name[?unix_socket=socket-path&ssl_mode=SSL_MODE*&ssl_ca=/etc/ssl/certs/ca-certificates.crt]

The backend this type connects to
Executes the given function inside of a database transaction Read more
Creates a transaction that will never be committed. This is useful for tests. Panics if called while inside of a transaction or if called with a connection containing a broken transaction Read more
Executes the given function inside a transaction, but does not commit it. Panics if the given function returns an error. Read more
Setup the following table: Read more
Check if a connection is still valid
Checks if the connection is broken and should not be reused Read more
Execute multiple SQL statements within the same string. Read more
See the traits documentation.

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.

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 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.