Skip to main content

toasty_cli/
flavor.rs

1use serde::{Deserialize, Serialize};
2use toasty::db::Capability;
3
4/// The database flavor a migration targets: selects the capability the schema
5/// is lowered with and the SQL dialect it is rendered in.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, clap::ValueEnum)]
7#[serde(rename_all = "lowercase")]
8pub enum Flavor {
9    /// SQLite
10    Sqlite,
11
12    /// PostgreSQL
13    Postgresql,
14
15    /// MySQL
16    Mysql,
17
18    /// MariaDB
19    ///
20    /// Distinct from [`Flavor::Mysql`]: MariaDB has its own dialect and a
21    /// native `UUID` column type.
22    #[value(name = "mariadb")]
23    MariaDb,
24
25    /// Turso
26    Turso,
27}
28
29impl Flavor {
30    /// The name passed to the schema dumper in `TOASTY_DUMP_SCHEMA`.
31    pub fn as_str(&self) -> &'static str {
32        match self {
33            Flavor::Sqlite => "sqlite",
34            Flavor::Postgresql => "postgresql",
35            Flavor::Mysql => "mysql",
36            Flavor::MariaDb => "mariadb",
37            Flavor::Turso => "turso",
38        }
39    }
40
41    /// The capability describing the target database.
42    pub fn capability(&self) -> &'static Capability {
43        match self {
44            Flavor::Sqlite => &Capability::SQLITE,
45            Flavor::Postgresql => &Capability::POSTGRESQL,
46            Flavor::Mysql => &Capability::MYSQL,
47            Flavor::MariaDb => &Capability::MARIADB,
48            Flavor::Turso => &Capability::TURSO,
49        }
50    }
51}
52
53impl std::fmt::Display for Flavor {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        f.write_str(self.as_str())
56    }
57}