Skip to main content

toasty_driver_mysql/
mariadb.rs

1use super::MySQL;
2use async_trait::async_trait;
3use std::borrow::Cow;
4use toasty_core::{
5    Result,
6    driver::{Capability, ConnectContext, Connection, Driver},
7};
8
9/// A MariaDB 11.8+ [`Driver`] that connects through SQLx.
10///
11/// Uses MariaDB's native `UUID` type and `INSERT ... RETURNING`.
12///
13/// # Examples
14///
15/// ```
16/// use toasty_driver_mysql::MariaDB;
17///
18/// let driver = MariaDB::new("mariadb://localhost/mydb").unwrap();
19/// ```
20#[derive(Debug)]
21pub struct MariaDB {
22    inner: MySQL,
23}
24
25impl MariaDB {
26    /// Creates a MariaDB driver without connecting to the server.
27    ///
28    /// The URL must use the `mariadb` scheme and include a database path,
29    /// such as `mariadb://user:pass@host:3306/dbname`. The server must run
30    /// MariaDB 11.8 or later.
31    ///
32    /// # Errors
33    ///
34    /// Returns an error if the URL is malformed or uses another scheme.
35    pub fn new(url: impl Into<String>) -> Result<Self> {
36        Ok(Self {
37            inner: MySQL::with_capability(url, "mariadb", &Capability::MARIADB)?,
38        })
39    }
40}
41
42#[async_trait]
43impl Driver for MariaDB {
44    fn url(&self) -> Cow<'_, str> {
45        self.inner.url()
46    }
47
48    fn capability(&self) -> &'static Capability {
49        &Capability::MARIADB
50    }
51
52    async fn connect(&self, cx: &ConnectContext) -> Result<Box<dyn Connection>> {
53        self.inner.connect(cx).await
54    }
55
56    async fn reset_db(&self) -> Result<()> {
57        self.inner.reset_db().await
58    }
59}