feat(db): 添加对达梦数据库的支持
- 在应用程序中新增对达梦数据库(DM)的配置和连接支持 - 实现 SetDmDB 函数以配置达梦数据库连接 - 更新数据库操作逻辑,支持达梦特有的 SQL 语法和功能 - 在相关文件中添加达梦数据库的处理逻辑,包括表创建、数据插入和查询 - 更新 go.mod 和 go.sum 文件以引入达梦数据库驱动 - 增强文档,详细说明达梦数据库的配置和使用方法
This commit is contained in:
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2018, 达梦数据库有限公司.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dm
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Properties struct {
|
||||
innerProps map[string]string
|
||||
}
|
||||
|
||||
func NewProperties() *Properties {
|
||||
p := Properties{
|
||||
innerProps: make(map[string]string, 50),
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (g *Properties) SetProperties(p *Properties) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
for k, v := range p.innerProps {
|
||||
g.Set(strings.ToLower(k), v)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Properties) Len() int {
|
||||
return len(g.innerProps)
|
||||
}
|
||||
|
||||
func (g *Properties) IsNil() bool {
|
||||
return g == nil || g.innerProps == nil
|
||||
}
|
||||
|
||||
func (g *Properties) GetString(key, def string) string {
|
||||
v, ok := g.innerProps[strings.ToLower(key)]
|
||||
|
||||
if !ok || v == "" {
|
||||
return def
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (g *Properties) GetInt(key string, def int, min int, max int) int {
|
||||
value, ok := g.innerProps[strings.ToLower(key)]
|
||||
if !ok || value == "" {
|
||||
return def
|
||||
}
|
||||
|
||||
i, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
|
||||
if i > max || i < min {
|
||||
return def
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (g *Properties) GetBool(key string, def bool) bool {
|
||||
value, ok := g.innerProps[strings.ToLower(key)]
|
||||
if !ok || value == "" {
|
||||
return def
|
||||
}
|
||||
b, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (g *Properties) GetTrimString(key string, def string) string {
|
||||
value, ok := g.innerProps[strings.ToLower(key)]
|
||||
if !ok || value == "" {
|
||||
return def
|
||||
} else {
|
||||
return strings.TrimSpace(value)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Properties) GetStringArray(key string, def []string) []string {
|
||||
value, ok := g.innerProps[strings.ToLower(key)]
|
||||
if ok || value != "" {
|
||||
array := strings.Split(value, ",")
|
||||
if len(array) > 0 {
|
||||
return array
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
//func (g *Properties) GetBool(key string) bool {
|
||||
// i, _ := strconv.ParseBool(g.innerProps[key])
|
||||
// return i
|
||||
//}
|
||||
|
||||
func (g *Properties) Set(key, value string) {
|
||||
g.innerProps[strings.ToLower(key)] = value
|
||||
}
|
||||
|
||||
func (g *Properties) SetIfNotExist(key, value string) {
|
||||
if _, ok := g.innerProps[strings.ToLower(key)]; !ok {
|
||||
g.Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果p有g没有的键值对,添加进g中
|
||||
func (g *Properties) SetDiffProperties(p *Properties) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
for k, v := range p.innerProps {
|
||||
if _, ok := g.innerProps[strings.ToLower(k)]; !ok {
|
||||
g.innerProps[strings.ToLower(k)] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user