Skip to content

Commit

Permalink
Added validate function to PgConfig and invoked it in finalize and po…
Browse files Browse the repository at this point in the history
…ol initialization
  • Loading branch information
Saru2003 committed Oct 21, 2024
1 parent 6f201fc commit 55289af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions martin/src/pg/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ pub struct PgCfgPublishFuncs {

impl PgConfig {
/// Apply defaults to the config, and validate if there is a connection string
pub fn validate(&self) -> PgResult<()> {
if let Some(pool_size) = self.pool_size() {
if pool_size < 1{
return Err("pool_size must be greater than or equal to 1.".into());
}
}
if self.connection_string.is_none() {
return Err("A connection string must be provided.".into());
}

Ok(())
}


pub fn finalize(&mut self) -> PgResult<UnrecognizedValues> {
let mut res = UnrecognizedValues::new();
if let Some(ref ts) = self.tables {
Expand All @@ -110,10 +124,12 @@ impl PgConfig {
self.auto_publish = OptBoolObj::Bool(true);
}

self.validate()?;
Ok(res)
}

pub async fn resolve(&mut self, id_resolver: IdResolver) -> MartinResult<TileInfoSources> {
self.validate()?;
let pg = PgBuilder::new(self, id_resolver).await?;
let inst_tables = on_slow(
pg.instantiate_tables(),
Expand Down
2 changes: 2 additions & 0 deletions martin/src/pg/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct PgPool {

impl PgPool {
pub async fn new(config: &PgConfig) -> PgResult<Self> {
config.validate()?;

let (id, mgr) = Self::parse_config(config)?;

let pool = Pool::builder(mgr)
Expand Down

0 comments on commit 55289af

Please sign in to comment.