pub struct CreateOptions {
pub(crate) url: String,
pub(crate) data_path: String,
pub(crate) storage_options: Vec<(String, String)>,
}
impl CreateOptions {
pub fn new(url: &str, data_path: &str) -> Self {
Self {
url: url.to_string(),
data_path: data_path.to_string(),
storage_options: Vec::new(),
}
}
pub fn with_storage_option(mut self, key: &str, value: &str) -> Self {
self.storage_options
.push((key.to_string(), value.to_string()));
self
}
pub fn with_storage_options(mut self, options: Vec<(String, String)>) -> Self {
self.storage_options.extend(options);
self
}
}
pub(crate) enum ConnectionType {
Latest,
SnapshotId(i64),
SnapshotTimestamp(chrono::DateTime<chrono::Utc>),
}
pub struct ConnectOptions {
pub(crate) url: String,
pub(crate) migrate: bool,
pub(crate) storage_options: Vec<(String, String)>,
pub(crate) connection_type: ConnectionType,
}
impl ConnectOptions {
pub fn new(url: &str) -> Self {
Self {
url: url.to_string(),
migrate: false,
storage_options: Vec::new(),
connection_type: ConnectionType::Latest,
}
}
pub fn with_migrate(mut self, migrate: bool) -> Self {
self.migrate = migrate;
self
}
pub fn with_storage_option(mut self, key: &str, value: &str) -> Self {
self.storage_options
.push((key.to_string(), value.to_string()));
self
}
pub fn with_storage_options(mut self, options: Vec<(String, String)>) -> Self {
self.storage_options.extend(options);
self
}
pub fn with_latest_snapshot(mut self) -> Self {
self.connection_type = ConnectionType::Latest;
self
}
pub fn with_snapshot_id(mut self, snapshot_id: i64) -> Self {
self.connection_type = ConnectionType::SnapshotId(snapshot_id);
self
}
pub fn with_snapshot_timestamp(mut self, timestamp: chrono::DateTime<chrono::Utc>) -> Self {
self.connection_type = ConnectionType::SnapshotTimestamp(timestamp);
self
}
}