Skip to main content

CreatePostgresReadOnlyDbConnection

Creates a read-only PostgreSQL database connection using the provided configuration and returns the sqlx.DB object. It pings the database to verify the connection before returning.

def CreatePostgresReadOnlyDbConnection(
ctx: context.Context,
pgConfig: PostgresConfig
) - > *sqlx.DB, error

Creates a read-only PostgreSQL database connection and returns the sqlx.DB object. This function is used to establish a connection for read operations, ensuring that no write operations can be performed through this connection.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the database operation, used for cancellation and timeouts.
pgConfigPostgresConfigThe configuration details for the PostgreSQL database connection, including credentials and connection parameters.

Returns

TypeDescription
*sqlx.DB, errorA pointer to the sqlx.DB object representing the read-only database connection, or an error if the connection cannot be established or pinged.