schema switch in runtime feature for clickhouse/mssql/pgsql/oracle

This commit is contained in:
John Guo
2022-04-27 17:15:26 +08:00
parent f326dc4eaa
commit ae5891068e
5 changed files with 19 additions and 0 deletions

View File

@ -66,8 +66,13 @@ func (d *Driver) Open(config *gdb.ConfigNode) (*sql.DB, error) {
source string
driver = "clickhouse"
)
// clickhouse://username:password@host1:9000,host2:9000/database?dial_timeout=200ms&max_execution_time=60
if config.Link != "" {
source = config.Link
// Custom changing the schema in runtime.
if config.Name != "" {
source, _ = gregex.ReplaceString(`@(.+?)/([\w\.\-]+)+`, "@$1/"+config.Name, source)
}
} else if config.Pass != "" {
source = fmt.Sprintf(
"clickhouse://%s:%s@%s:%s/%s?charset=%s&debug=%s",

View File

@ -66,6 +66,10 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
)
if config.Link != "" {
source = config.Link
// Custom changing the schema in runtime.
if config.Name != "" {
source, _ = gregex.ReplaceString(`database=([\w\.\-]+)+`, "database="+config.Name, source)
}
} else {
source = fmt.Sprintf(
"user id=%s;password=%s;server=%s;port=%s;database=%s;encrypt=disable",

View File

@ -67,8 +67,13 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
source string
underlyingDriverName = "oci8"
)
// [username/[password]@]host[:port][/service_name][?param1=value1&...&paramN=valueN]
if config.Link != "" {
source = config.Link
// Custom changing the schema in runtime.
if config.Name != "" {
source, _ = gregex.ReplaceString(`@(.+?)/([\w\.\-]+)+`, "@$1/"+config.Name, source)
}
} else {
source = fmt.Sprintf(
"%s/%s@%s:%s/%s",

View File

@ -65,6 +65,10 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
)
if config.Link != "" {
source = config.Link
// Custom changing the schema in runtime.
if config.Name != "" {
source, _ = gregex.ReplaceString(`dbname=([\w\.\-]+)+`, "dbname="+config.Name, source)
}
} else {
source = fmt.Sprintf(
"user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",

View File

@ -42,6 +42,7 @@ func (d *DriverMysql) Open(config *ConfigNode) (db *sql.DB, err error) {
source string
underlyingDriverName = "mysql"
)
// [username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]
if config.Link != "" {
source = config.Link
// Custom changing the schema in runtime.