Compare commits
No commits in common. 'master' and 'v1.0.49' have entirely different histories.
@ -0,0 +1,9 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/beego/beego/v2/client/orm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BeegoClient struct {
|
||||||
|
Db orm.Ormer // 驱动
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/beego/beego/v2/client/orm"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBeegoMysqlClient(dns string) (*BeegoClient, error) {
|
||||||
|
|
||||||
|
c := &BeegoClient{}
|
||||||
|
|
||||||
|
err := orm.RegisterDataBase("default", "mysql", dns)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.Db = orm.NewOrm()
|
||||||
|
|
||||||
|
return c, err
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/beego/beego/v2/client/orm"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBeegoPostgresClient(dns string) (*BeegoClient, error) {
|
||||||
|
|
||||||
|
c := &BeegoClient{}
|
||||||
|
|
||||||
|
err := orm.RegisterDataBase("default", "postgres", dns)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.Db = orm.NewOrm()
|
||||||
|
|
||||||
|
return c, err
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BunClientConfig struct {
|
||||||
|
Dns string // 地址
|
||||||
|
}
|
||||||
|
|
||||||
|
// BunClient
|
||||||
|
// https://bun.uptrace.dev/
|
||||||
|
type BunClient struct {
|
||||||
|
Db *bun.DB // 驱动
|
||||||
|
config *BunClientConfig // 配置
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetDb 获取驱动
|
||||||
|
func (c *BunClient) GetDb() *bun.DB {
|
||||||
|
return c.Db
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
"github.com/uptrace/bun/dialect/mysqldialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBunMysqlClient(config *BunClientConfig) (*BunClient, error) {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
c := &BunClient{config: config}
|
||||||
|
|
||||||
|
sqlDb, err := sql.Open("mysql", c.config.Dns)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprintf("加载驱动失败:%v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Db = bun.NewDB(sqlDb, mysqldialect.New())
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
"github.com/uptrace/bun/dialect/pgdialect"
|
||||||
|
"github.com/uptrace/bun/driver/pgdriver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBunPgsqlClient(config *BunClientConfig) (*BunClient, error) {
|
||||||
|
|
||||||
|
c := &BunClient{config: config}
|
||||||
|
|
||||||
|
sqlDb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(c.config.Dns)))
|
||||||
|
|
||||||
|
c.Db = bun.NewDB(sqlDb, pgdialect.New())
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -1,57 +1,86 @@
|
|||||||
module go.dtapp.net/dorm
|
module go.dtapp.net/dorm
|
||||||
|
|
||||||
go 1.22.1
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/redis/go-redis/v9 v9.5.1
|
github.com/basgys/goxml2json v1.1.0
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/beego/beego/v2 v2.0.5
|
||||||
go.dtapp.net/gojson v1.0.4
|
github.com/go-redis/redis/v9 v9.0.0-beta.2
|
||||||
go.dtapp.net/gotime v1.0.8
|
github.com/go-sql-driver/mysql v1.6.0
|
||||||
go.mongodb.org/mongo-driver v1.15.0
|
github.com/kamva/mgm/v3 v3.4.1
|
||||||
gorm.io/driver/mysql v1.5.6
|
github.com/lib/pq v1.10.7
|
||||||
gorm.io/driver/postgres v1.5.7
|
github.com/qiniu/qmgo v1.1.2
|
||||||
gorm.io/gen v0.3.26
|
github.com/sirupsen/logrus v1.9.0
|
||||||
gorm.io/gorm v1.25.10
|
github.com/upper/db/v4 v4.6.0
|
||||||
|
github.com/uptrace/bun v1.1.8
|
||||||
|
github.com/uptrace/bun/dialect/mysqldialect v1.1.8
|
||||||
|
github.com/uptrace/bun/dialect/pgdialect v1.1.8
|
||||||
|
github.com/uptrace/bun/driver/pgdriver v1.1.8
|
||||||
|
go.dtapp.net/gotime v1.0.5
|
||||||
|
go.dtapp.net/goxml v1.0.1
|
||||||
|
go.mongodb.org/mongo-driver v1.10.2
|
||||||
|
gorm.io/driver/mysql v1.3.6
|
||||||
|
gorm.io/driver/postgres v1.3.10
|
||||||
|
gorm.io/gorm v1.23.10
|
||||||
|
xorm.io/xorm v1.3.2
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
github.com/bitly/go-simplejson v0.5.0 // indirect
|
||||||
github.com/basgys/goxml2json v1.1.0 // indirect
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
github.com/bytedance/sonic v1.11.6 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
|
||||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
|
||||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.11.1 // indirect
|
||||||
|
github.com/goccy/go-json v0.9.11 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||||
|
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||||
|
github.com/jackc/pgconn v1.13.0 // indirect
|
||||||
|
github.com/jackc/pgio v1.0.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
|
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
|
||||||
github.com/jackc/pgx/v5 v5.5.5 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
github.com/jackc/pgtype v1.12.0 // indirect
|
||||||
|
github.com/jackc/pgx/v4 v4.17.2 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/compress v1.17.8 // indirect
|
github.com/klauspost/compress v1.15.11 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
|
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
github.com/montanaflynn/stats v0.6.6 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/segmentio/fasthash v1.0.3 // indirect
|
||||||
|
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
|
||||||
|
github.com/stretchr/testify v1.8.0 // indirect
|
||||||
|
github.com/syndtr/goleveldb v1.0.0 // indirect
|
||||||
|
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
|
||||||
|
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||||
|
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
github.com/xdg-go/scram v1.1.2 // indirect
|
github.com/xdg-go/scram v1.1.1 // indirect
|
||||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||||
github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect
|
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
||||||
golang.org/x/arch v0.7.0 // indirect
|
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
|
||||||
golang.org/x/crypto v0.22.0 // indirect
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||||
golang.org/x/mod v0.17.0 // indirect
|
golang.org/x/net v0.0.0-20220927171203-f486391704dc // indirect
|
||||||
golang.org/x/net v0.24.0 // indirect
|
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 // indirect
|
||||||
golang.org/x/sync v0.7.0 // indirect
|
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
|
||||||
golang.org/x/sys v0.19.0 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/tools v0.1.11 // indirect
|
||||||
golang.org/x/tools v0.20.0 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
gorm.io/datatypes v1.2.0 // indirect
|
lukechampine.com/uint128 v1.2.0 // indirect
|
||||||
gorm.io/hints v1.1.2 // indirect
|
mellium.im/sasl v0.3.0 // indirect
|
||||||
gorm.io/plugin/dbresolver v1.5.1 // indirect
|
modernc.org/ccgo/v3 v3.16.7 // indirect
|
||||||
|
modernc.org/libc v1.16.14 // indirect
|
||||||
|
modernc.org/opt v0.1.3 // indirect
|
||||||
|
modernc.org/sqlite v1.17.3 // indirect
|
||||||
|
modernc.org/strutil v1.1.2 // indirect
|
||||||
|
xorm.io/builder v0.3.12 // indirect
|
||||||
)
|
)
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package dorm
|
|
||||||
|
|
||||||
import "database/sql"
|
|
||||||
|
|
||||||
// Ping ping
|
|
||||||
func (c *GormClient) Ping() error {
|
|
||||||
return c.sqlDd.Ping()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close 关闭
|
|
||||||
func (c *GormClient) Close() error {
|
|
||||||
return c.sqlDd.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stats 返回数据库统计信息
|
|
||||||
func (c *GormClient) Stats() sql.DBStats {
|
|
||||||
return c.sqlDd.Stats()
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package dorm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GormGenClientFun *GormClient 驱动
|
|
||||||
type GormGenClientFun func() *GormGenClient
|
|
||||||
|
|
||||||
// GormGenClientTableFun
|
|
||||||
// *GormClient 驱动
|
|
||||||
// string 表名
|
|
||||||
type GormGenClientTableFun func() (*GormGenClient, string)
|
|
||||||
|
|
||||||
// GormGenClientConfig 配置
|
|
||||||
type GormGenClientConfig struct {
|
|
||||||
Dns string // dns地址
|
|
||||||
Db *gorm.DB // db驱动
|
|
||||||
Config gen.Config // gen配置
|
|
||||||
}
|
|
||||||
|
|
||||||
// GormGenClient
|
|
||||||
// https://gorm.io/zh_CN/gen/index.html
|
|
||||||
type GormGenClient struct {
|
|
||||||
db *gorm.DB // 驱动
|
|
||||||
generator *gen.Generator // 驱动
|
|
||||||
config *GormGenClientConfig // 配置
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package dorm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetDb 获取驱动
|
|
||||||
func (c *GormGenClient) GetDb() *gorm.DB {
|
|
||||||
return c.db
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGenerator 获取驱动
|
|
||||||
func (c *GormGenClient) GetGenerator() *gen.Generator {
|
|
||||||
return c.generator
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package dorm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"gorm.io/driver/mysql"
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewGormGenMysqlClient 创建GormGenClient实例 mysql
|
|
||||||
func NewGormGenMysqlClient(ctx context.Context, config *GormGenClientConfig) (*GormGenClient, error) {
|
|
||||||
|
|
||||||
c := &GormGenClient{config: config}
|
|
||||||
|
|
||||||
c.generator = gen.NewGenerator(config.Config)
|
|
||||||
|
|
||||||
if c.config.Dns != "" {
|
|
||||||
c.db, _ = gorm.Open(mysql.Open(c.config.Dns), &gorm.Config{})
|
|
||||||
c.generator.UseDB(c.db)
|
|
||||||
} else {
|
|
||||||
c.generator.UseDB(c.config.Db)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c, nil
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package dorm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"gorm.io/driver/postgres"
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewGormGenPostgresClient 创建GormGenClient实例 postgres
|
|
||||||
func NewGormGenPostgresClient(ctx context.Context, config *GormGenClientConfig) (*GormGenClient, error) {
|
|
||||||
|
|
||||||
c := &GormGenClient{config: config}
|
|
||||||
|
|
||||||
c.generator = gen.NewGenerator(config.Config)
|
|
||||||
|
|
||||||
if c.config.Dns != "" {
|
|
||||||
c.db, _ = gorm.Open(postgres.Open(c.config.Dns), &gorm.Config{})
|
|
||||||
c.generator.UseDB(c.db)
|
|
||||||
} else {
|
|
||||||
c.generator.UseDB(c.config.Db)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c, nil
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package dorm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"gorm.io/driver/postgres"
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewGormGenPostgresqlClient 创建GormGenClient实例 postgresql
|
|
||||||
func NewGormGenPostgresqlClient(ctx context.Context, config *GormGenClientConfig) (*GormGenClient, error) {
|
|
||||||
|
|
||||||
c := &GormGenClient{config: config}
|
|
||||||
|
|
||||||
c.generator = gen.NewGenerator(config.Config)
|
|
||||||
|
|
||||||
if c.config.Dns != "" {
|
|
||||||
c.db, _ = gorm.Open(postgres.Open(c.config.Dns), &gorm.Config{})
|
|
||||||
c.generator.UseDB(c.db)
|
|
||||||
} else {
|
|
||||||
c.generator.UseDB(c.config.Db)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c, nil
|
|
||||||
}
|
|
@ -1,16 +1,8 @@
|
|||||||
package dorm
|
package dorm
|
||||||
|
|
||||||
import (
|
import "gorm.io/gorm"
|
||||||
"database/sql"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetDb 获取驱动
|
// GetDb 获取驱动
|
||||||
func (c *GormClient) GetDb() *gorm.DB {
|
func (c *GormClient) GetDb() *gorm.DB {
|
||||||
return c.db
|
return c.Db
|
||||||
}
|
|
||||||
|
|
||||||
// GetSqlDb 获取驱动
|
|
||||||
func (c *GormClient) GetSqlDb() *sql.DB {
|
|
||||||
return c.sqlDd
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package dorm
|
package dorm
|
||||||
|
|
||||||
import "github.com/redis/go-redis/v9"
|
import "github.com/go-redis/redis/v9"
|
||||||
|
|
||||||
// GetDb 获取驱动
|
// GetDb 获取驱动
|
||||||
func (r *RedisClient) GetDb() *redis.Client {
|
func (r *RedisClient) GetDb() *redis.Client {
|
||||||
return r.db
|
return r.Db
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
package dorm
|
@ -1,76 +1,31 @@
|
|||||||
package dorm
|
package dorm
|
||||||
|
|
||||||
|
// String 复制 string 对象,并返回复制体
|
||||||
|
func String(s string) string {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// Bool 复制 bool 对象,并返回复制体
|
// Bool 复制 bool 对象,并返回复制体
|
||||||
func Bool(b bool) bool {
|
func Bool(b bool) bool {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uint8 复制 int8 对象,并返回复制体
|
|
||||||
func Uint8(ui uint8) uint8 {
|
|
||||||
return ui
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uint16 复制 uint16 对象,并返回复制体
|
|
||||||
func Uint16(ui uint16) uint16 {
|
|
||||||
return ui
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uint32 复制 uint32 对象,并返回复制体
|
|
||||||
func Uint32(ui uint32) uint32 {
|
|
||||||
return ui
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uint64 复制 uint64 对象,并返回复制体
|
|
||||||
func Uint64(ui uint64) uint64 {
|
|
||||||
return ui
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int8 复制 int8 对象,并返回复制体
|
|
||||||
func Int8(i int8) int8 {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int16 复制 int16 对象,并返回复制体
|
|
||||||
func Int16(i int16) int16 {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int32 复制 int64 对象,并返回复制体
|
|
||||||
func Int32(i int32) int32 {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int64 复制 int64 对象,并返回复制体
|
|
||||||
func Int64(i int64) int64 {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// Float32 复制 float32 对象,并返回复制体
|
|
||||||
func Float32(f float32) float32 {
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
// Float64 复制 float64 对象,并返回复制体
|
// Float64 复制 float64 对象,并返回复制体
|
||||||
func Float64(f float64) float64 {
|
func Float64(f float64) float64 {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// String 复制 string 对象,并返回复制体
|
// Float32 复制 float32 对象,并返回复制体
|
||||||
func String(s string) string {
|
func Float32(f float32) float32 {
|
||||||
return s
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int 复制 int 对象,并返回复制体
|
// Int64 复制 int64 对象,并返回复制体
|
||||||
func Int(i int) int {
|
func Int64(i int64) int64 {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uint 复制 uint 对象,并返回复制体
|
// Int32 复制 int64 对象,并返回复制体
|
||||||
func Uint(ui uint) uint {
|
func Int32(i int32) int32 {
|
||||||
return ui
|
return i
|
||||||
}
|
|
||||||
|
|
||||||
// Any 复制 any 对象,并返回复制体
|
|
||||||
func Any(a any) any {
|
|
||||||
return a
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import "github.com/upper/db/v4"
|
||||||
|
|
||||||
|
// UpperClient
|
||||||
|
// https://upper.io/
|
||||||
|
type UpperClient struct {
|
||||||
|
Db *db.Session // 驱动
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/upper/db/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetDb 获取驱动
|
||||||
|
func (c *UpperClient) GetDb() *db.Session {
|
||||||
|
return c.Db
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/upper/db/v4/adapter/mysql"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewUpperMysqlClient(settings mysql.ConnectionURL) (*UpperClient, error) {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
c := &UpperClient{}
|
||||||
|
|
||||||
|
sess, err := mysql.Open(settings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||||
|
}
|
||||||
|
defer sess.Close()
|
||||||
|
|
||||||
|
c.Db = &sess
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/upper/db/v4/adapter/postgresql"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewUpperPostgresqlClient(settings postgresql.ConnectionURL) (*UpperClient, error) {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
c := &UpperClient{}
|
||||||
|
|
||||||
|
sess, err := postgresql.Open(settings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||||
|
}
|
||||||
|
defer sess.Close()
|
||||||
|
|
||||||
|
c.Db = &sess
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
package dorm
|
|
||||||
|
|
||||||
// Version 版本
|
|
||||||
const Version = "1.0.59"
|
|
@ -0,0 +1,16 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type XormClientConfigXorm struct {
|
||||||
|
Dns string // 地址
|
||||||
|
}
|
||||||
|
|
||||||
|
// XormClient
|
||||||
|
// https://xorm.io/
|
||||||
|
type XormClient struct {
|
||||||
|
Db *xorm.Engine // 驱动
|
||||||
|
config *XormClientConfigXorm // 配置
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetDb 获取驱动
|
||||||
|
func (c *XormClient) GetDb() *xorm.Engine {
|
||||||
|
return c.Db
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewXormMysqlClient(config *XormClientConfigXorm) (*XormClient, error) {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
c := &XormClient{config: config}
|
||||||
|
|
||||||
|
c.Db, err = xorm.NewEngine("mysql", c.config.Dns)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewXormPostgresClient(config *XormClientConfigXorm) (*XormClient, error) {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
c := &XormClient{config: config}
|
||||||
|
|
||||||
|
c.Db, err = xorm.NewEngine("postgres", c.config.Dns)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprintf("连接失败:%v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package dorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// XormClientSession https://xorm.io/zh/docs/chapter-10/readme/
|
||||||
|
type XormClientSession struct {
|
||||||
|
*xorm.Session
|
||||||
|
}
|
||||||
|
|
||||||
|
// Begin 开始事务,需要创建 Session 对象
|
||||||
|
//func (c *XormClient) Begin() (*XormClientSession, error) {
|
||||||
|
// session := c.Db.NewSession()
|
||||||
|
// defer session.Close()
|
||||||
|
// return &session, session.Begin()
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Rollback 回滚事务
|
||||||
|
//func (c *XormClientSession) Rollback() error {
|
||||||
|
// return c.Rollback()
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Commit 提交事务
|
||||||
|
//func (c *XormClientSession) Commit() error {
|
||||||
|
// return c.Commit()
|
||||||
|
//}
|
Loading…
Reference in new issue