Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: utilize sqlx for database management to support PostgreSQL installations that do not bundle psql #95

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 68 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ serde_json = "1.0.118"
sha1 = "0.10.6"
sha2 = "0.10.8"
sha3 = "0.10.8"
sqlx = { version = "0.7.4", default-features = false, features = ["postgres"] }
tar = "0.4.41"
target-triple = "0.1.3"
test-log = "0.2.16"
Expand Down
11 changes: 11 additions & 0 deletions examples/zonky/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition.workspace = true
name = "zonky"
publish = false
license.workspace = true
version.workspace = true

[dependencies]
postgresql_archive = { path = "../../postgresql_archive" }
postgresql_embedded = { path = "../../postgresql_embedded" }
tokio = { workspace = true, features = ["full"] }
35 changes: 35 additions & 0 deletions examples/zonky/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![forbid(unsafe_code)]
#![deny(clippy::pedantic)]

use postgresql_archive::configuration::zonky;
use postgresql_archive::VersionReq;
use postgresql_embedded::{PostgreSQL, Result, Settings};

#[tokio::main]
async fn main() -> Result<()> {
let settings = Settings {
releases_url: zonky::URL.to_string(),
version: VersionReq::parse("=16.2.0")?,
..Default::default()
};
let mut postgresql = PostgreSQL::new(settings);
postgresql.setup().await?;
postgresql.start().await?;

let database_name = "test";
postgresql.create_database(database_name).await?;
postgresql.database_exists(database_name).await?;
postgresql.drop_database(database_name).await?;

postgresql.stop().await
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_main() -> Result<()> {
main()
}
}
14 changes: 11 additions & 3 deletions postgresql_embedded/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ postgresql_archive = { path = "../postgresql_archive", version = "0.12.0", defau
postgresql_commands = { path = "../postgresql_commands", version = "0.12.0" }
rand = { workspace = true }
semver = { workspace = true }
sqlx = { workspace = true, features = ["runtime-tokio"] }
tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"], optional = true }
Expand All @@ -39,11 +40,18 @@ tokio = { workspace = true, features = ["full"] }
default = ["rustls-tls"]
blocking = ["tokio"]
bundled = []
native-tls = ["postgresql_archive/native-tls"]
rustls-tls = ["postgresql_archive/rustls-tls"]
native-tls = [
"postgresql_archive/native-tls",
"sqlx/tls-native-tls",
]
rustls-tls = [
"postgresql_archive/rustls-tls",
"sqlx/tls-rustls",
]
tokio = [
"dep:tokio",
"postgresql_commands/tokio"
"postgresql_commands/tokio",
"sqlx/runtime-tokio",
]

[package.metadata.release]
Expand Down
3 changes: 3 additions & 0 deletions postgresql_embedded/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub enum Error {
/// Error when the database could not be created
#[error(transparent)]
CreateDatabaseError(anyhow::Error),
/// Error when accessing the database
#[error(transparent)]
DatabaseError(#[from] sqlx::Error),
/// Error when determining if the database exists
#[error(transparent)]
DatabaseExistsError(anyhow::Error),
Expand Down
Loading
Loading