add casbin rule
This commit is contained in:
43
database/migrations/20230131_170433_create_casbin_rule.go
Executable file
43
database/migrations/20230131_170433_create_casbin_rule.go
Executable file
@@ -0,0 +1,43 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"atom/container"
|
||||
"atom/contracts"
|
||||
"atom/providers/log"
|
||||
|
||||
adapter "github.com/casbin/gorm-adapter/v3"
|
||||
|
||||
"go.uber.org/dig"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := container.Container.Provide(New20230131_170433CreateCasbinRuleMigration, dig.Group("migrations")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type Migration20230131_170433CreateCasbinRule struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func New20230131_170433CreateCasbinRuleMigration() contracts.Migration {
|
||||
return &Migration20230131_170433CreateCasbinRule{id: "20230131_170433_create_casbin_rule"}
|
||||
}
|
||||
|
||||
func (m *Migration20230131_170433CreateCasbinRule) ID() string {
|
||||
return m.id
|
||||
}
|
||||
|
||||
func (m *Migration20230131_170433CreateCasbinRule) Up(tx *gorm.DB) error {
|
||||
table := m.table()
|
||||
return tx.AutoMigrate(&table)
|
||||
}
|
||||
|
||||
func (m *Migration20230131_170433CreateCasbinRule) Down(tx *gorm.DB) error {
|
||||
return tx.Migrator().DropTable(m.table())
|
||||
}
|
||||
|
||||
func (m *Migration20230131_170433CreateCasbinRule) table() interface{} {
|
||||
return adapter.CasbinRule{}
|
||||
}
|
||||
24
database/models/casbin_rule.gen.go
Normal file
24
database/models/casbin_rule.gen.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
const TableNameCasbinRule = "casbin_rule"
|
||||
|
||||
// CasbinRule mapped from table <casbin_rule>
|
||||
type CasbinRule struct {
|
||||
ID uint64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"`
|
||||
Ptype string `gorm:"column:ptype;type:varchar(100)" json:"ptype"`
|
||||
V0 string `gorm:"column:v0;type:varchar(100)" json:"v0"`
|
||||
V1 string `gorm:"column:v1;type:varchar(100)" json:"v1"`
|
||||
V2 string `gorm:"column:v2;type:varchar(100)" json:"v2"`
|
||||
V3 string `gorm:"column:v3;type:varchar(100)" json:"v3"`
|
||||
V4 string `gorm:"column:v4;type:varchar(100)" json:"v4"`
|
||||
V5 string `gorm:"column:v5;type:varchar(100)" json:"v5"`
|
||||
}
|
||||
|
||||
// TableName CasbinRule's table name
|
||||
func (*CasbinRule) TableName() string {
|
||||
return TableNameCasbinRule
|
||||
}
|
||||
420
database/query/casbin_rule.gen.go
Normal file
420
database/query/casbin_rule.gen.go
Normal file
@@ -0,0 +1,420 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"atom/database/models"
|
||||
)
|
||||
|
||||
func newCasbinRule(db *gorm.DB, opts ...gen.DOOption) casbinRule {
|
||||
_casbinRule := casbinRule{}
|
||||
|
||||
_casbinRule.casbinRuleDo.UseDB(db, opts...)
|
||||
_casbinRule.casbinRuleDo.UseModel(&models.CasbinRule{})
|
||||
|
||||
tableName := _casbinRule.casbinRuleDo.TableName()
|
||||
_casbinRule.ALL = field.NewAsterisk(tableName)
|
||||
_casbinRule.ID = field.NewUint64(tableName, "id")
|
||||
_casbinRule.Ptype = field.NewString(tableName, "ptype")
|
||||
_casbinRule.V0 = field.NewString(tableName, "v0")
|
||||
_casbinRule.V1 = field.NewString(tableName, "v1")
|
||||
_casbinRule.V2 = field.NewString(tableName, "v2")
|
||||
_casbinRule.V3 = field.NewString(tableName, "v3")
|
||||
_casbinRule.V4 = field.NewString(tableName, "v4")
|
||||
_casbinRule.V5 = field.NewString(tableName, "v5")
|
||||
|
||||
_casbinRule.fillFieldMap()
|
||||
|
||||
return _casbinRule
|
||||
}
|
||||
|
||||
type casbinRule struct {
|
||||
casbinRuleDo casbinRuleDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Ptype field.String
|
||||
V0 field.String
|
||||
V1 field.String
|
||||
V2 field.String
|
||||
V3 field.String
|
||||
V4 field.String
|
||||
V5 field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c casbinRule) Table(newTableName string) *casbinRule {
|
||||
c.casbinRuleDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c casbinRule) As(alias string) *casbinRule {
|
||||
c.casbinRuleDo.DO = *(c.casbinRuleDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *casbinRule) updateTableName(table string) *casbinRule {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewUint64(table, "id")
|
||||
c.Ptype = field.NewString(table, "ptype")
|
||||
c.V0 = field.NewString(table, "v0")
|
||||
c.V1 = field.NewString(table, "v1")
|
||||
c.V2 = field.NewString(table, "v2")
|
||||
c.V3 = field.NewString(table, "v3")
|
||||
c.V4 = field.NewString(table, "v4")
|
||||
c.V5 = field.NewString(table, "v5")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *casbinRule) WithContext(ctx context.Context) ICasbinRuleDo {
|
||||
return c.casbinRuleDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c casbinRule) TableName() string { return c.casbinRuleDo.TableName() }
|
||||
|
||||
func (c casbinRule) Alias() string { return c.casbinRuleDo.Alias() }
|
||||
|
||||
func (c *casbinRule) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := c.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (c *casbinRule) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 8)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["ptype"] = c.Ptype
|
||||
c.fieldMap["v0"] = c.V0
|
||||
c.fieldMap["v1"] = c.V1
|
||||
c.fieldMap["v2"] = c.V2
|
||||
c.fieldMap["v3"] = c.V3
|
||||
c.fieldMap["v4"] = c.V4
|
||||
c.fieldMap["v5"] = c.V5
|
||||
}
|
||||
|
||||
func (c casbinRule) clone(db *gorm.DB) casbinRule {
|
||||
c.casbinRuleDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c casbinRule) replaceDB(db *gorm.DB) casbinRule {
|
||||
c.casbinRuleDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type casbinRuleDo struct{ gen.DO }
|
||||
|
||||
type ICasbinRuleDo interface {
|
||||
gen.SubQuery
|
||||
Debug() ICasbinRuleDo
|
||||
WithContext(ctx context.Context) ICasbinRuleDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() ICasbinRuleDo
|
||||
WriteDB() ICasbinRuleDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) ICasbinRuleDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) ICasbinRuleDo
|
||||
Not(conds ...gen.Condition) ICasbinRuleDo
|
||||
Or(conds ...gen.Condition) ICasbinRuleDo
|
||||
Select(conds ...field.Expr) ICasbinRuleDo
|
||||
Where(conds ...gen.Condition) ICasbinRuleDo
|
||||
Order(conds ...field.Expr) ICasbinRuleDo
|
||||
Distinct(cols ...field.Expr) ICasbinRuleDo
|
||||
Omit(cols ...field.Expr) ICasbinRuleDo
|
||||
Join(table schema.Tabler, on ...field.Expr) ICasbinRuleDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) ICasbinRuleDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) ICasbinRuleDo
|
||||
Group(cols ...field.Expr) ICasbinRuleDo
|
||||
Having(conds ...gen.Condition) ICasbinRuleDo
|
||||
Limit(limit int) ICasbinRuleDo
|
||||
Offset(offset int) ICasbinRuleDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ICasbinRuleDo
|
||||
Unscoped() ICasbinRuleDo
|
||||
Create(values ...*models.CasbinRule) error
|
||||
CreateInBatches(values []*models.CasbinRule, batchSize int) error
|
||||
Save(values ...*models.CasbinRule) error
|
||||
First() (*models.CasbinRule, error)
|
||||
Take() (*models.CasbinRule, error)
|
||||
Last() (*models.CasbinRule, error)
|
||||
Find() ([]*models.CasbinRule, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.CasbinRule, err error)
|
||||
FindInBatches(result *[]*models.CasbinRule, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*models.CasbinRule) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) ICasbinRuleDo
|
||||
Assign(attrs ...field.AssignExpr) ICasbinRuleDo
|
||||
Joins(fields ...field.RelationField) ICasbinRuleDo
|
||||
Preload(fields ...field.RelationField) ICasbinRuleDo
|
||||
FirstOrInit() (*models.CasbinRule, error)
|
||||
FirstOrCreate() (*models.CasbinRule, error)
|
||||
FindByPage(offset int, limit int) (result []*models.CasbinRule, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) ICasbinRuleDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Debug() ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) WithContext(ctx context.Context) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) ReadDB() ICasbinRuleDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) WriteDB() ICasbinRuleDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Session(config *gorm.Session) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Clauses(conds ...clause.Expression) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Returning(value interface{}, columns ...string) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Not(conds ...gen.Condition) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Or(conds ...gen.Condition) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Select(conds ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Where(conds ...gen.Condition) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ICasbinRuleDo {
|
||||
return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Order(conds ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Distinct(cols ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Omit(cols ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Join(table schema.Tabler, on ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) RightJoin(table schema.Tabler, on ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Group(cols ...field.Expr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Having(conds ...gen.Condition) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Limit(limit int) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Offset(offset int) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Unscoped() ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Create(values ...*models.CasbinRule) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) CreateInBatches(values []*models.CasbinRule, batchSize int) error {
|
||||
return c.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (c casbinRuleDo) Save(values ...*models.CasbinRule) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) First() (*models.CasbinRule, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.CasbinRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Take() (*models.CasbinRule, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.CasbinRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Last() (*models.CasbinRule, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.CasbinRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Find() ([]*models.CasbinRule, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*models.CasbinRule), err
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.CasbinRule, err error) {
|
||||
buf := make([]*models.CasbinRule, 0, batchSize)
|
||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) FindInBatches(result *[]*models.CasbinRule, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Attrs(attrs ...field.AssignExpr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Assign(attrs ...field.AssignExpr) ICasbinRuleDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Joins(fields ...field.RelationField) ICasbinRuleDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Preload(fields ...field.RelationField) ICasbinRuleDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) FirstOrInit() (*models.CasbinRule, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.CasbinRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) FirstOrCreate() (*models.CasbinRule, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.CasbinRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) FindByPage(offset int, limit int) (result []*models.CasbinRule, count int64, err error) {
|
||||
result, err = c.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = c.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = c.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c casbinRuleDo) Delete(models ...*models.CasbinRule) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (c *casbinRuleDo) withDO(do gen.Dao) *casbinRuleDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
CasbinRule *casbinRule
|
||||
Migration *migration
|
||||
SysAPI *sysAPI
|
||||
SysDictionary *sysDictionary
|
||||
@@ -29,6 +30,7 @@ var (
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
CasbinRule = &Q.CasbinRule
|
||||
Migration = &Q.Migration
|
||||
SysAPI = &Q.SysAPI
|
||||
SysDictionary = &Q.SysDictionary
|
||||
@@ -42,6 +44,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
CasbinRule: newCasbinRule(db, opts...),
|
||||
Migration: newMigration(db, opts...),
|
||||
SysAPI: newSysAPI(db, opts...),
|
||||
SysDictionary: newSysDictionary(db, opts...),
|
||||
@@ -56,6 +59,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
CasbinRule casbinRule
|
||||
Migration migration
|
||||
SysAPI sysAPI
|
||||
SysDictionary sysDictionary
|
||||
@@ -71,6 +75,7 @@ func (q *Query) Available() bool { return q.db != nil }
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
CasbinRule: q.CasbinRule.clone(db),
|
||||
Migration: q.Migration.clone(db),
|
||||
SysAPI: q.SysAPI.clone(db),
|
||||
SysDictionary: q.SysDictionary.clone(db),
|
||||
@@ -93,6 +98,7 @@ func (q *Query) WriteDB() *Query {
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
CasbinRule: q.CasbinRule.replaceDB(db),
|
||||
Migration: q.Migration.replaceDB(db),
|
||||
SysAPI: q.SysAPI.replaceDB(db),
|
||||
SysDictionary: q.SysDictionary.replaceDB(db),
|
||||
@@ -105,6 +111,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
CasbinRule ICasbinRuleDo
|
||||
Migration IMigrationDo
|
||||
SysAPI ISysAPIDo
|
||||
SysDictionary ISysDictionaryDo
|
||||
@@ -117,6 +124,7 @@ type queryCtx struct {
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
CasbinRule: q.CasbinRule.WithContext(ctx),
|
||||
Migration: q.Migration.WithContext(ctx),
|
||||
SysAPI: q.SysAPI.WithContext(ctx),
|
||||
SysDictionary: q.SysDictionary.WithContext(ctx),
|
||||
|
||||
Reference in New Issue
Block a user