Skip to content

Commit

Permalink
upgrade to V16 for example
Browse files Browse the repository at this point in the history
  • Loading branch information
olexiyb committed Jun 13, 2024
1 parent 4db3315 commit cb29fc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pg_embed::pg_enums::PgAuthMethod;
use pg_embed::pg_fetch::{PgFetchSettings, PG_V13};
use pg_embed::pg_fetch::{PgFetchSettings, PG_V16};
use pg_embed::postgres::{PgEmbed, PgSettings};
use sqlx_tokio::postgres::PgPoolOptions;
use std::error::Error;
Expand All @@ -11,8 +11,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Postgresql settings
let pg_settings = PgSettings {
// Where to store the postgresql database
database_dir: PathBuf::from("data/db"),
cache_dir: None,
database_dir: PathBuf::from("data").join("db"),
cache_dir: Some(PathBuf::from("data").join("cache")),
port: 5432,
user: "postgres".to_string(),
password: "password".to_string(),
Expand All @@ -32,7 +32,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Postgresql binaries download settings
let fetch_settings = PgFetchSettings {
version: PG_V13,
version: PG_V16,
..Default::default()
};

Expand Down
19 changes: 13 additions & 6 deletions src/pg_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ impl PgAccess {
cache_dir: Option<&PathBuf>,
) -> Result<Self, PgEmbedError> {
let cache_dir = match cache_dir {
Some(d) => d.clone(),
None => Self::create_cache_dir_structure(&fetch_settings).await?,
Some(d) => {
std::fs::create_dir_all(&d)
.map_err(|e| PgEmbedError {
error_type: PgEmbedErrorType::DirCreationError,
source: Some(Box::new(e)),
message: None,
})?;
d.clone()
},
None => Self::create_cache_dir_structure(&fetch_settings)?,
};

Self::create_db_dir_structure(database_dir).await?;
Expand Down Expand Up @@ -104,7 +112,7 @@ impl PgAccess {
///
/// Returns PathBuf(cache_directory) on success, an error otherwise
///
async fn create_cache_dir_structure(fetch_settings: &PgFetchSettings) -> PgResult<PathBuf> {
fn create_cache_dir_structure(fetch_settings: &PgFetchSettings) -> PgResult<PathBuf> {
let cache_dir = dirs::cache_dir().ok_or_else(|| PgEmbedError {
error_type: PgEmbedErrorType::InvalidPgUrl,
source: None,
Expand All @@ -127,13 +135,12 @@ impl PgAccess {
);
let mut cache_pg_embed = cache_dir.clone();
cache_pg_embed.push(pg_path);
tokio::fs::create_dir_all(&cache_pg_embed)
std::fs::create_dir_all(&cache_pg_embed)
.map_err(|e| PgEmbedError {
error_type: PgEmbedErrorType::DirCreationError,
source: Some(Box::new(e)),
message: None,
})
.await?;
})?;
Ok(cache_pg_embed)
}

Expand Down

0 comments on commit cb29fc7

Please sign in to comment.