Database
Connection to database with ClueQuest SDK
Configuration
To connect to your database using the ClueQuest SDK, create new instance of the DatabaseConfiguration
struct with the necessary configuration parameters.
Environment Variables
To use environment variables for configuration, you can set the following variables in your environment:
CLUEQUEST_DB_HOST
: The hostname of your database server.CLUEQUEST_DB_PORT
: The port number of your database server.CLUEQUEST_DB_USER
: The username for database authentication.CLUEQUEST_DB_PASSWORD
: The password for database authentication.CLUEQUEST_DB_NAME
: The name of the database to connect to.CLUEQUEST_DB_SSL
: The SSL mode for the database connection.
Use the NewDatabaseConfigurationFromEnv
function to create a configuration instance from these environment variables.
import "git.secnex.io/cluquest/go-sdk/config"
config := config.NewDatabaseConfiguration()
Manual Configuration
You can also manually create a DatabaseConfiguration
instance by providing the necessary parameters directly.
import "git.secnex.io/cluquest/go-sdk/config"
config := config.NewDatabaseConfiguration(
"localhost", // host
5432, // port
"user", // username
"password", // password
"cluequest", // database name
"disable", // ssl mode
)
Connection
To establish a connection to the database, use the NewConnection
function from the database
package, passing in your DatabaseConfiguration
instance.
import (
"git.secnex.io/cluquest/go-sdk/config"
"git.secnex.io/cluquest/go-sdk/database"
)
dbConfig := config.NewDatabaseConfigurationFromEnv()
err := database.NewConnection(dbConfig)
if err != nil {
// handle error
}
You can use the NewConnectionFromEnv
function to create a connection directly from environment variables.
import "git.secnex.io/cluquest/go-sdk/database"
err := database.NewConnectionFromEnv()
if err != nil {
// handle error
}