use std::path::Path;
use serde::Deserialize;
use crate::column_types::models::ColumnType;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceColumn {
pub name: String,
pub postgres_type: String,
pub pg_type: PgType,
pub column_type: Result<ColumnType, String>,
pub nullable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceTable {
pub schema: String,
pub name: String,
pub columns: Vec<SourceColumn>,
pub primary_key: Vec<String>,
pub indexed_columns: Vec<String>,
pub estimated_rows: i64,
pub estimated_bytes: i64,
pub comment: Option<String>,
}
impl SourceTable {
pub fn qualified_name(&self) -> String {
match self.schema.is_empty() {
true => self.name.clone(),
false => format!("{}.{}", self.schema, self.name),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PgType {
Bool,
Int2,
Int4,
Int8,
Oid,
Float4,
Float8,
Numeric,
Text,
Varchar,
Date,
Time,
Timestamp,
TimestampTz,
Json,
Uuid,
Bytea,
Array,
Other,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WireType {
Bool,
Int2,
Int4,
Int8,
Float4,
Float8,
Numeric,
Text,
Uuid,
Bytea,
Date,
Time,
Timestamp,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReadColumn {
pub name: String,
pub expression: String,
pub wire: WireType,
pub output: ColumnType,
}
#[derive(Debug, Clone)]
pub struct PostgresAddress<'a> {
pub host: &'a str,
pub port: u16,
pub user: &'a str,
pub password: Option<&'a str>,
pub database: &'a str,
pub tls: PostgresTls<'a>,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct PostgresTls<'a> {
pub mode: SslMode,
pub root_cert: Option<&'a Path>,
pub cert: Option<&'a Path>,
pub key: Option<&'a Path>,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum SslMode {
Disable,
#[default]
Prefer,
Require,
VerifyCa,
VerifyFull,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Encryption {
None,
Unchecked,
CaChecked,
HostChecked,
}
impl std::fmt::Display for Encryption {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(match self {
Self::None => "not encrypted",
Self::Unchecked => "TLS, certificate not checked",
Self::CaChecked => "TLS, CA checked",
Self::HostChecked => "TLS, CA and host name checked",
})
}
}
#[derive(Debug)]
pub struct CopyRequest<'a> {
pub table: &'a SourceTable,
pub columns: Vec<ReadColumn>,
pub filter: Option<String>,
pub order_by: Option<String>,
pub batch_rows: usize,
pub batch_bytes: usize,
pub helpers: &'a [tokio_postgres::Client],
}