Crate sal_postgresclient

Source
Expand description

SAL PostgreSQL Client

This crate provides a PostgreSQL client for interacting with PostgreSQL databases. It offers connection management, query execution, and a builder pattern for flexible configuration.

§Features

  • Connection Management: Automatic connection handling and reconnection
  • Query Execution: Simple API for executing queries and fetching results
  • Builder Pattern: Flexible configuration with authentication support
  • Environment Variable Support: Easy configuration through environment variables
  • Thread Safety: Safe to use in multi-threaded applications
  • PostgreSQL Installer: Install and configure PostgreSQL using nerdctl
  • Rhai Integration: Scripting support for PostgreSQL operations

§Usage

use sal_postgresclient::{execute, query, query_one};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Execute a query
    let rows_affected = execute("CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT)", &[])?;

    // Query data
    let rows = query("SELECT * FROM users", &[])?;

    // Query single row
    let row = query_one("SELECT * FROM users WHERE id = $1", &[&1])?;

    Ok(())
}

Modules§

rhai
Rhai wrappers for PostgreSQL client module functions

Structs§

PostgresClientWrapper
Wrapper for PostgreSQL client to handle connection
PostgresConfigBuilder
PostgreSQL connection configuration builder
PostgresInstallerConfig
PostgreSQL installer configuration
QueryParams
Parameter builder for PostgreSQL queries

Enums§

PostgresInstallerError

Functions§

create_database
Create a new database in PostgreSQL
execute
Execute a query on the PostgreSQL connection
execute_sql
Execute a SQL script in PostgreSQL
execute_with_params
Execute a query with the parameter builder
execute_with_pool
Execute a query using the connection pool
execute_with_pool_params
Execute a query with the parameter builder using the connection pool
get_postgres_client
Get the PostgreSQL client instance
get_postgres_pool
Get the PostgreSQL connection pool instance
install_postgres
Install PostgreSQL using nerdctl
is_postgres_running
Check if PostgreSQL is running
notify
Send a notification on a channel
notify_with_pool
Send a notification on a channel using the connection pool
query
Execute a query on the PostgreSQL connection and return the rows
query_one
Execute a query on the PostgreSQL connection and return a single row
query_one_with_params
Execute a query with the parameter builder and return a single row
query_one_with_pool
Execute a query using the connection pool and return a single row
query_one_with_pool_params
Execute a query with the parameter builder using the connection pool and return a single row
query_opt
Execute a query on the PostgreSQL connection and return an optional row
query_opt_with_params
Execute a query with the parameter builder and return an optional row
query_opt_with_pool
Execute a query using the connection pool and return an optional row
query_opt_with_pool_params
Execute a query with the parameter builder using the connection pool and return an optional row
query_with_params
Execute a query with the parameter builder and return the rows
query_with_pool
Execute a query using the connection pool and return the rows
query_with_pool_params
Execute a query with the parameter builder using the connection pool and return the rows
reset
Reset the PostgreSQL client
reset_pool
Reset the PostgreSQL connection pool
transaction
Transaction functions for PostgreSQL
transaction_with_pool
Transaction functions for PostgreSQL using the connection pool
with_config
Create a new PostgreSQL client with custom configuration
with_pool_config
Create a new PostgreSQL connection pool with custom configuration