58 lines
1.3 KiB
Rust
58 lines
1.3 KiB
Rust
pub mod config;
|
|
pub mod postgresql;
|
|
pub mod sqlite;
|
|
|
|
use async_trait::async_trait;
|
|
use shared::db_type::DBType;
|
|
use std::error::Error;
|
|
use std::sync::Arc;
|
|
use url::Host;
|
|
|
|
use testcontainers::{ContainerAsync, GenericImage};
|
|
|
|
use crate::{
|
|
WithContainer, WithoutContainer,
|
|
containers::{DBConfigInfoType, UnStartedContainer},
|
|
};
|
|
|
|
#[derive(Clone)]
|
|
pub struct PreExistingDBInfo {
|
|
pub db_type: DBType,
|
|
pub url: String,
|
|
pub on_delete: Arc<dyn Fn() + Send + Sync>,
|
|
}
|
|
|
|
impl WithoutContainer for PreExistingDBInfo {
|
|
fn on_delete(&self) {
|
|
(self.on_delete)();
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct ContainerizedDBInfo {
|
|
pub db_type: DBType,
|
|
pub container: Arc<ContainerAsync<GenericImage>>,
|
|
pub container_name: String,
|
|
pub database_name: String,
|
|
pub host: Host,
|
|
pub port: u16,
|
|
pub url: String,
|
|
pub user: String,
|
|
pub password: String,
|
|
}
|
|
|
|
impl WithContainer for ContainerizedDBInfo {
|
|
fn container(&self) -> &Arc<ContainerAsync<GenericImage>> {
|
|
&self.container
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait DBInfo<T> {
|
|
async fn new(config: Option<T>) -> Self
|
|
where
|
|
Self: Sized;
|
|
async fn get_db_container_config_info(&self) -> DBConfigInfoType;
|
|
fn get_unstarted_container(&self) -> Result<UnStartedContainer, Box<dyn Error>>;
|
|
}
|