pub struct MysqlLikeConnection<DB: MysqlLikeBackend> { /* private fields */ }mariadb_backend or mysql_backend) and (crate features mariadb or mysql) 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]
hostcan 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.0or127.0.0.1instead.unix_socketexpects the path to the unix socketssl_caaccepts a path to the system’s certificate rootsssl_certaccepts a path to the client’s certificate filessl_keyaccepts a path to the client’s private key filessl_modeexpects a value defined for MySQL client command option--ssl-modeSee 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<DB: MysqlLikeBackend> Connection for MysqlLikeConnection<DB>
impl<DB: MysqlLikeBackend> Connection for MysqlLikeConnection<DB>
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&local_infile=true]
hostcan 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.0or127.0.0.1instead.unix_socketexpects the path to the unix socketssl_caaccepts a path to the system’s certificate rootsssl_certaccepts a path to the client’s certificate filessl_keyaccepts a path to the client’s private key filessl_modeexpects a value defined for MySQL client command option--ssl-modeSee https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-modelocal_infileexpects a boolean to enable or disable LOAD DATA LOCAL
Source§type TransactionManager = AnsiTransactionManager
type TransactionManager = AnsiTransactionManager
Source§fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>
fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>
Source§fn transaction_state(&mut self) -> &mut AnsiTransactionManager
fn transaction_state(&mut self) -> &mut AnsiTransactionManager
Source§fn instrumentation(&mut self) -> &mut dyn Instrumentation
fn instrumentation(&mut self) -> &mut dyn Instrumentation
Source§fn set_instrumentation(&mut self, instrumentation: impl Instrumentation)
fn set_instrumentation(&mut self, instrumentation: impl Instrumentation)
Instrumentation implementation for this connectionSource§fn set_prepared_statement_cache_size(&mut self, size: CacheSize)
fn set_prepared_statement_cache_size(&mut self, size: CacheSize)
CacheSize for this connectionSource§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<()>
impl<DB: MysqlLikeBackend> ConnectionSealed for MysqlLikeConnection<DB>
Source§impl<DB: MysqlLikeBackend> LoadConnection for MysqlLikeConnection<DB>
impl<DB: MysqlLikeBackend> LoadConnection for MysqlLikeConnection<DB>
Source§type Cursor<'conn, 'query> = StatementIterator<'conn, DB>
type Cursor<'conn, 'query> = StatementIterator<'conn, DB>
LoadConnection::load Read moreSource§type Row<'conn, 'query> = MysqlRow<DB>
type Row<'conn, 'query> = MysqlRow<DB>
Iterator::Item for the iterator implementation
of LoadConnection::CursorSource§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>,
Source§impl<DB: MysqlLikeBackend> MultiConnectionHelper for MysqlLikeConnection<DB>
impl<DB: MysqlLikeBackend> MultiConnectionHelper for MysqlLikeConnection<DB>
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<DB: MysqlLikeBackend> R2D2Connection for MysqlLikeConnection<DB>
Available on crate feature r2d2 only.
impl<DB: MysqlLikeBackend> R2D2Connection for MysqlLikeConnection<DB>
r2d2 only.impl<DB: MysqlLikeBackend> Send for MysqlLikeConnection<DB>
Source§impl<DB: MysqlLikeBackend> SimpleConnection for MysqlLikeConnection<DB>
impl<DB: MysqlLikeBackend> SimpleConnection for MysqlLikeConnection<DB>
Source§fn batch_execute(&mut self, query: &str) -> QueryResult<()>
fn batch_execute(&mut self, query: &str) -> QueryResult<()>
Auto Trait Implementations§
impl<DB> !RefUnwindSafe for MysqlLikeConnection<DB>
impl<DB> !Sync for MysqlLikeConnection<DB>
impl<DB> !UnwindSafe for MysqlLikeConnection<DB>
impl<DB> Freeze for MysqlLikeConnection<DB>
impl<DB> Unpin for MysqlLikeConnection<DB>
impl<DB> UnsafeUnpin for MysqlLikeConnection<DB>
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> AggregateDistinct<Self>where
Self: DistinctDsl,
fn aggregate_distinct(self) -> AggregateDistinct<Self>where
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> AggregateAll<Self>where
Self: AllDsl,
fn aggregate_all(self) -> AggregateAll<Self>where
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> AggregateFilter<Self, P>
fn aggregate_filter<P>(self, f: P) -> AggregateFilter<Self, P>
Source§fn aggregate_order<O>(self, o: O) -> AggregateOrder<Self, O>where
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> AggregateOrder<Self, O>where
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<C> BoxableConnection<<C as Connection>::Backend> for Cwhere
C: Connection + Any,
impl<C> BoxableConnection<<C as Connection>::Backend> for Cwhere
C: Connection + Any,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.