Add database pool configuration (#32)

This commit is contained in:
Wenbo Han
2023-02-13 23:26:53 +08:00
committed by GitHub
parent 486b8727a4
commit d1a3ac0796
4 changed files with 69 additions and 21 deletions

View File

@@ -60,9 +60,14 @@ err := facades.Queue.Job(&jobs.Test{}, []queue.Arg{}).Dispatch()
## Roadmap
- [ ] Custom .env path
- [ ] Database read-write separation
- [ ] Extend Redis driver
- [ ] Hash
- [ ] Crypt
- [ ] Support Websocket
- [ ] Broadcasting
- [ ] Delay Queue
- [ ] Queue supports DB driver
- [ ] Notifications
- [ ] Optimize unit tests
## Documentation

View File

@@ -58,9 +58,14 @@ err := facades.Queue.Job(&jobs.Test{}, []queue.Arg{}).Dispatch()
## 路线图
- [ ] 自定义 .env 路径
- [ ] 数据库读写分离
- [ ] 扩展 Redis 驱动
- [ ] Hash
- [ ] Crypt
- [ ] Websocket 支持
- [ ] 广播系统
- [ ] 延迟队列
- [ ] 队列支持 DB 驱动
- [ ] 消息通知
- [ ] 完善单元测试
## 文档

View File

@@ -15,7 +15,7 @@ func init() {
"mysql": map[string]any{
"driver": "mysql",
"host": config.Env("DB_HOST", "127.0.0.1"),
"port": config.Env("DB_PORT", "3306"),
"port": config.Env("DB_PORT", 3306),
"database": config.Env("DB_DATABASE", "forge"),
"username": config.Env("DB_USERNAME", ""),
"password": config.Env("DB_PASSWORD", ""),
@@ -25,7 +25,7 @@ func init() {
"postgresql": map[string]any{
"driver": "postgresql",
"host": config.Env("DB_HOST", "127.0.0.1"),
"port": config.Env("DB_PORT", "3306"),
"port": config.Env("DB_PORT", 5432),
"database": config.Env("DB_DATABASE", "forge"),
"username": config.Env("DB_USERNAME", ""),
"password": config.Env("DB_PASSWORD", ""),
@@ -39,7 +39,7 @@ func init() {
"sqlserver": map[string]any{
"driver": "sqlserver",
"host": config.Env("DB_HOST", "127.0.0.1"),
"port": config.Env("DB_PORT", "3306"),
"port": config.Env("DB_PORT", 1433),
"database": config.Env("DB_DATABASE", "forge"),
"username": config.Env("DB_USERNAME", ""),
"password": config.Env("DB_PASSWORD", ""),
@@ -47,6 +47,40 @@ func init() {
},
},
// Set pool configuration
"pool": map[string]any{
// Sets the maximum number of connections in the idle
// connection pool.
//
// If MaxOpenConns is greater than 0 but less than the new MaxIdleConns,
// then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
//
// If n <= 0, no idle connections are retained.
"max_idle_conns": 10,
// Sets the maximum number of open connections to the database.
//
// If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
// MaxIdleConns, then MaxIdleConns will be reduced to match the new
// MaxOpenConns limit.
//
// If n <= 0, then there is no limit on the number of open connections.
"max_open_conns": 100,
// Sets the maximum amount of time a connection may be idle.
//
// Expired connections may be closed lazily before reuse.
//
// If d <= 0, connections are not closed due to a connection's idle time.
// Unit: Second
"conn_max_idletime": 3600,
// Sets the maximum amount of time a connection may be reused.
//
// Expired connections may be closed lazily before reuse.
//
// If d <= 0, connections are not closed due to a connection's age.
// Unit: Second
"conn_max_lifetime": 3600,
},
// Migration Repository Table
//
// This table keeps track of all the migrations that have already run for

28
go.mod
View File

@@ -3,7 +3,7 @@ module goravel
go 1.18
require (
github.com/goravel/framework v1.8.3
github.com/goravel/framework v1.9.0
google.golang.org/grpc v1.50.1
)
@@ -50,14 +50,15 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.7.3 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.9.0 // indirect
github.com/gin-gonic/gin v1.8.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-redis/redis/v8 v8.11.4 // indirect
github.com/go-redsync/redsync/v4 v4.0.4 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-migrate/migrate/v4 v4.15.3-0.20230111075136-dc26c41ac9da // indirect
@@ -100,7 +101,7 @@ require (
github.com/lestrrat-go/strftime v1.0.5 // indirect
github.com/lib/pq v1.10.2 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/microsoft/go-mssqldb v0.19.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -113,7 +114,9 @@ require (
github.com/opencontainers/runc v1.1.4 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/ory/dockertest/v3 v3.9.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect
@@ -131,7 +134,7 @@ require (
github.com/stretchr/testify v1.8.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tencentyun/cos-go-sdk-v5 v0.7.40 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/unrolled/secure v1.13.0 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
@@ -145,13 +148,13 @@ require (
go.mongodb.org/mongo-driver v1.7.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.5.0 // indirect
google.golang.org/api v0.103.0 // indirect
@@ -165,5 +168,6 @@ require (
gorm.io/driver/postgres v1.4.6 // indirect
gorm.io/driver/sqlite v1.4.4 // indirect
gorm.io/driver/sqlserver v1.4.2 // indirect
gorm.io/gorm v1.24.3 // indirect
gorm.io/gorm v1.24.5 // indirect
gorm.io/plugin/dbresolver v1.4.1 // indirect
)