use serde_json::Value;
use crate::drivers::cloudflare_d1::client::D1ConnectionInfo;
use crate::drivers::scylla::client::ScyllaConnectionInfo;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AthenaEngine {
Postgres,
D1,
Scylla,
S3,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AthenaClientLifecycle {
Active,
Frozen,
Inactive,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AthenaCapabilities {
pub gateway_query: bool,
pub raw_sql: bool,
pub raw_cql: bool,
pub schema_read: bool,
pub migrations_read: bool,
pub provisioning: bool,
pub deferred_query: bool,
pub cdc: bool,
pub object_read: bool,
pub object_write: bool,
}
impl AthenaCapabilities {
pub fn for_engine(engine: AthenaEngine) -> Self {
match engine {
AthenaEngine::Postgres => Self {
gateway_query: true,
raw_sql: true,
raw_cql: false,
schema_read: true,
migrations_read: true,
provisioning: true,
deferred_query: true,
cdc: true,
object_read: false,
object_write: false,
},
AthenaEngine::D1 => Self {
gateway_query: true,
raw_sql: true,
raw_cql: false,
schema_read: false,
migrations_read: false,
provisioning: false,
deferred_query: false,
cdc: false,
object_read: false,
object_write: false,
},
AthenaEngine::Scylla => Self {
gateway_query: true,
raw_sql: false,
raw_cql: true,
schema_read: false,
migrations_read: false,
provisioning: false,
deferred_query: false,
cdc: false,
object_read: false,
object_write: false,
},
AthenaEngine::S3 => Self {
gateway_query: false,
raw_sql: false,
raw_cql: false,
schema_read: false,
migrations_read: false,
provisioning: false,
deferred_query: false,
cdc: false,
object_read: true,
object_write: true,
},
}
}
}
#[derive(Debug, Clone)]
pub struct AthenaPostgresConnection {
pub pg_uri: Option<String>,
pub pg_uri_env_var: Option<String>,
pub config_uri_template: Option<String>,
}
#[derive(Debug, Clone)]
pub struct AthenaD1Connection {
pub worker_base_url: String,
pub auth_token_env_var: String,
pub database_binding: String,
pub default_session_mode: Option<String>,
}
impl From<D1ConnectionInfo> for AthenaD1Connection {
fn from(value: D1ConnectionInfo) -> Self {
Self {
worker_base_url: value.worker_base_url,
auth_token_env_var: value.auth_token_env_var,
database_binding: value.database_binding,
default_session_mode: value.default_session_mode,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct AthenaS3Connection;
#[derive(Debug, Clone)]
pub enum AthenaConnection {
Postgres(AthenaPostgresConnection),
D1(AthenaD1Connection),
Scylla(ScyllaConnectionInfo),
S3(AthenaS3Connection),
}
#[derive(Debug, Clone)]
pub struct AthenaClientDefinition {
pub client_name: String,
pub description: Option<String>,
pub source: String,
pub engine: AthenaEngine,
pub lifecycle: AthenaClientLifecycle,
pub capabilities: AthenaCapabilities,
pub connection: AthenaConnection,
pub metadata: Value,
}