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 one.
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 to perform the creation if necessary.
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 and the database name to be created or connected to. |
Returns
| Type | Description |
|---|---|
*sqlx.DB, error | A database connection object to the specified PostgreSQL database and an error if the connection or creation fails. |