- update dorm gorm gen

master v1.0.91
李光春 1 year ago
parent d04b818803
commit c8bd8e9f2b

@ -1,5 +1,5 @@
package go_library
func Version() string {
return "1.0.90"
return "1.0.91"
}

@ -13,13 +13,14 @@ type GormGenClientFun func() *GormGenClient
type GormGenClientTableFun func() (*GormGenClient, string)
type GormGenClientConfig struct {
Dns string // 地址
Dns string // dns地址
Config gen.Config // gen配置
}
// GormGenClient
// https://gorm.io/zh_CN/gen/index.html
type GormGenClient struct {
Db *gorm.DB // 驱动
Generator *gen.Generator // 驱动
db *gorm.DB // 驱动
generator *gen.Generator // 驱动
config *GormGenClientConfig // 配置
}

@ -0,0 +1,16 @@
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
}

@ -10,13 +10,10 @@ func NewGormGenMysqlClient(config *GormGenClientConfig) (*GormGenClient, error)
c := &GormGenClient{config: config}
c.Generator = gen.NewGenerator(gen.Config{
OutPath: "../query",
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
})
c.generator = gen.NewGenerator(config.Config)
c.Db, _ = gorm.Open(mysql.Open(c.config.Dns), &gorm.Config{})
c.Generator.UseDB(c.Db)
c.db, _ = gorm.Open(mysql.Open(c.config.Dns), &gorm.Config{})
c.generator.UseDB(c.db)
return c, nil
}

@ -6,32 +6,14 @@ import (
"gorm.io/gorm"
)
func NewGormGenPostgresClient(config *GormGenClientConfig) (*GormGenClient, error) {
c := &GormGenClient{config: config}
c.Generator = gen.NewGenerator(gen.Config{
OutPath: "../query",
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
})
c.Db, _ = gorm.Open(postgres.Open(c.config.Dns), &gorm.Config{})
c.Generator.UseDB(c.Db)
return c, nil
}
func NewGormGenPostgresqlClient(config *GormGenClientConfig) (*GormGenClient, error) {
c := &GormGenClient{config: config}
c.Generator = gen.NewGenerator(gen.Config{
OutPath: "../query",
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
})
c.generator = gen.NewGenerator(config.Config)
c.Db, _ = gorm.Open(postgres.Open(c.config.Dns), &gorm.Config{})
c.Generator.UseDB(c.Db)
c.db, _ = gorm.Open(postgres.Open(c.config.Dns), &gorm.Config{})
c.generator.UseDB(c.db)
return c, nil
}

Loading…
Cancel
Save