CreatePostgresDbIfNotExists
Creates a PostgreSQL database if it does not already exist, using the provided configuration. If the database already exists, it connects to it; otherwise, it connects to the default 'postgres' database to create the specified database before establishing a connection to the newly created database.
def CreatePostgresDbIfNotExists(
ctx: context.Context,
pgConfig: PostgresConfig
) - > *sqlx.DB, error
Creates a PostgreSQL database if it does not already exist, using the provided configuration. This function ensures that the specified database is available for use, connecting to a default 'postgres' database first if the target database does not exist to perform the creation.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and timeouts. |
| pgConfig | PostgresConfig | The configuration details for the PostgreSQL database, including connection parameters like host, port, user, password, and the target database name. |
Returns
| Type | Description |
|---|---|
*sqlx.DB, error | A pointer to an sqlx.DB object representing the connection to the PostgreSQL database, or an error if the connection or creation fails. |