Skip to main content

GetDB

Uses the dbConfig to create a sqlx DB object. If the database doesn't exist for the dbConfig, a new one is created using the default database for the provider (e.g., 'postgres' for PostgreSQL).

def GetDB(
ctx: context.Context,
dbConfig: *DbConfig
) - > (*sqlx.DB, error)

Creates a sqlx DB object based on the provided database configuration. If a database does not exist for the given configuration, a new one is created using the provider's default database name (e.g., 'postgres' for PostgreSQL). This function allows callers to obtain a database connection for further operations.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the database operation, allowing for cancellation and timeouts.
dbConfig*DbConfigThe database configuration object containing details for connecting to the database. This object can specify PostgreSQL settings directly or use deprecated fields for backward compatibility.

Returns

TypeDescription
(*sqlx.DB, error)A pointer to the sqlx DB object and an error, if any occurred during database initialization or connection.