Struct diesel::mysql::MysqlConnection
source · pub struct MysqlConnection { /* private fields */ }
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[?unix_socket=socket-path&ssl_mode=SSL_MODE*&ssl_ca=/etc/ssl/certs/ca-certificates.crt&ssl_cert=/etc/ssl/certs/client-cert.crt&ssl_key=/etc/ssl/certs/client-key.crt]
host
can be an IP address or a hostname. If it is set tolocalhost
, a connection will be attempted through the socket at/tmp/mysql.sock
. If you want to connect to a local server via TCP (e.g. docker containers), use0.0.0.0
or127.0.0.1
instead.unix_socket
expects the path to the unix socketssl_ca
accepts a path to the system’s certificate rootsssl_cert
accepts a path to the client’s certificate filessl_key
accepts a path to the client’s private key filessl_mode
expects a value defined for MySQL client command option--ssl-mode
See https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode
§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§
source§impl Connection for MysqlConnection
impl Connection for MysqlConnection
source§fn establish(database_url: &str) -> ConnectionResult<Self>
fn establish(database_url: &str) -> ConnectionResult<Self>
Establishes a new connection to the MySQL database
database_url
may be enhanced by GET parameters
mysql://[user[:password]@]host[:port]/database_name[?unix_socket=socket-path&ssl_mode=SSL_MODE*&ssl_ca=/etc/ssl/certs/ca-certificates.crt&ssl_cert=/etc/ssl/certs/client-cert.crt&ssl_key=/etc/ssl/certs/client-key.crt]
host
can be an IP address or a hostname. If it is set tolocalhost
, a connection will be attempted through the socket at/tmp/mysql.sock
. If you want to connect to a local server via TCP (e.g. docker containers), use0.0.0.0
or127.0.0.1
instead.unix_socket
expects the path to the unix socketssl_ca
accepts a path to the system’s certificate rootsssl_cert
accepts a path to the client’s certificate filessl_key
accepts a path to the client’s private key filessl_mode
expects a value defined for MySQL client command option--ssl-mode
See https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode
§type TransactionManager = AnsiTransactionManager
type TransactionManager = AnsiTransactionManager
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.source§fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>
fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.source§fn transaction_state(&mut self) -> &mut AnsiTransactionManager
fn transaction_state(&mut self) -> &mut AnsiTransactionManager
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.source§fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
source§fn begin_test_transaction(&mut self) -> QueryResult<()>
fn begin_test_transaction(&mut self) -> QueryResult<()>
source§impl LoadConnection for MysqlConnection
impl LoadConnection for MysqlConnection
§type Cursor<'conn, 'query> = StatementIterator<'conn>
type Cursor<'conn, 'query> = StatementIterator<'conn>
LoadConnection::load
Read more§type Row<'conn, 'query> = MysqlRow
type Row<'conn, 'query> = MysqlRow
Iterator::Item
for the iterator implementation
of LoadConnection::Cursor
source§fn load<'conn, 'query, T>(
&'conn mut self,
source: T
) -> QueryResult<Self::Cursor<'conn, 'query>>where
T: Query + QueryFragment<Self::Backend> + QueryId + 'query,
Self::Backend: QueryMetadata<T::SqlType>,
fn load<'conn, 'query, T>(
&'conn mut self,
source: T
) -> QueryResult<Self::Cursor<'conn, 'query>>where
T: Query + QueryFragment<Self::Backend> + QueryId + 'query,
Self::Backend: QueryMetadata<T::SqlType>,
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.source§impl MultiConnectionHelper for MysqlConnection
impl MultiConnectionHelper for MysqlConnection
source§fn to_any<'a>(
lookup: &mut <Self::Backend as TypeMetadata>::MetadataLookup
) -> &mut (dyn Any + 'a)
fn to_any<'a>( lookup: &mut <Self::Backend as TypeMetadata>::MetadataLookup ) -> &mut (dyn Any + 'a)
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.source§fn from_any(
lookup: &mut dyn Any
) -> Option<&mut <Self::Backend as TypeMetadata>::MetadataLookup>
fn from_any( lookup: &mut dyn Any ) -> Option<&mut <Self::Backend as TypeMetadata>::MetadataLookup>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.source§impl R2D2Connection for MysqlConnection
Available on crate feature r2d2
only.
impl R2D2Connection for MysqlConnection
r2d2
only.