Struct diesel::prelude::MysqlConnection
source · 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§
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/database_name[?unix_socket=socket-path&ssl_mode=SSL_MODE*&ssl_ca=/etc/ssl/certs/ca-certificates.crt]
unix_socketexpects the path to the unix socketssl_caaccepts a path to the system’s certificate rootsssl_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
§type TransactionManager = AnsiTransactionManager
type TransactionManager = AnsiTransactionManager
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.The transaction manager implementation used by this connection
source§fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>where
T: QueryFragment<Self::Backend> + QueryId,
fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>where T: QueryFragment<Self::Backend> + QueryId,
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.Execute a single SQL statements given by a query and return
number of affected rows
source§fn transaction_state(&mut self) -> &mut AnsiTransactionManager
fn transaction_state(&mut self) -> &mut AnsiTransactionManager
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.Get access to the current transaction state of this connection Read more
source§fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>where
F: FnOnce(&mut Self) -> Result<T, E>,
E: From<Error>,
fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>where F: FnOnce(&mut Self) -> Result<T, E>, E: From<Error>,
Executes the given function inside of a database transaction Read more
source§fn begin_test_transaction(&mut self) -> QueryResult<()>
fn begin_test_transaction(&mut self) -> QueryResult<()>
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
source§impl<'conn, 'query> ConnectionGatWorkaround<'conn, 'query, Mysql, DefaultLoadingMode> for MysqlConnection
impl<'conn, 'query> ConnectionGatWorkaround<'conn, 'query, Mysql, DefaultLoadingMode> for MysqlConnection
§type Cursor = StatementIterator<'conn>
type Cursor = StatementIterator<'conn>
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.The cursor type returned by
LoadConnection::load Read more§type Row = MysqlRow
type Row = MysqlRow
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.The row type used as
Iterator::Item for the iterator implementation
of ConnectionGatWorkaround::Cursorsource§impl LoadConnection<DefaultLoadingMode> for MysqlConnection
impl LoadConnection<DefaultLoadingMode> for MysqlConnection
source§fn load<'conn, 'query, T>(
&'conn mut self,
source: T
) -> QueryResult<LoadRowIter<'conn, 'query, Self, Self::Backend>>where
T: Query + QueryFragment<Self::Backend> + QueryId + 'query,
Self::Backend: QueryMetadata<T::SqlType>,
fn load<'conn, 'query, T>( &'conn mut self, source: T ) -> QueryResult<LoadRowIter<'conn, 'query, Self, Self::Backend>>where T: Query + QueryFragment<Self::Backend> + QueryId + 'query, Self::Backend: QueryMetadata<T::SqlType>,
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes only.Executes a given query and returns any requested values Read more
source§impl R2D2Connection for MysqlConnection
Available on crate feature r2d2 only.
impl R2D2Connection for MysqlConnection
Available on crate feature
r2d2 only.source§impl SimpleConnection for MysqlConnection
impl SimpleConnection for MysqlConnection
source§fn batch_execute(&mut self, query: &str) -> QueryResult<()>
fn batch_execute(&mut self, query: &str) -> QueryResult<()>
Execute multiple SQL statements within the same string. Read more
source§impl<'b, Changes, Output> UpdateAndFetchResults<Changes, Output> for MysqlConnectionwhere
Changes: Copy + Identifiable + AsChangeset<Target = <Changes as HasTable>::Table> + IntoUpdateTarget,
Changes::Table: FindDsl<Changes::Id>,
Update<Changes, Changes>: ExecuteDsl<MysqlConnection>,
Find<Changes::Table, Changes::Id>: LoadQuery<'b, MysqlConnection, Output>,
<Changes::Table as Table>::AllColumns: ValidGrouping<()>,
<<Changes::Table as Table>::AllColumns as ValidGrouping<()>>::IsAggregate: MixedAggregates<No, Output = No>,
impl<'b, Changes, Output> UpdateAndFetchResults<Changes, Output> for MysqlConnectionwhere Changes: Copy + Identifiable + AsChangeset<Target = <Changes as HasTable>::Table> + IntoUpdateTarget, Changes::Table: FindDsl<Changes::Id>, Update<Changes, Changes>: ExecuteDsl<MysqlConnection>, Find<Changes::Table, Changes::Id>: LoadQuery<'b, MysqlConnection, Output>, <Changes::Table as Table>::AllColumns: ValidGrouping<()>, <<Changes::Table as Table>::AllColumns as ValidGrouping<()>>::IsAggregate: MixedAggregates<No, Output = No>,
source§fn update_and_fetch(&mut self, changeset: Changes) -> QueryResult<Output>
fn update_and_fetch(&mut self, changeset: Changes) -> QueryResult<Output>
See the traits documentation.
impl Send for MysqlConnection
Auto Trait Implementations§
impl RefUnwindSafe for MysqlConnection
impl !Sync for MysqlConnection
impl Unpin for MysqlConnection
impl UnwindSafe for MysqlConnection
Blanket Implementations§
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> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> AsExprOf<Self, T>where
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
fn into_sql<T>(self) -> AsExprOf<Self, T>where Self: AsExpression<T> + Sized, T: SqlType + TypedExpressionType,
Convert
self to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>where
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,
Convert
&self to an expression for Diesel’s query builder. Read more