Configuration File
It's recommended to use configuration components to manage database configurations. Utilize the g
object to manage the database operations module with the g.DB("Group Name")
method, which will automatically read the corresponding configuration items from the configuration component based on the "Group Name".
Simple Configuration
Example:
yaml
# config.yaml
database:
default:
host: "localhost"
port: "3306"
user: "root"
pass: "123456"
name: "gb"
type: "mysql"
Complete Configuration
The complete config.yaml database configuration item data format is as follows:
yaml
# config.yaml
database:
{Group Name}:
host: "Address"
port: "Port"
user: "Username"
pass: "Password"
name: "Database Name"
type: "Database Type (e.g., mysql/pgsql/mssql)"
extra: "(Optional) Additional configuration for different databases"
charset: "(Optional) Database Encoding (e.g., utf8/gbk/gb2312)"
protocol: "(Optional) Database Connection Protocol, default is TCP"
timezone: "(Optional) Timezone configuration"
tablePrefix: "(Optional) Table name prefix"
dryRun: "(Optional) ORM dry run (read-only mode)"
singularTable: "(Optional) Whether to enable singular table names, for example, User will be converted to user, no longer users"
maxIdle: "(Optional) Maximum idle connections in the connection pool (default 10)"
maxOpen: "(Optional) Maximum open connections in the connection pool (default unlimited)"
Logging Configuration
gbdb
supports logging output, internally utilizing the gblog.Logger
object for logging management, and can be configured through the configuration file for the logger object. Here's an example configuration file:
yaml
# config.yaml
database:
logger:
path: "/var/log/gb/database"
level: "all"
stdout: false
default:
host: "localhost"
port: "3306"
user: "root"
pass: "123456"
name: "gb"
type: "mysql"