use std::path::PathBuf;
use crate::supertable::reader_cache::ColdFetchMode as InternalColdFetchMode;
#[derive(Debug, Clone)]
pub(crate) struct S3Config {
pub(crate) endpoint: String,
pub(crate) region: String,
pub(crate) access_key: String,
pub(crate) secret_key: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ColdFetchMode {
HybridWithPrefetch,
RangeOnly,
#[default]
LazyForegroundWithBackgroundFill,
}
impl ColdFetchMode {
pub(crate) fn to_internal(self) -> InternalColdFetchMode {
match self {
ColdFetchMode::HybridWithPrefetch => InternalColdFetchMode::HybridWithPrefetch,
ColdFetchMode::RangeOnly => InternalColdFetchMode::RangeOnly,
ColdFetchMode::LazyForegroundWithBackgroundFill => {
InternalColdFetchMode::LazyForegroundWithBackgroundFill
}
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ConnectOptions {
pub(crate) s3: Option<S3Config>,
pub(crate) cache_dir: Option<PathBuf>,
pub(crate) cache_budget_bytes: Option<u64>,
pub(crate) cold_fetch_mode: ColdFetchMode,
}
impl ConnectOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_cache_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.cache_dir = Some(dir.into());
self
}
pub fn with_cache_budget_bytes(mut self, bytes: u64) -> Self {
self.cache_budget_bytes = Some(bytes);
self
}
pub fn with_cold_fetch_mode(mut self, mode: ColdFetchMode) -> Self {
self.cold_fetch_mode = mode;
self
}
pub fn with_s3_endpoint(
mut self,
endpoint: impl Into<String>,
region: impl Into<String>,
access_key: impl Into<String>,
secret_key: impl Into<String>,
) -> Self {
self.s3 = Some(S3Config {
endpoint: endpoint.into(),
region: region.into(),
access_key: access_key.into(),
secret_key: secret_key.into(),
});
self
}
}