parent
bfa0593eab
commit
d3a88c60f4
@ -1,5 +1,5 @@
|
||||
package go_library
|
||||
|
||||
func Version() string {
|
||||
return "v2022-07-19"
|
||||
return "v2022-07-20"
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func NewBeegoSqliteClient(config *ConfigBeegoClient) (*BeegoClient, error) {
|
||||
|
||||
var err error
|
||||
c := &BeegoClient{config: config}
|
||||
|
||||
err = orm.RegisterDriver("sqlite", orm.DRSqlite)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("加载驱动失败:%v", err))
|
||||
}
|
||||
|
||||
var db *sql.DB
|
||||
o, err := orm.NewOrmWithDB("sqlite", "default", db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.Db = &o
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect/sqlitedialect"
|
||||
"github.com/uptrace/bun/driver/sqliteshim"
|
||||
)
|
||||
|
||||
func NewBunSqliteClient(config *ConfigBunClient) (*BunClient, error) {
|
||||
|
||||
var err error
|
||||
c := &BunClient{config: config}
|
||||
|
||||
sqlDb, err := sql.Open(sqliteshim.ShimName, c.config.Dns)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("加载驱动失败:%v", err))
|
||||
}
|
||||
|
||||
c.Db = bun.NewDB(sqlDb, sqlitedialect.New())
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import "github.com/bradfitz/gomemcache/memcache"
|
||||
|
||||
type ConfigMemcacheClient struct {
|
||||
Dns string
|
||||
}
|
||||
|
||||
type MemcacheClient struct {
|
||||
Db *memcache.Client // 驱动
|
||||
config *ConfigMemcacheClient // 配置
|
||||
}
|
||||
|
||||
func NewMemcacheClient(config *ConfigMemcacheClient) (*MemcacheClient, error) {
|
||||
|
||||
c := &MemcacheClient{config: config}
|
||||
|
||||
c.Db = memcache.New(c.config.Dns)
|
||||
if c.Db != nil {
|
||||
panic("memcache New failed")
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"github.com/kamva/mgm/v3"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type ConfigMgmClient struct {
|
||||
Opts *options.ClientOptions
|
||||
DatabaseName string // 库名
|
||||
}
|
||||
|
||||
type MgmClient struct {
|
||||
config *ConfigMgmClient // 配置
|
||||
}
|
||||
|
||||
func NewMgmClient(config *ConfigMgmClient) (*MgmClient, error) {
|
||||
|
||||
c := &MgmClient{config: config}
|
||||
|
||||
_ = mgm.SetDefaultConfig(nil, c.config.DatabaseName, c.config.Opts)
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"gopkg.in/mgo.v2"
|
||||
)
|
||||
|
||||
type ConfigMgoClient struct {
|
||||
Dns string
|
||||
DatabaseName string // 库名
|
||||
}
|
||||
|
||||
type MgoClient struct {
|
||||
config *ConfigMgoClient // 配置
|
||||
}
|
||||
|
||||
func NewMgoClient(config *ConfigMgoClient) (*MgoClient, error) {
|
||||
|
||||
c := &MgoClient{config: config}
|
||||
|
||||
session, err := mgo.Dial(c.config.Dns)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer session.Close()
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/qiniu/qmgo"
|
||||
)
|
||||
|
||||
type ConfigQMgoClient struct {
|
||||
Dns string
|
||||
DatabaseName string // 库名
|
||||
}
|
||||
|
||||
type QMgoClient struct {
|
||||
Db *qmgo.Client
|
||||
config *ConfigQMgoClient // 配置
|
||||
}
|
||||
|
||||
func NewQgoClient(config *ConfigQMgoClient) (*QMgoClient, error) {
|
||||
|
||||
var err error
|
||||
c := &QMgoClient{config: config}
|
||||
|
||||
c.Db, err = qmgo.NewClient(context.Background(), &qmgo.Config{Uri: c.config.Dns})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("检查连接失败:%v", err))
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gomodule/redigo/redis"
|
||||
)
|
||||
|
||||
type ConfigRedigoClient struct {
|
||||
Addr string // 地址
|
||||
Password string // 密码
|
||||
DB int // 数据库
|
||||
PoolSize int // 连接池大小
|
||||
}
|
||||
|
||||
// RedigoClient
|
||||
// https://Redigo.uptrace.dev/
|
||||
type RedigoClient struct {
|
||||
Db *redis.Conn // 驱动
|
||||
config *ConfigRedigoClient // 配置
|
||||
}
|
||||
|
||||
func NewRedigoClient(config *ConfigRedigoClient) (*RedigoClient, error) {
|
||||
|
||||
c := &RedigoClient{}
|
||||
c.config = config
|
||||
if c.config.PoolSize == 0 {
|
||||
c.config.PoolSize = 100
|
||||
}
|
||||
|
||||
db, err := redis.Dial("tcp", c.config.Addr, redis.DialPassword(c.config.Password), redis.DialDatabase(c.config.DB))
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||
}
|
||||
c.Db = &db
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/upper/db/v4/adapter/sqlite"
|
||||
)
|
||||
|
||||
func NewUpperSqliteClient(settings sqlite.ConnectionURL) (*UpperClient, error) {
|
||||
|
||||
var err error
|
||||
c := &UpperClient{}
|
||||
|
||||
sess, err := sqlite.Open(settings)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||
}
|
||||
defer sess.Close()
|
||||
|
||||
c.Db = &sess
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func NewXormSqlite3Client(config *ConfigXormClient) (*XormClient, error) {
|
||||
|
||||
var err error
|
||||
c := &XormClient{config: config}
|
||||
|
||||
c.Db, err = xorm.NewEngine("sqlite3", c.config.Dns)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package dorm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitee.com/chunanyong/zorm"
|
||||
_ "github.com/bmizerany/pq"
|
||||
)
|
||||
|
||||
func NewZormPgsqlClient(config *ConfigZormClient) (*ZormClient, error) {
|
||||
|
||||
var err error
|
||||
c := &ZormClient{config: config}
|
||||
|
||||
c.Db, err = zorm.NewDBDao(&zorm.DataSourceConfig{
|
||||
DSN: c.config.Dns,
|
||||
DriverName: "postgres", // 数据库驱动名称
|
||||
DBType: "postgresql", // 数据库类型
|
||||
PrintSQL: true, // 是否打印sql
|
||||
MaxOpenConns: 0, // 数据库最大连接数,默认50
|
||||
MaxIdleConns: 0, // 数据库最大空闲连接数,默认50
|
||||
ConnMaxLifetimeSecond: 0, // 连接存活秒时间. 默认600(10分钟)后连接被销毁重建.
|
||||
// 避免数据库主动断开连接,造成死连接.MySQL默认wait_timeout 28800秒(8小时)
|
||||
DefaultTxOptions: nil, // 事务隔离级别的默认配置,默认为nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
Loading…
Reference in new issue