### PostgreSQL Server - Default Setup (Async) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Demonstrates setting up and managing a PostgreSQL server instance with default asynchronous settings. It handles downloading, installing, initializing, and starting PostgreSQL on a random ephemeral port. Supports creating, checking, and dropping databases. ```rust use postgresql_embedded::{PostgreSQL, Result}; #[tokio::main] async fn main() -> Result<()> { // Create PostgreSQL with default settings (auto-downloads latest version) let mut postgresql = PostgreSQL::default(); // Setup downloads/extracts archive and initializes database postgresql.setup().await?; // Start server on random ephemeral port postgresql.start().await?; // Create a new database let database_name = "my_app_db"; postgresql.create_database(database_name).await?; // Check if database exists let exists = postgresql.database_exists(database_name).await?; println!("Database exists: {}", exists); // Output: Database exists: true // Drop the database postgresql.drop_database(database_name).await?; // Stop the server gracefully postgresql.stop().await?; Ok(()) } ``` -------------------------------- ### Basic PostgreSQL Setup and Operations in Rust Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/README.md Demonstrates the basic setup, start, stop, and database management operations for an embedded PostgreSQL instance using the `postgresql-embedded` crate. It requires the `tokio` runtime for asynchronous operations. ```rust use postgresql_embedded::{PostgreSQL, Result}; #[tokio::main] async fn main() -> Result<()> { let mut postgresql = PostgreSQL::default(); 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 } ``` -------------------------------- ### Integrate Embedded PostgreSQL with SQLx (Rust) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Demonstrates how to set up and start an embedded PostgreSQL instance, create a database, and then connect to it using the SQLx library for asynchronous database operations. This includes creating tables, inserting data, and querying records. ```rust use postgresql_embedded::{PostgreSQL, Result as PgResult}; use sqlx::{PgPool, Row}; #[tokio::main] async fn main() -> anyhow::Result<()> { // Setup embedded PostgreSQL let mut postgresql = PostgreSQL::default(); postgresql.setup().await?; postgresql.start().await?; let database_name = "sqlx_demo"; postgresql.create_database(database_name).await?; // Connect with SQLx let database_url = postgresql.settings().url(database_name); let pool = PgPool::connect(&database_url).await?; // Create table sqlx::query( "CREATE TABLE IF NOT EXISTS users ( id BIGSERIAL PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE NOT NULL )" ).execute(&pool).await?; // Insert data let row = sqlx::query( "INSERT INTO users (name, email) VALUES ($1, $2) RETURNING id" ) .bind("Alice") .bind("alice@example.com") .fetch_one(&pool) .await?; let user_id: i64 = row.get("id"); println!("Created user with ID: {}", user_id); // Output: Created user with ID: 1 // Query data let users = sqlx::query("SELECT id, name, email FROM users") .fetch_all(&pool) .await?; for user in users { let id: i64 = user.get("id"); let name: String = user.get("name"); let email: String = user.get("email"); println!("User {}: {} <{}>", id, name, email); // Output: User 1: Alice } pool.close().await; postgresql.stop().await?; Ok(()) } ``` -------------------------------- ### Manage PostgreSQL Extensions with Rust Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Installs, lists, and uninstalls PostgreSQL extensions using the `postgresql_extensions` crate. It requires setting up a PostgreSQL instance and provides functions to interact with available and installed extensions. Dependencies include `postgresql-embedded` and `tokio` for async operations. ```rust use postgresql_embedded::{PostgreSQL, Result, Settings, VersionReq}; use postgresql_extensions::{get_available_extensions, get_installed_extensions, install, uninstall}; #[tokio::main] async fn main() -> Result<()> { // Setup PostgreSQL let settings = Settings { version: VersionReq::parse("=16.4.0")?, ..Default::default() }; let mut postgresql = PostgreSQL::new(settings); postgresql.setup().await?; // List available extensions from repositories let available = get_available_extensions().await?; println!("Available extensions: {}", available.len()); for ext in available.iter().take(5) { println!(" - {}/{}", ext.namespace(), ext.name()); } // Output: // Available extensions: 42 // - tensor-chord/pgvecto.rs // - portal-corp/pgvector // - steampipe/steampipe-plugin-aws // - ... // Install an extension install( postgresql.settings(), "tensor-chord", // namespace "pgvecto.rs", // extension name &VersionReq::parse("=0.4.0")?, ).await?; println!("Extension installed"); // List installed extensions let installed = get_installed_extensions(postgresql.settings()).await?; for ext in &installed { println!("Installed: {}/{} v{}", ext.namespace(), ext.name(), ext.version()); } // Output: Installed: tensor-chord/pgvecto.rs v0.4.0 // Uninstall extension uninstall(postgresql.settings(), "tensor-chord", "pgvecto.rs").await?; Ok(()) } ``` -------------------------------- ### PostgreSQL Server - Custom Version and Settings (Async) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Illustrates configuring a PostgreSQL server with specific version requirements and custom settings using the asynchronous API. This includes defining host, port, credentials, installation directory, timeouts, and database configurations. ```rust use postgresql_embedded::{PostgreSQL, Result, Settings, VersionReq}; use std::time::Duration; use std::collections::HashMap; #[tokio::main] async fn main() -> Result<()> { // Create settings with specific PostgreSQL version let settings = Settings { version: VersionReq::parse("=16.4.0")?, host: "127.0.0.1".to_string(), port: 5433, username: "admin".to_string(), password: "secure_password".to_string(), temporary: false, // Don't delete data dir on drop timeout: Some(Duration::from_secs(30)), configuration: HashMap::from([ ("max_connections".to_string(), "100".to_string()), ("shared_buffers".to_string(), "256MB".to_string()), ]), ..Default::default() }; let mut postgresql = PostgreSQL::new(settings); postgresql.setup().await?; postgresql.start().await?; // Get connection URL for a specific database let settings = postgresql.settings(); let database_url = settings.url("postgres"); println!("Connection URL: {}", database_url); // Output: Connection URL: postgresql://admin:secure_password@127.0.0.1:5433/postgres // Check server status let status = postgresql.status(); println!("Server status: {:?}", status); // Output: Server status: Started postgresql.stop().await?; Ok(()) } ``` -------------------------------- ### Connect to PostgreSQL with 'postgres' Crate (Blocking) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Demonstrates how to set up, start, and connect to an embedded PostgreSQL instance using the standard 'postgres' crate for synchronous database operations. It shows table creation, data insertion, and querying. Requires the 'postgres' and 'anyhow' crates. ```rust use postgresql_embedded::Result as PgResult; use postgresql_embedded::blocking::PostgreSQL; use postgres::{Client, NoTls}; fn main() -> anyhow::Result<()> { let mut postgresql = PostgreSQL::default(); postgresql.setup()?; postgresql.start()?; let database_name = "postgres_demo"; postgresql.create_database(database_name)?; // Connect with postgres crate let settings = postgresql.settings(); let mut client = Client::connect( &format!( "host={} port={} user={} password={} dbname={}", settings.host, settings.port, settings.username, settings.password, database_name ), NoTls, )?; // Create and query client.execute( "CREATE TABLE products (id SERIAL PRIMARY KEY, name TEXT, price DECIMAL)", &[], )?; client.execute( "INSERT INTO products (name, price) VALUES ($1, $2)", &[&"Widget", &19.99_f64], )?; let rows = client.query("SELECT id, name, price FROM products", &[])?; for row in rows { let id: i32 = row.get("id"); let name: String = row.get("name"); let price: f64 = row.get("price"); println!("Product {}: {} - ${:.2}", id, name, price); // Output: Product 1: Widget - $19.99 } postgresql.stop()?; Ok(()) } ``` -------------------------------- ### Integrate PostgreSQL with Diesel ORM and Migrations (Async) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Shows how to integrate embedded PostgreSQL with the Diesel ORM, including running database migrations. This example uses asynchronous operations and requires Diesel, diesel-migrations, and tokio dependencies. ```rust use diesel::r2d2::{ConnectionManager, Pool}; use diesel::{PgConnection, RunQueryDsl, Insertable, Queryable, Selectable}; use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations}; use postgresql_embedded::{PostgreSQL, Result, Settings, VersionReq}; // Embed migrations from ./migrations directory const MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations/"); #[derive(Queryable, Selectable)] #[diesel(table_name = posts)] struct Post { id: i32, title: String, body: String, } #[derive(Insertable)] #[diesel(table_name = posts)] struct NewPost<'a> { title: &'a str, body: &'a str, } diesel::table! { posts (id) { id -> Integer, title -> Text, body -> Text, } } #[tokio::main] async fn main() -> Result<()> { let settings = Settings { version: VersionReq::parse("=16.4.0")?, username: "postgres".to_string(), password: "postgres".to_string(), ..Default::default() }; let mut postgresql = PostgreSQL::new(settings); postgresql.setup().await?; postgresql.start().await?; let database_name = "diesel_demo"; postgresql.create_database(database_name).await?; // Create connection pool let database_url = postgresql.settings().url(database_name); let manager = ConnectionManager::::new(database_url); let pool = Pool::builder() .test_on_check_out(true) .build(manager) .expect("Could not build connection pool"); // Run migrations let mut conn = pool.get().unwrap(); conn.run_pending_migrations(MIGRATIONS).unwrap(); // Insert data let new_post = NewPost { title: "My First Post", body: "Hello, Diesel!", }; diesel::insert_into(posts::table) .values(&new_post) .execute(&mut conn) .expect("Error saving post"); println!("Post created successfully"); // Output: Post created successfully postgresql.stop().await?; Ok(()) } ``` -------------------------------- ### Extensions Crate with Specific Extensions Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This configuration for the `postgresql_extensions` crate enables support for specific PostgreSQL extensions. The example includes features for `portal-corp`, `steampipe`, and `tensor-chord`, allowing you to integrate these extensions into your PostgreSQL environment managed by the crate. ```toml [dependencies] postgresql_extensions = { version = "0.20", features = ["portal-corp", "steampipe", "tensor-chord"] } ``` -------------------------------- ### Control PostgreSQL Server with pg_ctl Builder in Rust Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Manages PostgreSQL server instances using the `postgresql_commands::pg_ctl::PgCtlBuilder`. This builder supports various modes like Start, Stop, and Status, allowing configuration of the data directory, log files, specific options, and shutdown modes. It simplifies server control operations within Rust applications. ```rust use postgresql_commands::pg_ctl::{PgCtlBuilder, Mode, ShutdownMode}; use postgresql_commands::CommandBuilder; fn main() { // Start command let start_command = PgCtlBuilder::new() .program_dir("/usr/local/pgsql/bin") .mode(Mode::Start) .pgdata("/var/lib/postgresql/data") .log("/var/log/postgresql/startup.log") .options(&["-p 5432", "-c shared_buffers=256MB"]) .wait() .build(); // Stop command let stop_command = PgCtlBuilder::new() .program_dir("/usr/local/pgsql/bin") .mode(Mode::Stop) .pgdata("/var/lib/postgresql/data") .shutdown_mode(ShutdownMode::Fast) .wait() .build(); // Status command let status_command = PgCtlBuilder::new() .program_dir("/usr/local/pgsql/bin") .mode(Mode::Status) .pgdata("/var/lib/postgresql/data") .build(); println!("pg_ctl commands configured"); } ``` -------------------------------- ### Get Available Extensions Asynchronously - Rust Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/postgresql_extensions/README.md Retrieves a list of available PostgreSQL extensions using the asynchronous API. This function is part of the main `postgresql_extensions` library and requires the `tokio` runtime. ```rust use postgresql_extensions::{get_available_extensions, Result}; #[tokio::main] async fn main() -> Result<()> { let extensions = get_available_extensions().await?; Ok(()) } ``` -------------------------------- ### Get Available Extensions Synchronously - Rust Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/postgresql_extensions/README.md Retrieves a list of available PostgreSQL extensions using the synchronous API. This function is available when the `blocking` feature flag is enabled and is part of the `postgresql_extensions::blocking` module. ```rust use postgresql_extensions::Result; use postgresql_extensions::blocking::get_available_extensions; async fn main() -> Result<()> { let extensions = get_available_extensions().await?; Ok(()) } ``` -------------------------------- ### Full Featured PostgreSQL Embedded with Tokio Runtime Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This comprehensive configuration enables multiple features for `postgresql_embedded`: `blocking` for synchronous operations, `tokio` for integration with the Tokio runtime, and `bundled` to include PostgreSQL binaries within the application. This setup provides a robust and self-contained PostgreSQL environment. ```toml [dependencies] postgresql_embedded = { version = "0.20", features = ["blocking", "tokio", "bundled"] } ``` -------------------------------- ### Create PostgreSQL Settings from URL (Rust) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Demonstrates how to create PostgreSQL settings by parsing a connection URL string. This includes query parameters for various configuration options like version, directories, and specific settings. It utilizes the `Settings::from_url` method. ```rust use postgresql_embedded::{Result, Settings}; fn main() -> Result<()> { // Create settings from URL with query parameters let url = "postgresql://admin:secret@localhost:5432/mydb?\ version=%3D16.4.0&\ installation_dir=/opt/postgresql&\ data_dir=/var/lib/postgresql/data&\ temporary=false&\ timeout=30&\ configuration.max_connections=200&\ configuration.work_mem=64MB"; let settings = Settings::from_url(url)?; println!("Host: {}", settings.host); println!("Port: {}", settings.port); println!("Username: {}", settings.username); println!("Version: {}", settings.version); println!("Binary dir: {:?}", settings.binary_dir()); // Output: // Host: localhost // Port: 5432 // Username: admin // Version: =16.4.0 // Binary dir: "/opt/postgresql/bin" Ok(()) } ``` -------------------------------- ### Build initdb Command with Rust Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Initializes a new PostgreSQL database cluster using `postgresql_commands::initdb::InitDbBuilder`. This builder facilitates the configuration of `initdb` parameters such as the data directory, username, authentication method, password file, encoding, and locale. It's essential for setting up new PostgreSQL instances programmatically. ```rust use postgresql_commands::initdb::InitDbBuilder; use postgresql_commands::CommandBuilder; fn main() { let command = InitDbBuilder::new() .program_dir("/usr/local/pgsql/bin") .pgdata("/var/lib/postgresql/data") .username("postgres") .auth("password") .pwfile("/tmp/.pgpass") .encoding("UTF8") .locale("en_US.UTF-8") .build(); println!("InitDb command configured for cluster initialization"); } ``` -------------------------------- ### Bundling PostgreSQL Binaries with PostgreSQL Embedded Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This snippet demonstrates how to bundle PostgreSQL binaries directly into your application binary using the `bundled` feature. This eliminates the need for runtime downloads, making deployment simpler and ensuring consistent binary versions across environments. ```toml [dependencies] postgresql_embedded = { version = "0.20", features = ["bundled"] } ``` -------------------------------- ### Execute PostgreSQL Command with PsqlBuilder in Rust Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/postgresql_commands/README.md Demonstrates how to use `PsqlBuilder` to construct and execute a PostgreSQL command. It specifies connection details like host, port, username, and password. The `execute` method returns standard output and standard error. ```rust use postgresql_commands::Result; use postgresql_commands::psql::PsqlBuilder; fn main() -> Result<()> { let psql = PsqlBuilder::new() .command("CREATE DATABASE \"test\"") .host("127.0.0.1") .port(5432) .username("postgresql") .pg_password("password") .build(); let (stdout, stderr) = psql.execute()?; Ok(()) } ``` -------------------------------- ### Download and Extract PostgreSQL Archive (Async) Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/postgresql_archive/README.md This snippet demonstrates how to asynchronously download and extract a PostgreSQL archive using the `postgresql_archive` crate. It utilizes the `tokio` runtime and specifies the version requirement using `VersionReq::STAR`. The output directory is set to the system's temporary directory. ```rust use postgresql_archive::{extract, get_archive, Result, VersionReq}; use postgresql_archive::configuration::theseus; #[tokio::main] async fn main() -> Result<()> { let url = theseus::URL; let (archive_version, archive) = get_archive(url, &VersionReq::STAR).await?; let out_dir = std::env::temp_dir(); extract(url, &archive, &out_dir).await } ``` -------------------------------- ### Build createdb Command with Rust Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Programmatically builds a `createdb` command using `postgresql_commands::createdb::CreateDbBuilder`. This allows setting database name, owner, encoding, locale, template, and connection parameters like host, port, and user. The builder simplifies the creation of `createdb` commands for automated database provisioning. ```rust use postgresql_commands::createdb::CreateDbBuilder; use postgresql_commands::CommandBuilder; fn main() { let command = CreateDbBuilder::new() .program_dir("/usr/local/pgsql/bin") .host("localhost") .port(5432) .username("postgres") .pg_password("admin_password") .dbname("new_database") .owner("app_user") .encoding("UTF8") .locale("en_US.UTF-8") .template("template0") .build(); println!("CreateDb command configured"); } ``` -------------------------------- ### Download and Extract PostgreSQL Archives (Rust) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Shows how to use the `postgresql_archive` crate to download and extract PostgreSQL binaries. It covers resolving versions based on requirements, downloading specific archive versions, and extracting them to a specified directory. This is useful for obtaining binaries without full server management. ```rust use postgresql_archive::{Result, VersionReq, extract, get_archive, get_version}; use postgresql_archive::configuration::theseus; #[tokio::main] async fn main() -> Result<()> { let url = theseus::URL; // Get the resolved version for a version requirement let version_req = VersionReq::parse(">=16.0.0, <17.0.0")?; let resolved_version = get_version(url, &version_req).await?; println!("Resolved version: {}", resolved_version); // Output: Resolved version: 16.10.0 // Download archive for specific version let (version, archive_bytes) = get_archive(url, &VersionReq::parse("=16.4.0")?).await?; println!("Downloaded PostgreSQL {} ({} bytes)", version, archive_bytes.len()); // Output: Downloaded PostgreSQL 16.4.0 (45678912 bytes) // Extract to a directory let out_dir = tempfile::tempdir()?.into_path(); let extracted_files = extract(url, &archive_bytes, &out_dir).await?; println!("Extracted {} files to {:?}", extracted_files.len(), out_dir); // Output: Extracted 1247 files to "/tmp/.tmpXXXXXX" Ok(()) } ``` -------------------------------- ### Configure Bundled PostgreSQL Version Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/postgresql_embedded/README.md This snippet demonstrates how to configure the version of PostgreSQL to be bundled with your application. It requires the `bundled` feature to be enabled and sets the `POSTGRESQL_VERSION` environment variable at compile time, and an explicit version in `Settings` at runtime. It uses the `tokio` runtime for asynchronous operations. ```rust use postgresql_embedded::{Result, Settings, VersionReq}; #[tokio::main] async fn main() -> Result<()> { let settings = Settings { version: VersionReq::from_str("=17.2.0")?, ..Default::default() }; Ok(()) } ``` -------------------------------- ### Use Predefined PostgreSQL Version Constants (Rust) Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Illustrates the usage of predefined version constants provided by the `postgresql-embedded` crate for easily specifying PostgreSQL versions. It shows how to use constants like `LATEST`, `V18`, `V17`, `V16`, etc., when creating `Settings`. ```rust use postgresql_embedded::{PostgreSQL, Result, Settings, LATEST, V18, V17, V16, V15, V14}; #[tokio::main] async fn main() -> Result<()> { // Use predefined version constants let settings_latest = Settings { version: LATEST, // Resolves to latest available version (*) ..Default::default() }; let settings_v17 = Settings { version: V17.clone(), // Resolves to latest PostgreSQL 17.x ..Default::default() }; let settings_v16 = Settings { version: V16.clone(), // Resolves to latest PostgreSQL 16.x ..Default::default() }; println!("LATEST: {}", LATEST); // Output: LATEST: * println!("V17: {}", V17.to_string()); // Output: V17: =17 println!("V16: {}", V16.to_string()); // Output: V16: =16 Ok(()) } ``` -------------------------------- ### Build pg_dump Command with Rust Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Constructs a `pg_dump` command using the `postgresql_commands::pg_dump::PgDumpBuilder`. This builder allows programmatic configuration of various `pg_dump` options, including host, port, username, database name, output file, format, and schema options. The built command can be executed or inspected. ```rust use postgresql_commands::pg_dump::PgDumpBuilder; use postgresql_commands::CommandBuilder; fn main() { // Build a pg_dump command with options let command = PgDumpBuilder::new() .program_dir("/usr/local/pgsql/bin") .host("localhost") .port(5432) .username("postgres") .pg_password("secret") .dbname("my_database") .file("/backup/my_database.sql") .format("plain") .schema_only() .no_owner() .verbose() .build(); // The command can be executed // let output = command.output()?; // Or converted to inspect println!("Command: {:?}", command); // Output: Command shows pg_dump with all configured arguments } ``` -------------------------------- ### Run PostgreSQL with Blocking API - Rust Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/postgresql_embedded/README.md Illustrates the usage of the blocking API for managing a PostgreSQL instance with the postgresql-embedded library. This synchronous approach is suitable for simpler applications or scenarios where blocking operations are acceptable. ```rust use postgresql_embedded::Result; use postgresql_embedded::blocking::PostgreSQL; fn main() -> Result<()> { let mut postgresql = PostgreSQL::default(); postgresql.setup()?; postgresql.start()?; let database_name = "test"; postgresql.create_database(database_name)?; postgresql.database_exists(database_name)?; postgresql.drop_database(database_name)?; postgresql.stop() } ``` -------------------------------- ### PostgreSQL Server - Synchronous/Blocking API Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt Demonstrates using the synchronous (blocking) API for PostgreSQL Embedded, suitable for applications not using async runtimes. This requires enabling the 'blocking' feature flag in Cargo.toml and provides synchronous methods for server management and database operations. ```rust // Cargo.toml: postgresql_embedded = { version = "0.20", features = ["blocking"] } use postgresql_embedded::Result; use postgresql_embedded::blocking::PostgreSQL; fn main() -> Result<()> { let mut postgresql = PostgreSQL::default(); // All operations are synchronous postgresql.setup()?; postgresql.start()?; let database_name = "sync_test"; postgresql.create_database(database_name)?; let exists = postgresql.database_exists(database_name)?; println!("Database '{}' exists: {}", database_name, exists); // Output: Database 'sync_test' exists: true postgresql.drop_database(database_name)?; postgresql.stop()?; Ok(()) } ``` -------------------------------- ### Using Zonky Binaries with PostgreSQL Embedded Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This configuration allows the use of Zonky binaries instead of the default Theseus binaries for PostgreSQL. The `zonky` feature is enabled, and `default-features = false` is used to explicitly disable default features, ensuring only the specified features are active. ```toml [dependencies] postgresql_embedded = { version = "0.20", features = ["zonky"], default-features = false } ``` -------------------------------- ### Default Async Usage with PostgreSQL Embedded Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This snippet shows the default asynchronous usage of the `postgresql_embedded` crate. It requires adding the crate to your `Cargo.toml` file with the specified version. No specific features are enabled, meaning it will use the default runtime and download binaries as needed. ```toml [dependencies] postgresql_embedded = "0.20" ``` -------------------------------- ### Using Rustls with PostgreSQL Embedded Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This configuration switches the TLS backend to `rustls` instead of the default `native-tls`. The `rustls` feature is enabled, and `default-features = false` is used to ensure only the desired features are included, providing an alternative TLS implementation. ```toml [dependencies] postgresql_embedded = { version = "0.20", features = ["rustls"], default-features = false } ``` -------------------------------- ### Download and Extract PostgreSQL Archive (Sync) Source: https://github.com/theseus-rs/postgresql-embedded/blob/main/postgresql_archive/README.md This snippet shows the synchronous approach to downloading and extracting a PostgreSQL archive using the `postgresql_archive` crate. It uses the `blocking` module for synchronous operations and specifies the version requirement with `VersionReq::STAR`. The extracted files are placed in the system's temporary directory. ```rust use postgresql_archive::configuration::theseus; use postgresql_archive::{Result, VersionReq}; use postgresql_archive::blocking::{extract, get_archive}; fn main() -> Result<()> { let url = theseus::URL; let (archive_version, archive) = get_archive(url, &VersionReq::STAR)?; let out_dir = std::env::temp_dir(); extract(url, &archive, &out_dir) } ``` -------------------------------- ### Archive Crate with Additional Extractors Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This snippet shows the configuration for the `postgresql_archive` crate, which handles PostgreSQL archive files. It enables features for various archive formats (`tar-xz`, `zip`) and checksum algorithms (`md5`, `sha1`), allowing for flexible handling of compressed PostgreSQL data. ```toml [dependencies] postgresql_archive = { version = "0.20", features = ["tar-xz", "zip", "md5", "sha1"] } ``` -------------------------------- ### Blocking/Synchronous API Usage with PostgreSQL Embedded Source: https://context7.com/theseus-rs/postgresql-embedded/llms.txt This configuration enables the `blocking` feature for the `postgresql_embedded` crate, allowing for synchronous or blocking API usage. This is useful in applications that do not use an async runtime or prefer a simpler, blocking interface for database operations. ```toml [dependencies] postgresql_embedded = { version = "0.20", features = ["blocking"] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.