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 ensure connectivity before returning the connection.

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, allowing for cancellation and timeouts.
pgConfigPostgresConfigThe configuration details required to establish the PostgreSQL connection, including host, port, user, password, and database name.

Returns​

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