pub struct MySqlConnection { /* private fields */ }Expand description
MySQL connection.
Manages a TCP connection to a MySQL server, handling the wire protocol, authentication, and state tracking.
Implementations§
Source§impl MySqlConnection
impl MySqlConnection
Sourcepub fn connect(config: MySqlConfig) -> Result<Self, Error>
pub fn connect(config: MySqlConfig) -> Result<Self, Error>
Establish a new connection to the MySQL server.
This performs the complete connection handshake:
- TCP connection
- Receive server handshake
- Send handshake response with authentication
- Handle auth result (possibly auth switch)
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
Get the current connection state.
Sourcepub fn connection_id(&self) -> u32
pub fn connection_id(&self) -> u32
Get the connection ID.
Sourcepub fn server_version(&self) -> Option<&str>
pub fn server_version(&self) -> Option<&str>
Get the server version.
Sourcepub fn affected_rows(&self) -> u64
pub fn affected_rows(&self) -> u64
Get the number of affected rows from the last statement.
Sourcepub fn last_insert_id(&self) -> u64
pub fn last_insert_id(&self) -> u64
Get the last insert ID.
Sourcepub fn query_sync(
&mut self,
sql: &str,
params: &[Value],
) -> Result<Vec<Row>, Error>
pub fn query_sync( &mut self, sql: &str, params: &[Value], ) -> Result<Vec<Row>, Error>
Execute a text protocol query with parameters (synchronous).
Returns a vector of rows for SELECT queries, or empty for other statements. Parameters are interpolated into the SQL string with proper escaping.
Sourcepub fn query_one_sync(
&mut self,
sql: &str,
params: &[Value],
) -> Result<Option<Row>, Error>
pub fn query_one_sync( &mut self, sql: &str, params: &[Value], ) -> Result<Option<Row>, Error>
Execute a query and return the first row, if any (synchronous).
Sourcepub fn execute_sync(
&mut self,
sql: &str,
params: &[Value],
) -> Result<u64, Error>
pub fn execute_sync( &mut self, sql: &str, params: &[Value], ) -> Result<u64, Error>
Execute a statement that doesn’t return rows (synchronous).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MySqlConnection
impl RefUnwindSafe for MySqlConnection
impl Send for MySqlConnection
impl Sync for MySqlConnection
impl Unpin for MySqlConnection
impl UnwindSafe for MySqlConnection
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).