gorm
5/14/25About 1 mincomponentgormmysqlpostgresqlsqlite
gorm Database Component
sgorm
is a higher-level database component built upon GORM. While retaining all GORM features, it adds the following capabilities:
- Full tracing support
- Enhanced custom condition querying functionality
Click to view gorm Usage Example.
Database Configuration
Configure database settings in the YAML configuration files located in the configs
directory:
MySQL Configuration
# database setting
database:
driver: "mysql"
mysql:
# dsn format, <user>:<pass>@(127.0.0.1:3306)/<db>?[k=v& ......]
dsn: "root:123456@(127.0.0.1:3306)/account?parseTime=true&loc=Local&charset=utf8mb4"
enableLog: true # Whether to enable logging
maxIdleConns: 3 # Sets the maximum number of connections in the idle connection pool
maxOpenConns: 100 # Sets the maximum number of open database connections
connMaxLifetime: 30 # Sets the maximum amount of time a connection may be reused, unit (minutes)
#slavesDsn: # Sets slave mysql dsn
# - "your dsn 1"
# - "your dsn 2"
#mastersDsn: # Sets masters mysql dsn, array type, optional field. If there's only one master, no need to set the mastersDsn field, the default dsn field is the mysql master.
# - "your master dsn"
PostgreSQL Configuration
# database setting
database:
driver: "postgresql"
postgres:
# dsn format, <username>:<password>@<hostname>:<port>/<db>?[k=v& ......]
dsn: "root:123456@192.168.3.37:5432/account?sslmode=disable"
enableLog: true # Whether to enable logging
maxIdleConns: 3 # Sets the maximum number of connections in the idle connection pool
maxOpenConns: 100 # Sets the maximum number of open database connections
connMaxLifetime: 30 # Sets the maximum amount of time a connection may be reused, unit (minutes)
SQLite Configuration
# database setting
database:
driver: "sqlite"
sqlite:
dbFile: "test/sql/sqlite/sponge.db" # If in a Windows environment, path separators are \\
enableLog: true # Whether to enable logging
maxIdleConns: 3 # Sets the maximum number of connections in the idle connection pool
maxOpenConns: 100 # Sets the maximum number of open database connections
connMaxLifetime: 30 # Sets the maximum amount of time a connection may be reused, unit (minutes)