mirror of
https://gitee.com/johng/gf
synced 2026-06-10 11:27:17 +08:00
Compare commits
2 Commits
v2.2.0-bet
...
contrib/dr
| Author | SHA1 | Date | |
|---|---|---|---|
| 007715dbd5 | |||
| 6cd84e8276 |
4
.github/workflows/gf.yml
vendored
4
.github/workflows/gf.yml
vendored
@ -94,6 +94,7 @@ jobs:
|
||||
--health-retries 10
|
||||
|
||||
# ClickHouse backend server.
|
||||
# docker run -d --name clickhouse -p 9000:9000 -p 8123:8123 -p 9001:9001 loads/clickhouse-server:latest
|
||||
clickhouse-server:
|
||||
image: loads/clickhouse-server:latest
|
||||
ports:
|
||||
@ -101,13 +102,14 @@ jobs:
|
||||
- 8123:8123
|
||||
- 9001:9001
|
||||
|
||||
# Polaris backend server.
|
||||
polaris:
|
||||
image: loads/polaris-server-standalone:latest
|
||||
ports:
|
||||
- 8090:8090
|
||||
- 8091:8091
|
||||
|
||||
# oracle 11g server
|
||||
# Oracle 11g server
|
||||
oracle-server:
|
||||
image: loads/oracle-xe-11g-r2:latest
|
||||
env:
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package clickhouse
|
||||
|
||||
import (
|
||||
@ -123,7 +129,7 @@ func clickhouseConfigDB() gdb.DB {
|
||||
User: "default",
|
||||
Name: "default",
|
||||
Type: "clickhouse",
|
||||
Debug: true,
|
||||
Debug: false,
|
||||
})
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertNE(connect, nil)
|
||||
@ -132,9 +138,7 @@ func clickhouseConfigDB() gdb.DB {
|
||||
|
||||
func clickhouseLink() gdb.DB {
|
||||
connect, err := gdb.New(gdb.ConfigNode{
|
||||
Link: "clickhouse://default@127.0.0.1:9000,127.0.0.1:9000/default?dial_timeout=200ms&max_execution_time=60",
|
||||
Type: "clickhouse",
|
||||
Name: "default",
|
||||
Link: "clickhouse:default:@tcp(127.0.0.1:9000)/default?dial_timeout=200ms&max_execution_time=60",
|
||||
})
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertNE(connect, nil)
|
||||
|
||||
@ -9,6 +9,7 @@ package mssql_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
@ -53,8 +54,10 @@ func init() {
|
||||
nodeLink := gdb.ConfigNode{
|
||||
Type: "mssql",
|
||||
Name: "test",
|
||||
Link: fmt.Sprintf("user id=%s;password=%s;server=%s;port=%s;database=%s;encrypt=disable",
|
||||
node.User, node.Pass, node.Host, node.Port, node.Name),
|
||||
Link: fmt.Sprintf(
|
||||
"mssql:%s:%s@tcp(%s:%s)/%s?encrypt=disable",
|
||||
node.User, node.Pass, node.Host, node.Port, node.Name,
|
||||
),
|
||||
}
|
||||
|
||||
nodeErr := gdb.ConfigNode{
|
||||
|
||||
@ -9,13 +9,14 @@ package oracle_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
_ "github.com/sijms/go-ora/v2"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -61,8 +62,9 @@ func init() {
|
||||
nodeLink := gdb.ConfigNode{
|
||||
Type: TestDbType,
|
||||
Name: TestDbName,
|
||||
Link: fmt.Sprintf("%s://%s:%s@%s:%s/%s",
|
||||
TestDbType, TestDbUser, TestDbPass, TestDbIP, TestDbPort, TestDbName),
|
||||
Link: fmt.Sprintf("%s:%s:%s@tcp(%s:%s)/%s",
|
||||
TestDbType, TestDbUser, TestDbPass, TestDbIP, TestDbPort, TestDbName,
|
||||
),
|
||||
}
|
||||
|
||||
nodeErr := gdb.ConfigNode{
|
||||
|
||||
@ -23,8 +23,6 @@ const (
|
||||
TableSize = 10
|
||||
TablePrefix = "t_"
|
||||
SchemaName = "test"
|
||||
TestDbUser = "postgres"
|
||||
TestDbPass = "12345678"
|
||||
CreateTime = "2018-10-24 10:00:00"
|
||||
)
|
||||
|
||||
@ -36,18 +34,7 @@ var (
|
||||
|
||||
func init() {
|
||||
configNode = gdb.ConfigNode{
|
||||
Host: "127.0.0.1",
|
||||
Port: "5432",
|
||||
User: TestDbUser,
|
||||
Pass: TestDbPass,
|
||||
Timezone: "Asia/Shanghai", // For calculating UT cases of datetime zones in convenience.
|
||||
Type: "pgsql",
|
||||
Role: "master",
|
||||
Charset: "utf8",
|
||||
Weight: 1,
|
||||
MaxIdleConnCount: 10,
|
||||
MaxOpenConnCount: 10,
|
||||
MaxConnLifeTime: 600,
|
||||
Link: `pgsql:postgres:12345678@tcp(127.0.0.1:5432)`,
|
||||
}
|
||||
|
||||
//pgsql only permit to connect to the designation database.
|
||||
|
||||
@ -53,9 +53,10 @@ func init() {
|
||||
|
||||
fmt.Println("init sqlite db dir: ", dbDir)
|
||||
|
||||
dbFilePath := gfile.Join(dbDir, "test.db")
|
||||
configNode = gdb.ConfigNode{
|
||||
Type: "sqlite",
|
||||
Link: gfile.Join(dbDir, "test.db"),
|
||||
Link: fmt.Sprintf(`sqlite::@file(%s)`, dbFilePath),
|
||||
Charset: "utf8",
|
||||
}
|
||||
nodePrefix := configNode
|
||||
|
||||
@ -304,6 +304,9 @@ const (
|
||||
ctxKeyForDB gctx.StrKey = `CtxKeyForDB`
|
||||
ctxKeyCatchSQL gctx.StrKey = `CtxKeyCatchSQL`
|
||||
ctxKeyInternalProducedSQL gctx.StrKey = `CtxKeyInternalProducedSQL`
|
||||
|
||||
// type:[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]
|
||||
linkPattern = `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([\w\-]*)\?{0,1}(.*)`
|
||||
)
|
||||
|
||||
const (
|
||||
@ -372,9 +375,6 @@ var (
|
||||
|
||||
// tableFieldsMap caches the table information retrieved from database.
|
||||
tableFieldsMap = gmap.NewStrAnyMap(true)
|
||||
|
||||
// type:[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]
|
||||
linkPattern = `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([\w\-]*)\?{0,1}(.*)`
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -426,6 +426,9 @@ func NewByGroup(group ...string) (db DB, err error) {
|
||||
|
||||
// newDBByConfigNode creates and returns an ORM object with given configuration node and group name.
|
||||
func newDBByConfigNode(node *ConfigNode, group string) (db DB, err error) {
|
||||
if node.Link != "" {
|
||||
node = parseConfigNodeLink(node)
|
||||
}
|
||||
c := &Core{
|
||||
group: group,
|
||||
debug: gtype.NewBool(),
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// Config is the configuration management object.
|
||||
@ -105,6 +106,9 @@ func AddConfigNode(group string, node ConfigNode) {
|
||||
|
||||
// parseConfigNode parses `Link` configuration syntax.
|
||||
func parseConfigNode(node ConfigNode) ConfigNode {
|
||||
if node.Link != "" {
|
||||
node = *parseConfigNodeLink(&node)
|
||||
}
|
||||
if node.Link != "" && node.Type == "" {
|
||||
match, _ := gregex.MatchString(`([a-z]+):(.+)`, node.Link)
|
||||
if len(match) == 3 {
|
||||
@ -245,3 +249,41 @@ func (c *Core) GetPrefix() string {
|
||||
func (c *Core) GetSchema() string {
|
||||
return c.schema
|
||||
}
|
||||
|
||||
func parseConfigNodeLink(node *ConfigNode) *ConfigNode {
|
||||
var match []string
|
||||
if node.Link != "" {
|
||||
match, _ = gregex.MatchString(linkPattern, node.Link)
|
||||
if len(match) > 5 {
|
||||
node.Type = match[1]
|
||||
node.User = match[2]
|
||||
node.Pass = match[3]
|
||||
node.Protocol = match[4]
|
||||
array := gstr.Split(match[5], ":")
|
||||
if len(array) == 2 {
|
||||
node.Host = array[0]
|
||||
node.Port = array[1]
|
||||
node.Name = match[6]
|
||||
} else {
|
||||
node.Name = match[5]
|
||||
}
|
||||
if len(match) > 6 {
|
||||
node.Extra = match[7]
|
||||
}
|
||||
node.Link = ""
|
||||
}
|
||||
}
|
||||
if node.Extra != "" {
|
||||
if m, _ := gstr.Parse(node.Extra); len(m) > 0 {
|
||||
_ = gconv.Struct(m, &node)
|
||||
}
|
||||
}
|
||||
// Default value checks.
|
||||
if node.Charset == "" {
|
||||
node.Charset = defaultCharset
|
||||
}
|
||||
if node.Protocol == "" {
|
||||
node.Protocol = defaultProtocol
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
@ -13,9 +13,7 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
)
|
||||
|
||||
@ -27,9 +25,6 @@ type DriverWrapperDB struct {
|
||||
// Open creates and returns an underlying sql.DB object for pgsql.
|
||||
// https://pkg.go.dev/github.com/lib/pq
|
||||
func (d *DriverWrapperDB) Open(config *ConfigNode) (db *sql.DB, err error) {
|
||||
if config.Link != "" {
|
||||
config = parseConfigNodeLink(config)
|
||||
}
|
||||
return d.DB.Open(config)
|
||||
}
|
||||
|
||||
@ -83,41 +78,3 @@ func (d *DriverWrapperDB) TableFields(ctx context.Context, table string, schema
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func parseConfigNodeLink(node *ConfigNode) *ConfigNode {
|
||||
var match []string
|
||||
if node.Link != "" {
|
||||
match, _ = gregex.MatchString(linkPattern, node.Link)
|
||||
if len(match) > 5 {
|
||||
node.Type = match[1]
|
||||
node.User = match[2]
|
||||
node.Pass = match[3]
|
||||
node.Protocol = match[4]
|
||||
array := gstr.Split(match[5], ":")
|
||||
if len(array) == 2 {
|
||||
node.Host = array[0]
|
||||
node.Port = array[1]
|
||||
node.Name = match[6]
|
||||
} else {
|
||||
node.Name = match[5]
|
||||
}
|
||||
if len(match) > 6 {
|
||||
node.Extra = match[7]
|
||||
}
|
||||
node.Link = ""
|
||||
}
|
||||
}
|
||||
if node.Extra != "" {
|
||||
if m, _ := gstr.Parse(node.Extra); len(m) > 0 {
|
||||
_ = gconv.Struct(m, &node)
|
||||
}
|
||||
}
|
||||
// Default value checks.
|
||||
if node.Charset == "" {
|
||||
node.Charset = defaultCharset
|
||||
}
|
||||
if node.Protocol == "" {
|
||||
node.Protocol = defaultProtocol
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package gf
|
||||
|
||||
const VERSION = "v2.2.0-beta"
|
||||
const VERSION = "v2.2.0-beta2"
|
||||
const AUTHORS = "john<john@goframe.org>"
|
||||
|
||||
Reference in New Issue
Block a user