Connection
Establishing a connection to the database using ClueQuest SDK for Golang
database.NewDatabaseConnection()
The database.NewDatabaseConnection() function establishes a connection to the database using the provided configuration settings.
Arguments
config(config.DatabaseConfiguration/config.DatabaseConnectionFromEnv): A struct containing the database configuration settings such as host, port, username, password, and database name.
Example
config := config.NewDatabaseConfiguration(
"localhost", // host
"5432", // port
"user", // username
"password", // password
"cluequest", // database name
"disable", // ssl mode
)
// config := config.NewDatabaseConfigurationFromEnv()
err := database.NewConnection(config)
if err != nil {
// handle error
}database.NewDatabaseConnectionFromEnv()
The database.NewDatabaseConnectionFromEnv() function establishes a connection to the database using configuration settings retrieved from environment variables.
Example
err := database.NewConnectionFromEnv()
if err != nil {
// handle error
}database.AutoMigration()
The database.AutoMigration() function automatically migrates the database schema based on the defined models in the ClueQuest SDK.
Example
err := Conn.AutoMigration()
if err != nil {
// handle error
}