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 has default dbName as postgres).

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

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).

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the database operation, allowing for cancellation and timeouts.
dbConfig*DbConfigThe database configuration object containing connection details for PostgreSQL or deprecated host/user/dbName settings. This configuration is used to establish or create the database connection.

Returns

TypeDescription
(*sqlx.DB, error)A pointer to the sqlx.DB object and an error if the database connection could not be established or configured.