1 Star 0 Fork 0

李易/gorm-dm8-dialect

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zv.go 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
zhenyong.li 提交于 2024-01-19 02:47 . update driver to embed dm8
/*
* 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
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/java-dev101/gorm-dm8-dialect.git
git@gitee.com:java-dev101/gorm-dm8-dialect.git
java-dev101
gorm-dm8-dialect
gorm-dm8-dialect
v0.9.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385