|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | +use stackable_operator::{ |
| 3 | + databases::{ |
| 4 | + databases::{ |
| 5 | + derby::DerbyConnection, mysql::MysqlConnection, postgresql::PostgresqlConnection, |
| 6 | + }, |
| 7 | + drivers::jdbc::JDBCDatabaseConnection, |
| 8 | + }, |
| 9 | + schemars::{self, JsonSchema}, |
| 10 | +}; |
| 11 | + |
| 12 | +#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)] |
| 13 | +#[serde(rename_all = "camelCase")] |
| 14 | +pub enum MetadataDatabaseConnection { |
| 15 | + /// TODO docs |
| 16 | + Postgresql(PostgresqlConnection), |
| 17 | + |
| 18 | + /// TODO docs |
| 19 | + /// |
| 20 | + /// Please note that - due to license issues - we don't ship the mysql driver, you need to add |
| 21 | + /// it it yourself. |
| 22 | + /// See <https://docs.stackable.tech/home/stable/hive/usage-guide/database-driver/> for details. |
| 23 | + Mysql(MysqlConnection), |
| 24 | + |
| 25 | + /// TODO docs |
| 26 | + Derby(DerbyConnection), |
| 27 | + // We don't support generic (yet?), as we need to tell the metastore the `--dbtype` on startup, |
| 28 | + // which is not known for generic connection. |
| 29 | + // Generic(GenericJDBCDatabaseConnection), |
| 30 | +} |
| 31 | + |
| 32 | +impl MetadataDatabaseConnection { |
| 33 | + pub fn as_jdbc_database_connection(&self) -> &dyn JDBCDatabaseConnection { |
| 34 | + match self { |
| 35 | + Self::Postgresql(p) => p, |
| 36 | + Self::Mysql(m) => m, |
| 37 | + Self::Derby(d) => d, |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + /// Name of the database as it should be passed using the `--db-type` CLI argument to Hive |
| 42 | + pub fn as_hive_db_type(&self) -> &str { |
| 43 | + match self { |
| 44 | + MetadataDatabaseConnection::Postgresql(_) => "postgres", |
| 45 | + MetadataDatabaseConnection::Mysql(_) => "mysql", |
| 46 | + MetadataDatabaseConnection::Derby(_) => "derby", |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments