use std::sync::Arc;
use crate::adapters::postgres::models::PostgresDestination;
use crate::loader::errors::LoaderError;
use crate::project::models::{ConnectionConfig, ProjectConfig};
pub(in crate::adapters) fn open_postgres(
project: &ProjectConfig,
connection: &str,
database: Option<&str>,
) -> Result<PostgresDestination, LoaderError> {
let Some(ConnectionConfig::Postgres { .. }) = project.connections.get(connection) else {
return Err(LoaderError::Invalid(format!(
"connection {connection:?} is not a Postgres connection"
)));
};
Ok(PostgresDestination {
project: Arc::new(project.clone()),
connection: connection.to_owned(),
database: database.map(str::to_owned),
session: Arc::default(),
reconnects: true,
ddl: Arc::default(),
})
}