Docs.rs
  • mysql-connector-0.0.2
    • mysql-connector 0.0.2
    • Docs.rs crate page
    • MIT
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • untbu
    • github:riseupgroup:owners
    • Dependencies
      • bitflags ^2.5.0 normal
      • btoi ^0.4.3 normal
      • bytes ^1.6.0 normal
      • chrono ^0.4.38 normal
      • crossbeam ^0.8.4 normal
      • hex ^0.4.3 normal
      • lazy_static ^1.4.0 normal
      • mysql-connector-macros ^0.0.2 normal
      • paste ^1.0.15 normal
      • serde ^1.0.203 normal optional
      • sha1 ^0.10.6 normal
      • tokio ^1.38.0 normal
      • dotenv ^0.15.0 dev
      • tokio ^1.38.0 dev
    • Versions
    • 1.85% of the crate is documented
  • Go to latest version
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate mysql_connector

mysql_connector0.0.2

  • All Items
  • Re-exports
  • Modules
  • Macros
  • Structs

Crates

  • mysql_connector
?
Settings

Crate mysql_connector

source ·
Expand description

§mysql-connector

Simple MySQL connector for Rust that allows exchanging the underlying connection.

§Features

  • tcpstream (enabled by default): implements the Stream trait for tokio’s TcpStream.
  • serde: implements serde::Serialize and serde::Deserialize for some types.

§Example

use std::sync::Arc;

use mysql_connector::{
    macros::*, model::*, types::AuthPlugin, Connection, ConnectionOptions, TcpStream,
};

#[derive(Debug, ModelData, FromQueryResult, ActiveModel, IntoQuery, Model)]
#[mysql_connector(table = "user", primary = "id", auto_increment = "true")]
pub struct User {
    id: u32,
    name: String,
    email: Option<String>,
}

#[tokio::main]
async fn main() {
    dotenv::dotenv().unwrap();
    let mut conn = <Connection<TcpStream>>::connect(Arc::new(ConnectionOptions {
        user: "user".into(),
        password: std::env::var("PASSWORD").unwrap(),
        db_name: Some("db".into()),
        host: Some("localhost".into()),
        secure_auth: false,
        auth_plugin: Some(AuthPlugin::Native),
        ..Default::default()
    }))
    .await
    .unwrap();

    conn.execute_query(
        "CREATE TABLE `user` (
            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
            `name` VARCHAR(255) NOT NULL,
            `email` VARCHAR(255)
        )",
    )
    .await
    .unwrap();

    User {
        id: 0,
        name: String::from("foo"),
        email: Some(String::from("foo@example.com")),
    }
    .into_active_model()
    .insert(&mut conn)
    .await
    .unwrap();

    User {
        id: 0,
        name: String::from("bar"),
        email: None,
    }
    .into_active_model()
    .insert(&mut conn)
    .await
    .unwrap();

    let users: Vec<User> = conn
        .query(&User::build_query())
        .await
        .unwrap()
        .collect()
        .await
        .unwrap();
    println!("{users:?}");

    conn.disconnect().await.unwrap();
}

Re-exports§

  • pub use error::Error;
  • pub use mysql_connector_macros as macros;
  • pub use connection::*;

Modules§

  • connection
  • error
  • migrator
  • model
  • pool
  • types

Macros§

  • simple_migration

Structs§

  • TcpStream
    A TCP stream between a local and a remote socket.

Results

module
mysql_connector::model
trait
mysql_connector::model::Model
trait
mysql_connector::model::ModelData
trait
mysql_connector::model::ActiveModel
assoc type
mysql_connector::model::HasActiveModel::ActiveModel
struct
mysql_connector::model::UpdateModel
method
mysql_connector::model::Model::active_model
method
mysql_connector::model::Model::update_model
trait
mysql_connector::model::HasActiveModel
trait method
mysql_connector::model::HasActiveModel::into_active_model
Create ActiveModel containing the model’s data.
method
mysql_connector::model::UpdateModel::deref
trait method
mysql_connector::model::Model::primary
method
mysql_connector::model::UpdateModel::deref_mut
method
mysql_connector::model::Model::update_model
method
mysql_connector::model::ActiveReference::fmt
method
mysql_connector::model::UpdateModel::fmt
method
mysql_connector::model::UpdateModel::update
method
mysql_connector::model::ActiveReference::insert_named_value
method
mysql_connector::model::UpdateModel::new
method
mysql_connector::model::ActiveReference::default
method
mysql_connector::model::Model::update_model