add tables

This commit is contained in:
yanghao05
2023-01-31 16:58:35 +08:00
parent 05622922e9
commit e0191e30c1
22 changed files with 3069 additions and 484 deletions

View File

@@ -0,0 +1,56 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"github.com/gofrs/uuid"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_160904CreateUserMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_160904CreateUser struct {
id string
}
func New20230131_160904CreateUserMigration() contracts.Migration {
return &Migration20230131_160904CreateUser{id: "20230131_160904_create_user"}
}
func (m *Migration20230131_160904CreateUser) ID() string {
return m.id
}
func (m *Migration20230131_160904CreateUser) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_160904CreateUser) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_160904CreateUser) table() interface{} {
type User struct {
gorm.Model
UUID uuid.UUID `gorm:"index;comment:UUID"`
Username string `gorm:"index;comment:登录名"`
Password string `gorm:"comment:登录密码"`
Nickname string `gorm:"default:'';comment:昵称"`
Avatar string `gorm:"default:'';comment:头像"`
RoleID uint `gorm:"default:1;comment:角色ID"`
Phone string `gorm:"comment:手机号"`
Email string `gorm:"comment:邮箱"`
Status string `gorm:"default:ok;comment:用户状态"` // OK,BLOCKED,DISABLED,
}
return User{}
}

View File

@@ -0,0 +1,50 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_162400CreateSysApiMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_162400CreateSysApi struct {
id string
}
func New20230131_162400CreateSysApiMigration() contracts.Migration {
return &Migration20230131_162400CreateSysApi{id: "20230131_162400_create_sys_api"}
}
func (m *Migration20230131_162400CreateSysApi) ID() string {
return m.id
}
func (m *Migration20230131_162400CreateSysApi) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_162400CreateSysApi) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_162400CreateSysApi) table() interface{} {
type SysApi struct {
gorm.Model
Path string `gorm:"comment:路径"`
Description string `gorm:"comment:中文描述"`
ApiGroup string `gorm:"comment:组"`
Method string `gorm:"default:GET;comment:方法"`
}
return SysApi{}
}

View File

@@ -0,0 +1,50 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165134CreateSysDictionaryMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165134CreateSysDictionary struct {
id string
}
func New20230131_165134CreateSysDictionaryMigration() contracts.Migration {
return &Migration20230131_165134CreateSysDictionary{id: "20230131_165134_create_sys_dictionary"}
}
func (m *Migration20230131_165134CreateSysDictionary) ID() string {
return m.id
}
func (m *Migration20230131_165134CreateSysDictionary) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165134CreateSysDictionary) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165134CreateSysDictionary) table() interface{} {
type SysDictionary struct {
gorm.Model
Name string `gorm:"column:name;comment:字典名(中)"` // 字典名(中)
Type string `gorm:"column:type;comment:字典名(英)"` // 字典名(英)
Status *bool `gorm:"column:status;comment:状态"` // 状态
Desc string `gorm:"column:desc;comment:描述"` // 描述
}
return SysDictionary{}
}

View File

@@ -0,0 +1,51 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165218CreateSysDictionaryDetailMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165218CreateSysDictionaryDetail struct {
id string
}
func New20230131_165218CreateSysDictionaryDetailMigration() contracts.Migration {
return &Migration20230131_165218CreateSysDictionaryDetail{id: "20230131_165218_create_sys_dictionary_detail"}
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) ID() string {
return m.id
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) table() interface{} {
type SysDictionaryDetail struct {
gorm.Model
Label string `gorm:"column:label;comment:展示值"` // 展示值
Value int `gorm:"column:value;comment:字典值"` // 字典值
Status *bool `gorm:"column:status;comment:启用状态"` // 启用状态
Sort int `gorm:"column:sort;comment:排序标记"` // 排序标记
SysDictionaryID int `gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
}
return SysDictionaryDetail{}
}

View File

@@ -0,0 +1,46 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165352CreateUserRoleMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165352CreateUserRole struct {
id string
}
func New20230131_165352CreateUserRoleMigration() contracts.Migration {
return &Migration20230131_165352CreateUserRole{id: "20230131_165352_create_user_role"}
}
func (m *Migration20230131_165352CreateUserRole) ID() string {
return m.id
}
func (m *Migration20230131_165352CreateUserRole) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165352CreateUserRole) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165352CreateUserRole) table() interface{} {
type UserRole struct {
UserID uint `gorm:"column:user_id"`
RoleID uint `gorm:"column:role_id"`
}
return UserRole{}
}

View File

@@ -0,0 +1,50 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165509CreateSysRoleMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165509CreateSysRole struct {
id string
}
func New20230131_165509CreateSysRoleMigration() contracts.Migration {
return &Migration20230131_165509CreateSysRole{id: "20230131_165509_create_sys_role"}
}
func (m *Migration20230131_165509CreateSysRole) ID() string {
return m.id
}
func (m *Migration20230131_165509CreateSysRole) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165509CreateSysRole) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165509CreateSysRole) table() interface{} {
type SysRole struct {
gorm.Model
Alias string `gorm:"not null;unique;primary_key;comment:角色Alias;size:90"` // 角色ID
Name string `gorm:"comment:角色名"` // 角色名
ParentId *uint `gorm:"comment:父角色ID"` // 父角色ID
DefaultRouter string `gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
}
return SysRole{}
}

View File

@@ -0,0 +1,30 @@
// 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
import (
"time"
"gorm.io/gorm"
)
const TableNameSysAPI = "sys_apis"
// SysAPI mapped from table <sys_apis>
type SysAPI struct {
ID uint64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3)" json:"deleted_at"`
Path string `gorm:"column:path;type:varchar(191)" json:"path"` // 路径
Description string `gorm:"column:description;type:varchar(191)" json:"description"` // 中文描述
APIGroup string `gorm:"column:api_group;type:varchar(191)" json:"api_group"` // 组
Method string `gorm:"column:method;type:varchar(191);default:GET" json:"method"` // 方法
}
// TableName SysAPI's table name
func (*SysAPI) TableName() string {
return TableNameSysAPI
}

View File

@@ -0,0 +1,30 @@
// 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
import (
"time"
"gorm.io/gorm"
)
const TableNameSysDictionary = "sys_dictionaries"
// SysDictionary mapped from table <sys_dictionaries>
type SysDictionary struct {
ID uint64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3)" json:"deleted_at"`
Name string `gorm:"column:name;type:varchar(191)" json:"name"` // 字典名(中)
Type string `gorm:"column:type;type:varchar(191)" json:"type"` // 字典名(英)
Status bool `gorm:"column:status;type:tinyint(1)" json:"status"` // 状态
Desc string `gorm:"column:desc;type:varchar(191)" json:"desc"` // 描述
}
// TableName SysDictionary's table name
func (*SysDictionary) TableName() string {
return TableNameSysDictionary
}

View File

@@ -0,0 +1,31 @@
// 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
import (
"time"
"gorm.io/gorm"
)
const TableNameSysDictionaryDetail = "sys_dictionary_details"
// SysDictionaryDetail mapped from table <sys_dictionary_details>
type SysDictionaryDetail struct {
ID uint64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3)" json:"deleted_at"`
Label string `gorm:"column:label;type:varchar(191)" json:"label"` // 展示值
Value int64 `gorm:"column:value;type:bigint(20)" json:"value"` // 字典值
Status bool `gorm:"column:status;type:tinyint(1)" json:"status"` // 启用状态
Sort int64 `gorm:"column:sort;type:bigint(20)" json:"sort"` // 排序标记
SysDictionaryID int64 `gorm:"column:sys_dictionary_id;type:bigint(20)" json:"sys_dictionary_id"` // 关联标记
}
// TableName SysDictionaryDetail's table name
func (*SysDictionaryDetail) TableName() string {
return TableNameSysDictionaryDetail
}

View File

@@ -0,0 +1,30 @@
// 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
import (
"time"
"gorm.io/gorm"
)
const TableNameSysRole = "sys_roles"
// SysRole mapped from table <sys_roles>
type SysRole struct {
ID uint64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3)" json:"deleted_at"`
Alias_ string `gorm:"column:alias;type:varchar(90);primaryKey" json:"alias"` // 角色Alias
Name string `gorm:"column:name;type:varchar(191)" json:"name"` // 角色名
ParentID uint64 `gorm:"column:parent_id;type:bigint(20) unsigned" json:"parent_id"` // 父角色ID
DefaultRouter string `gorm:"column:default_router;type:varchar(191);default:dashboard" json:"default_router"` // 默认菜单
}
// TableName SysRole's table name
func (*SysRole) TableName() string {
return TableNameSysRole
}

View File

@@ -0,0 +1,18 @@
// 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 TableNameUserRole = "user_roles"
// UserRole mapped from table <user_roles>
type UserRole struct {
UserID uint64 `gorm:"column:user_id;type:bigint(20) unsigned" json:"user_id"`
RoleID uint64 `gorm:"column:role_id;type:bigint(20) unsigned" json:"role_id"`
}
// TableName UserRole's table name
func (*UserRole) TableName() string {
return TableNameUserRole
}

View File

@@ -0,0 +1,35 @@
// 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
import (
"time"
"gorm.io/gorm"
)
const TableNameUser = "users"
// User mapped from table <users>
type User struct {
ID uint64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3)" json:"deleted_at"`
UUID string `gorm:"column:uuid;type:varchar(191)" json:"uuid"` // UUID
Username string `gorm:"column:username;type:varchar(191)" json:"username"` // 登录名
Password string `gorm:"column:password;type:varchar(191)" json:"password"` // 登录密码
Nickname string `gorm:"column:nickname;type:varchar(191)" json:"nickname"` // 昵称
Avatar string `gorm:"column:avatar;type:varchar(191)" json:"avatar"` // 头像
RoleID uint64 `gorm:"column:role_id;type:bigint(20) unsigned;default:1" json:"role_id"` // 角色ID
Phone string `gorm:"column:phone;type:varchar(191)" json:"phone"` // 手机号
Email string `gorm:"column:email;type:varchar(191)" json:"email"` // 邮箱
Status string `gorm:"column:status;type:varchar(191);default:ok" json:"status"` // 用户状态
}
// TableName User's table name
func (*User) TableName() string {
return TableNameUser
}

View File

@@ -16,39 +16,69 @@ import (
)
var (
Q = new(Query)
Migration *migration
SysOperationRecord *sysOperationRecord
Q = new(Query)
Migration *migration
SysAPI *sysAPI
SysDictionary *sysDictionary
SysDictionaryDetail *sysDictionaryDetail
SysOperationRecord *sysOperationRecord
SysRole *sysRole
User *user
UserRole *userRole
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Migration = &Q.Migration
SysAPI = &Q.SysAPI
SysDictionary = &Q.SysDictionary
SysDictionaryDetail = &Q.SysDictionaryDetail
SysOperationRecord = &Q.SysOperationRecord
SysRole = &Q.SysRole
User = &Q.User
UserRole = &Q.UserRole
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Migration: newMigration(db, opts...),
SysOperationRecord: newSysOperationRecord(db, opts...),
db: db,
Migration: newMigration(db, opts...),
SysAPI: newSysAPI(db, opts...),
SysDictionary: newSysDictionary(db, opts...),
SysDictionaryDetail: newSysDictionaryDetail(db, opts...),
SysOperationRecord: newSysOperationRecord(db, opts...),
SysRole: newSysRole(db, opts...),
User: newUser(db, opts...),
UserRole: newUserRole(db, opts...),
}
}
type Query struct {
db *gorm.DB
Migration migration
SysOperationRecord sysOperationRecord
Migration migration
SysAPI sysAPI
SysDictionary sysDictionary
SysDictionaryDetail sysDictionaryDetail
SysOperationRecord sysOperationRecord
SysRole sysRole
User user
UserRole userRole
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Migration: q.Migration.clone(db),
SysOperationRecord: q.SysOperationRecord.clone(db),
db: db,
Migration: q.Migration.clone(db),
SysAPI: q.SysAPI.clone(db),
SysDictionary: q.SysDictionary.clone(db),
SysDictionaryDetail: q.SysDictionaryDetail.clone(db),
SysOperationRecord: q.SysOperationRecord.clone(db),
SysRole: q.SysRole.clone(db),
User: q.User.clone(db),
UserRole: q.UserRole.clone(db),
}
}
@@ -62,21 +92,39 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Migration: q.Migration.replaceDB(db),
SysOperationRecord: q.SysOperationRecord.replaceDB(db),
db: db,
Migration: q.Migration.replaceDB(db),
SysAPI: q.SysAPI.replaceDB(db),
SysDictionary: q.SysDictionary.replaceDB(db),
SysDictionaryDetail: q.SysDictionaryDetail.replaceDB(db),
SysOperationRecord: q.SysOperationRecord.replaceDB(db),
SysRole: q.SysRole.replaceDB(db),
User: q.User.replaceDB(db),
UserRole: q.UserRole.replaceDB(db),
}
}
type queryCtx struct {
Migration IMigrationDo
SysOperationRecord ISysOperationRecordDo
Migration IMigrationDo
SysAPI ISysAPIDo
SysDictionary ISysDictionaryDo
SysDictionaryDetail ISysDictionaryDetailDo
SysOperationRecord ISysOperationRecordDo
SysRole ISysRoleDo
User IUserDo
UserRole IUserRoleDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Migration: q.Migration.WithContext(ctx),
SysOperationRecord: q.SysOperationRecord.WithContext(ctx),
Migration: q.Migration.WithContext(ctx),
SysAPI: q.SysAPI.WithContext(ctx),
SysDictionary: q.SysDictionary.WithContext(ctx),
SysDictionaryDetail: q.SysDictionaryDetail.WithContext(ctx),
SysOperationRecord: q.SysOperationRecord.WithContext(ctx),
SysRole: q.SysRole.WithContext(ctx),
User: q.User.WithContext(ctx),
UserRole: q.UserRole.WithContext(ctx),
}
}

View File

@@ -0,0 +1,418 @@
// 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 newSysAPI(db *gorm.DB, opts ...gen.DOOption) sysAPI {
_sysAPI := sysAPI{}
_sysAPI.sysAPIDo.UseDB(db, opts...)
_sysAPI.sysAPIDo.UseModel(&models.SysAPI{})
tableName := _sysAPI.sysAPIDo.TableName()
_sysAPI.ALL = field.NewAsterisk(tableName)
_sysAPI.ID = field.NewUint64(tableName, "id")
_sysAPI.CreatedAt = field.NewTime(tableName, "created_at")
_sysAPI.UpdatedAt = field.NewTime(tableName, "updated_at")
_sysAPI.DeletedAt = field.NewField(tableName, "deleted_at")
_sysAPI.Path = field.NewString(tableName, "path")
_sysAPI.Description = field.NewString(tableName, "description")
_sysAPI.APIGroup = field.NewString(tableName, "api_group")
_sysAPI.Method = field.NewString(tableName, "method")
_sysAPI.fillFieldMap()
return _sysAPI
}
type sysAPI struct {
sysAPIDo sysAPIDo
ALL field.Asterisk
ID field.Uint64
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Path field.String // 路径
Description field.String // 中文描述
APIGroup field.String // 组
Method field.String // 方法
fieldMap map[string]field.Expr
}
func (s sysAPI) Table(newTableName string) *sysAPI {
s.sysAPIDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s sysAPI) As(alias string) *sysAPI {
s.sysAPIDo.DO = *(s.sysAPIDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *sysAPI) updateTableName(table string) *sysAPI {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewUint64(table, "id")
s.CreatedAt = field.NewTime(table, "created_at")
s.UpdatedAt = field.NewTime(table, "updated_at")
s.DeletedAt = field.NewField(table, "deleted_at")
s.Path = field.NewString(table, "path")
s.Description = field.NewString(table, "description")
s.APIGroup = field.NewString(table, "api_group")
s.Method = field.NewString(table, "method")
s.fillFieldMap()
return s
}
func (s *sysAPI) WithContext(ctx context.Context) ISysAPIDo { return s.sysAPIDo.WithContext(ctx) }
func (s sysAPI) TableName() string { return s.sysAPIDo.TableName() }
func (s sysAPI) Alias() string { return s.sysAPIDo.Alias() }
func (s *sysAPI) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *sysAPI) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 8)
s.fieldMap["id"] = s.ID
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["deleted_at"] = s.DeletedAt
s.fieldMap["path"] = s.Path
s.fieldMap["description"] = s.Description
s.fieldMap["api_group"] = s.APIGroup
s.fieldMap["method"] = s.Method
}
func (s sysAPI) clone(db *gorm.DB) sysAPI {
s.sysAPIDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s sysAPI) replaceDB(db *gorm.DB) sysAPI {
s.sysAPIDo.ReplaceDB(db)
return s
}
type sysAPIDo struct{ gen.DO }
type ISysAPIDo interface {
gen.SubQuery
Debug() ISysAPIDo
WithContext(ctx context.Context) ISysAPIDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISysAPIDo
WriteDB() ISysAPIDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISysAPIDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISysAPIDo
Not(conds ...gen.Condition) ISysAPIDo
Or(conds ...gen.Condition) ISysAPIDo
Select(conds ...field.Expr) ISysAPIDo
Where(conds ...gen.Condition) ISysAPIDo
Order(conds ...field.Expr) ISysAPIDo
Distinct(cols ...field.Expr) ISysAPIDo
Omit(cols ...field.Expr) ISysAPIDo
Join(table schema.Tabler, on ...field.Expr) ISysAPIDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISysAPIDo
RightJoin(table schema.Tabler, on ...field.Expr) ISysAPIDo
Group(cols ...field.Expr) ISysAPIDo
Having(conds ...gen.Condition) ISysAPIDo
Limit(limit int) ISysAPIDo
Offset(offset int) ISysAPIDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISysAPIDo
Unscoped() ISysAPIDo
Create(values ...*models.SysAPI) error
CreateInBatches(values []*models.SysAPI, batchSize int) error
Save(values ...*models.SysAPI) error
First() (*models.SysAPI, error)
Take() (*models.SysAPI, error)
Last() (*models.SysAPI, error)
Find() ([]*models.SysAPI, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysAPI, err error)
FindInBatches(result *[]*models.SysAPI, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.SysAPI) (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) ISysAPIDo
Assign(attrs ...field.AssignExpr) ISysAPIDo
Joins(fields ...field.RelationField) ISysAPIDo
Preload(fields ...field.RelationField) ISysAPIDo
FirstOrInit() (*models.SysAPI, error)
FirstOrCreate() (*models.SysAPI, error)
FindByPage(offset int, limit int) (result []*models.SysAPI, 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) ISysAPIDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s sysAPIDo) Debug() ISysAPIDo {
return s.withDO(s.DO.Debug())
}
func (s sysAPIDo) WithContext(ctx context.Context) ISysAPIDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s sysAPIDo) ReadDB() ISysAPIDo {
return s.Clauses(dbresolver.Read)
}
func (s sysAPIDo) WriteDB() ISysAPIDo {
return s.Clauses(dbresolver.Write)
}
func (s sysAPIDo) Session(config *gorm.Session) ISysAPIDo {
return s.withDO(s.DO.Session(config))
}
func (s sysAPIDo) Clauses(conds ...clause.Expression) ISysAPIDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s sysAPIDo) Returning(value interface{}, columns ...string) ISysAPIDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s sysAPIDo) Not(conds ...gen.Condition) ISysAPIDo {
return s.withDO(s.DO.Not(conds...))
}
func (s sysAPIDo) Or(conds ...gen.Condition) ISysAPIDo {
return s.withDO(s.DO.Or(conds...))
}
func (s sysAPIDo) Select(conds ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.Select(conds...))
}
func (s sysAPIDo) Where(conds ...gen.Condition) ISysAPIDo {
return s.withDO(s.DO.Where(conds...))
}
func (s sysAPIDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ISysAPIDo {
return s.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func (s sysAPIDo) Order(conds ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.Order(conds...))
}
func (s sysAPIDo) Distinct(cols ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s sysAPIDo) Omit(cols ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s sysAPIDo) Join(table schema.Tabler, on ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s sysAPIDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s sysAPIDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s sysAPIDo) Group(cols ...field.Expr) ISysAPIDo {
return s.withDO(s.DO.Group(cols...))
}
func (s sysAPIDo) Having(conds ...gen.Condition) ISysAPIDo {
return s.withDO(s.DO.Having(conds...))
}
func (s sysAPIDo) Limit(limit int) ISysAPIDo {
return s.withDO(s.DO.Limit(limit))
}
func (s sysAPIDo) Offset(offset int) ISysAPIDo {
return s.withDO(s.DO.Offset(offset))
}
func (s sysAPIDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysAPIDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s sysAPIDo) Unscoped() ISysAPIDo {
return s.withDO(s.DO.Unscoped())
}
func (s sysAPIDo) Create(values ...*models.SysAPI) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s sysAPIDo) CreateInBatches(values []*models.SysAPI, batchSize int) error {
return s.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 (s sysAPIDo) Save(values ...*models.SysAPI) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s sysAPIDo) First() (*models.SysAPI, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.SysAPI), nil
}
}
func (s sysAPIDo) Take() (*models.SysAPI, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.SysAPI), nil
}
}
func (s sysAPIDo) Last() (*models.SysAPI, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.SysAPI), nil
}
}
func (s sysAPIDo) Find() ([]*models.SysAPI, error) {
result, err := s.DO.Find()
return result.([]*models.SysAPI), err
}
func (s sysAPIDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysAPI, err error) {
buf := make([]*models.SysAPI, 0, batchSize)
err = s.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 (s sysAPIDo) FindInBatches(result *[]*models.SysAPI, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s sysAPIDo) Attrs(attrs ...field.AssignExpr) ISysAPIDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s sysAPIDo) Assign(attrs ...field.AssignExpr) ISysAPIDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s sysAPIDo) Joins(fields ...field.RelationField) ISysAPIDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s sysAPIDo) Preload(fields ...field.RelationField) ISysAPIDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s sysAPIDo) FirstOrInit() (*models.SysAPI, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.SysAPI), nil
}
}
func (s sysAPIDo) FirstOrCreate() (*models.SysAPI, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.SysAPI), nil
}
}
func (s sysAPIDo) FindByPage(offset int, limit int) (result []*models.SysAPI, count int64, err error) {
result, err = s.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 = s.Offset(-1).Limit(-1).Count()
return
}
func (s sysAPIDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s sysAPIDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s sysAPIDo) Delete(models ...*models.SysAPI) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *sysAPIDo) withDO(do gen.Dao) *sysAPIDo {
s.DO = *do.(*gen.DO)
return s
}

View 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 newSysDictionary(db *gorm.DB, opts ...gen.DOOption) sysDictionary {
_sysDictionary := sysDictionary{}
_sysDictionary.sysDictionaryDo.UseDB(db, opts...)
_sysDictionary.sysDictionaryDo.UseModel(&models.SysDictionary{})
tableName := _sysDictionary.sysDictionaryDo.TableName()
_sysDictionary.ALL = field.NewAsterisk(tableName)
_sysDictionary.ID = field.NewUint64(tableName, "id")
_sysDictionary.CreatedAt = field.NewTime(tableName, "created_at")
_sysDictionary.UpdatedAt = field.NewTime(tableName, "updated_at")
_sysDictionary.DeletedAt = field.NewField(tableName, "deleted_at")
_sysDictionary.Name = field.NewString(tableName, "name")
_sysDictionary.Type = field.NewString(tableName, "type")
_sysDictionary.Status = field.NewBool(tableName, "status")
_sysDictionary.Desc = field.NewString(tableName, "desc")
_sysDictionary.fillFieldMap()
return _sysDictionary
}
type sysDictionary struct {
sysDictionaryDo sysDictionaryDo
ALL field.Asterisk
ID field.Uint64
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Name field.String // 字典名(中)
Type field.String // 字典名(英)
Status field.Bool // 状态
Desc field.String // 描述
fieldMap map[string]field.Expr
}
func (s sysDictionary) Table(newTableName string) *sysDictionary {
s.sysDictionaryDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s sysDictionary) As(alias string) *sysDictionary {
s.sysDictionaryDo.DO = *(s.sysDictionaryDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *sysDictionary) updateTableName(table string) *sysDictionary {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewUint64(table, "id")
s.CreatedAt = field.NewTime(table, "created_at")
s.UpdatedAt = field.NewTime(table, "updated_at")
s.DeletedAt = field.NewField(table, "deleted_at")
s.Name = field.NewString(table, "name")
s.Type = field.NewString(table, "type")
s.Status = field.NewBool(table, "status")
s.Desc = field.NewString(table, "desc")
s.fillFieldMap()
return s
}
func (s *sysDictionary) WithContext(ctx context.Context) ISysDictionaryDo {
return s.sysDictionaryDo.WithContext(ctx)
}
func (s sysDictionary) TableName() string { return s.sysDictionaryDo.TableName() }
func (s sysDictionary) Alias() string { return s.sysDictionaryDo.Alias() }
func (s *sysDictionary) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *sysDictionary) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 8)
s.fieldMap["id"] = s.ID
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["deleted_at"] = s.DeletedAt
s.fieldMap["name"] = s.Name
s.fieldMap["type"] = s.Type
s.fieldMap["status"] = s.Status
s.fieldMap["desc"] = s.Desc
}
func (s sysDictionary) clone(db *gorm.DB) sysDictionary {
s.sysDictionaryDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s sysDictionary) replaceDB(db *gorm.DB) sysDictionary {
s.sysDictionaryDo.ReplaceDB(db)
return s
}
type sysDictionaryDo struct{ gen.DO }
type ISysDictionaryDo interface {
gen.SubQuery
Debug() ISysDictionaryDo
WithContext(ctx context.Context) ISysDictionaryDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISysDictionaryDo
WriteDB() ISysDictionaryDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISysDictionaryDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISysDictionaryDo
Not(conds ...gen.Condition) ISysDictionaryDo
Or(conds ...gen.Condition) ISysDictionaryDo
Select(conds ...field.Expr) ISysDictionaryDo
Where(conds ...gen.Condition) ISysDictionaryDo
Order(conds ...field.Expr) ISysDictionaryDo
Distinct(cols ...field.Expr) ISysDictionaryDo
Omit(cols ...field.Expr) ISysDictionaryDo
Join(table schema.Tabler, on ...field.Expr) ISysDictionaryDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDo
RightJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDo
Group(cols ...field.Expr) ISysDictionaryDo
Having(conds ...gen.Condition) ISysDictionaryDo
Limit(limit int) ISysDictionaryDo
Offset(offset int) ISysDictionaryDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISysDictionaryDo
Unscoped() ISysDictionaryDo
Create(values ...*models.SysDictionary) error
CreateInBatches(values []*models.SysDictionary, batchSize int) error
Save(values ...*models.SysDictionary) error
First() (*models.SysDictionary, error)
Take() (*models.SysDictionary, error)
Last() (*models.SysDictionary, error)
Find() ([]*models.SysDictionary, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysDictionary, err error)
FindInBatches(result *[]*models.SysDictionary, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.SysDictionary) (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) ISysDictionaryDo
Assign(attrs ...field.AssignExpr) ISysDictionaryDo
Joins(fields ...field.RelationField) ISysDictionaryDo
Preload(fields ...field.RelationField) ISysDictionaryDo
FirstOrInit() (*models.SysDictionary, error)
FirstOrCreate() (*models.SysDictionary, error)
FindByPage(offset int, limit int) (result []*models.SysDictionary, 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) ISysDictionaryDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s sysDictionaryDo) Debug() ISysDictionaryDo {
return s.withDO(s.DO.Debug())
}
func (s sysDictionaryDo) WithContext(ctx context.Context) ISysDictionaryDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s sysDictionaryDo) ReadDB() ISysDictionaryDo {
return s.Clauses(dbresolver.Read)
}
func (s sysDictionaryDo) WriteDB() ISysDictionaryDo {
return s.Clauses(dbresolver.Write)
}
func (s sysDictionaryDo) Session(config *gorm.Session) ISysDictionaryDo {
return s.withDO(s.DO.Session(config))
}
func (s sysDictionaryDo) Clauses(conds ...clause.Expression) ISysDictionaryDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s sysDictionaryDo) Returning(value interface{}, columns ...string) ISysDictionaryDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s sysDictionaryDo) Not(conds ...gen.Condition) ISysDictionaryDo {
return s.withDO(s.DO.Not(conds...))
}
func (s sysDictionaryDo) Or(conds ...gen.Condition) ISysDictionaryDo {
return s.withDO(s.DO.Or(conds...))
}
func (s sysDictionaryDo) Select(conds ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.Select(conds...))
}
func (s sysDictionaryDo) Where(conds ...gen.Condition) ISysDictionaryDo {
return s.withDO(s.DO.Where(conds...))
}
func (s sysDictionaryDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ISysDictionaryDo {
return s.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func (s sysDictionaryDo) Order(conds ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.Order(conds...))
}
func (s sysDictionaryDo) Distinct(cols ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s sysDictionaryDo) Omit(cols ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s sysDictionaryDo) Join(table schema.Tabler, on ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s sysDictionaryDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s sysDictionaryDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s sysDictionaryDo) Group(cols ...field.Expr) ISysDictionaryDo {
return s.withDO(s.DO.Group(cols...))
}
func (s sysDictionaryDo) Having(conds ...gen.Condition) ISysDictionaryDo {
return s.withDO(s.DO.Having(conds...))
}
func (s sysDictionaryDo) Limit(limit int) ISysDictionaryDo {
return s.withDO(s.DO.Limit(limit))
}
func (s sysDictionaryDo) Offset(offset int) ISysDictionaryDo {
return s.withDO(s.DO.Offset(offset))
}
func (s sysDictionaryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysDictionaryDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s sysDictionaryDo) Unscoped() ISysDictionaryDo {
return s.withDO(s.DO.Unscoped())
}
func (s sysDictionaryDo) Create(values ...*models.SysDictionary) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s sysDictionaryDo) CreateInBatches(values []*models.SysDictionary, batchSize int) error {
return s.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 (s sysDictionaryDo) Save(values ...*models.SysDictionary) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s sysDictionaryDo) First() (*models.SysDictionary, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionary), nil
}
}
func (s sysDictionaryDo) Take() (*models.SysDictionary, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionary), nil
}
}
func (s sysDictionaryDo) Last() (*models.SysDictionary, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionary), nil
}
}
func (s sysDictionaryDo) Find() ([]*models.SysDictionary, error) {
result, err := s.DO.Find()
return result.([]*models.SysDictionary), err
}
func (s sysDictionaryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysDictionary, err error) {
buf := make([]*models.SysDictionary, 0, batchSize)
err = s.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 (s sysDictionaryDo) FindInBatches(result *[]*models.SysDictionary, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s sysDictionaryDo) Attrs(attrs ...field.AssignExpr) ISysDictionaryDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s sysDictionaryDo) Assign(attrs ...field.AssignExpr) ISysDictionaryDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s sysDictionaryDo) Joins(fields ...field.RelationField) ISysDictionaryDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s sysDictionaryDo) Preload(fields ...field.RelationField) ISysDictionaryDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s sysDictionaryDo) FirstOrInit() (*models.SysDictionary, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionary), nil
}
}
func (s sysDictionaryDo) FirstOrCreate() (*models.SysDictionary, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionary), nil
}
}
func (s sysDictionaryDo) FindByPage(offset int, limit int) (result []*models.SysDictionary, count int64, err error) {
result, err = s.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 = s.Offset(-1).Limit(-1).Count()
return
}
func (s sysDictionaryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s sysDictionaryDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s sysDictionaryDo) Delete(models ...*models.SysDictionary) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *sysDictionaryDo) withDO(do gen.Dao) *sysDictionaryDo {
s.DO = *do.(*gen.DO)
return s
}

View File

@@ -0,0 +1,424 @@
// 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 newSysDictionaryDetail(db *gorm.DB, opts ...gen.DOOption) sysDictionaryDetail {
_sysDictionaryDetail := sysDictionaryDetail{}
_sysDictionaryDetail.sysDictionaryDetailDo.UseDB(db, opts...)
_sysDictionaryDetail.sysDictionaryDetailDo.UseModel(&models.SysDictionaryDetail{})
tableName := _sysDictionaryDetail.sysDictionaryDetailDo.TableName()
_sysDictionaryDetail.ALL = field.NewAsterisk(tableName)
_sysDictionaryDetail.ID = field.NewUint64(tableName, "id")
_sysDictionaryDetail.CreatedAt = field.NewTime(tableName, "created_at")
_sysDictionaryDetail.UpdatedAt = field.NewTime(tableName, "updated_at")
_sysDictionaryDetail.DeletedAt = field.NewField(tableName, "deleted_at")
_sysDictionaryDetail.Label = field.NewString(tableName, "label")
_sysDictionaryDetail.Value = field.NewInt64(tableName, "value")
_sysDictionaryDetail.Status = field.NewBool(tableName, "status")
_sysDictionaryDetail.Sort = field.NewInt64(tableName, "sort")
_sysDictionaryDetail.SysDictionaryID = field.NewInt64(tableName, "sys_dictionary_id")
_sysDictionaryDetail.fillFieldMap()
return _sysDictionaryDetail
}
type sysDictionaryDetail struct {
sysDictionaryDetailDo sysDictionaryDetailDo
ALL field.Asterisk
ID field.Uint64
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Label field.String // 展示值
Value field.Int64 // 字典值
Status field.Bool // 启用状态
Sort field.Int64 // 排序标记
SysDictionaryID field.Int64 // 关联标记
fieldMap map[string]field.Expr
}
func (s sysDictionaryDetail) Table(newTableName string) *sysDictionaryDetail {
s.sysDictionaryDetailDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s sysDictionaryDetail) As(alias string) *sysDictionaryDetail {
s.sysDictionaryDetailDo.DO = *(s.sysDictionaryDetailDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *sysDictionaryDetail) updateTableName(table string) *sysDictionaryDetail {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewUint64(table, "id")
s.CreatedAt = field.NewTime(table, "created_at")
s.UpdatedAt = field.NewTime(table, "updated_at")
s.DeletedAt = field.NewField(table, "deleted_at")
s.Label = field.NewString(table, "label")
s.Value = field.NewInt64(table, "value")
s.Status = field.NewBool(table, "status")
s.Sort = field.NewInt64(table, "sort")
s.SysDictionaryID = field.NewInt64(table, "sys_dictionary_id")
s.fillFieldMap()
return s
}
func (s *sysDictionaryDetail) WithContext(ctx context.Context) ISysDictionaryDetailDo {
return s.sysDictionaryDetailDo.WithContext(ctx)
}
func (s sysDictionaryDetail) TableName() string { return s.sysDictionaryDetailDo.TableName() }
func (s sysDictionaryDetail) Alias() string { return s.sysDictionaryDetailDo.Alias() }
func (s *sysDictionaryDetail) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *sysDictionaryDetail) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 9)
s.fieldMap["id"] = s.ID
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["deleted_at"] = s.DeletedAt
s.fieldMap["label"] = s.Label
s.fieldMap["value"] = s.Value
s.fieldMap["status"] = s.Status
s.fieldMap["sort"] = s.Sort
s.fieldMap["sys_dictionary_id"] = s.SysDictionaryID
}
func (s sysDictionaryDetail) clone(db *gorm.DB) sysDictionaryDetail {
s.sysDictionaryDetailDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s sysDictionaryDetail) replaceDB(db *gorm.DB) sysDictionaryDetail {
s.sysDictionaryDetailDo.ReplaceDB(db)
return s
}
type sysDictionaryDetailDo struct{ gen.DO }
type ISysDictionaryDetailDo interface {
gen.SubQuery
Debug() ISysDictionaryDetailDo
WithContext(ctx context.Context) ISysDictionaryDetailDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISysDictionaryDetailDo
WriteDB() ISysDictionaryDetailDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISysDictionaryDetailDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISysDictionaryDetailDo
Not(conds ...gen.Condition) ISysDictionaryDetailDo
Or(conds ...gen.Condition) ISysDictionaryDetailDo
Select(conds ...field.Expr) ISysDictionaryDetailDo
Where(conds ...gen.Condition) ISysDictionaryDetailDo
Order(conds ...field.Expr) ISysDictionaryDetailDo
Distinct(cols ...field.Expr) ISysDictionaryDetailDo
Omit(cols ...field.Expr) ISysDictionaryDetailDo
Join(table schema.Tabler, on ...field.Expr) ISysDictionaryDetailDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDetailDo
RightJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDetailDo
Group(cols ...field.Expr) ISysDictionaryDetailDo
Having(conds ...gen.Condition) ISysDictionaryDetailDo
Limit(limit int) ISysDictionaryDetailDo
Offset(offset int) ISysDictionaryDetailDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISysDictionaryDetailDo
Unscoped() ISysDictionaryDetailDo
Create(values ...*models.SysDictionaryDetail) error
CreateInBatches(values []*models.SysDictionaryDetail, batchSize int) error
Save(values ...*models.SysDictionaryDetail) error
First() (*models.SysDictionaryDetail, error)
Take() (*models.SysDictionaryDetail, error)
Last() (*models.SysDictionaryDetail, error)
Find() ([]*models.SysDictionaryDetail, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysDictionaryDetail, err error)
FindInBatches(result *[]*models.SysDictionaryDetail, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.SysDictionaryDetail) (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) ISysDictionaryDetailDo
Assign(attrs ...field.AssignExpr) ISysDictionaryDetailDo
Joins(fields ...field.RelationField) ISysDictionaryDetailDo
Preload(fields ...field.RelationField) ISysDictionaryDetailDo
FirstOrInit() (*models.SysDictionaryDetail, error)
FirstOrCreate() (*models.SysDictionaryDetail, error)
FindByPage(offset int, limit int) (result []*models.SysDictionaryDetail, 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) ISysDictionaryDetailDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s sysDictionaryDetailDo) Debug() ISysDictionaryDetailDo {
return s.withDO(s.DO.Debug())
}
func (s sysDictionaryDetailDo) WithContext(ctx context.Context) ISysDictionaryDetailDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s sysDictionaryDetailDo) ReadDB() ISysDictionaryDetailDo {
return s.Clauses(dbresolver.Read)
}
func (s sysDictionaryDetailDo) WriteDB() ISysDictionaryDetailDo {
return s.Clauses(dbresolver.Write)
}
func (s sysDictionaryDetailDo) Session(config *gorm.Session) ISysDictionaryDetailDo {
return s.withDO(s.DO.Session(config))
}
func (s sysDictionaryDetailDo) Clauses(conds ...clause.Expression) ISysDictionaryDetailDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s sysDictionaryDetailDo) Returning(value interface{}, columns ...string) ISysDictionaryDetailDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s sysDictionaryDetailDo) Not(conds ...gen.Condition) ISysDictionaryDetailDo {
return s.withDO(s.DO.Not(conds...))
}
func (s sysDictionaryDetailDo) Or(conds ...gen.Condition) ISysDictionaryDetailDo {
return s.withDO(s.DO.Or(conds...))
}
func (s sysDictionaryDetailDo) Select(conds ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Select(conds...))
}
func (s sysDictionaryDetailDo) Where(conds ...gen.Condition) ISysDictionaryDetailDo {
return s.withDO(s.DO.Where(conds...))
}
func (s sysDictionaryDetailDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ISysDictionaryDetailDo {
return s.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func (s sysDictionaryDetailDo) Order(conds ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Order(conds...))
}
func (s sysDictionaryDetailDo) Distinct(cols ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s sysDictionaryDetailDo) Omit(cols ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s sysDictionaryDetailDo) Join(table schema.Tabler, on ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s sysDictionaryDetailDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s sysDictionaryDetailDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s sysDictionaryDetailDo) Group(cols ...field.Expr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Group(cols...))
}
func (s sysDictionaryDetailDo) Having(conds ...gen.Condition) ISysDictionaryDetailDo {
return s.withDO(s.DO.Having(conds...))
}
func (s sysDictionaryDetailDo) Limit(limit int) ISysDictionaryDetailDo {
return s.withDO(s.DO.Limit(limit))
}
func (s sysDictionaryDetailDo) Offset(offset int) ISysDictionaryDetailDo {
return s.withDO(s.DO.Offset(offset))
}
func (s sysDictionaryDetailDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysDictionaryDetailDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s sysDictionaryDetailDo) Unscoped() ISysDictionaryDetailDo {
return s.withDO(s.DO.Unscoped())
}
func (s sysDictionaryDetailDo) Create(values ...*models.SysDictionaryDetail) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s sysDictionaryDetailDo) CreateInBatches(values []*models.SysDictionaryDetail, batchSize int) error {
return s.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 (s sysDictionaryDetailDo) Save(values ...*models.SysDictionaryDetail) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s sysDictionaryDetailDo) First() (*models.SysDictionaryDetail, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionaryDetail), nil
}
}
func (s sysDictionaryDetailDo) Take() (*models.SysDictionaryDetail, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionaryDetail), nil
}
}
func (s sysDictionaryDetailDo) Last() (*models.SysDictionaryDetail, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionaryDetail), nil
}
}
func (s sysDictionaryDetailDo) Find() ([]*models.SysDictionaryDetail, error) {
result, err := s.DO.Find()
return result.([]*models.SysDictionaryDetail), err
}
func (s sysDictionaryDetailDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysDictionaryDetail, err error) {
buf := make([]*models.SysDictionaryDetail, 0, batchSize)
err = s.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 (s sysDictionaryDetailDo) FindInBatches(result *[]*models.SysDictionaryDetail, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s sysDictionaryDetailDo) Attrs(attrs ...field.AssignExpr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s sysDictionaryDetailDo) Assign(attrs ...field.AssignExpr) ISysDictionaryDetailDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s sysDictionaryDetailDo) Joins(fields ...field.RelationField) ISysDictionaryDetailDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s sysDictionaryDetailDo) Preload(fields ...field.RelationField) ISysDictionaryDetailDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s sysDictionaryDetailDo) FirstOrInit() (*models.SysDictionaryDetail, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionaryDetail), nil
}
}
func (s sysDictionaryDetailDo) FirstOrCreate() (*models.SysDictionaryDetail, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.SysDictionaryDetail), nil
}
}
func (s sysDictionaryDetailDo) FindByPage(offset int, limit int) (result []*models.SysDictionaryDetail, count int64, err error) {
result, err = s.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 = s.Offset(-1).Limit(-1).Count()
return
}
func (s sysDictionaryDetailDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s sysDictionaryDetailDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s sysDictionaryDetailDo) Delete(models ...*models.SysDictionaryDetail) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *sysDictionaryDetailDo) withDO(do gen.Dao) *sysDictionaryDetailDo {
s.DO = *do.(*gen.DO)
return s
}

View File

@@ -0,0 +1,418 @@
// 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 newSysRole(db *gorm.DB, opts ...gen.DOOption) sysRole {
_sysRole := sysRole{}
_sysRole.sysRoleDo.UseDB(db, opts...)
_sysRole.sysRoleDo.UseModel(&models.SysRole{})
tableName := _sysRole.sysRoleDo.TableName()
_sysRole.ALL = field.NewAsterisk(tableName)
_sysRole.ID = field.NewUint64(tableName, "id")
_sysRole.CreatedAt = field.NewTime(tableName, "created_at")
_sysRole.UpdatedAt = field.NewTime(tableName, "updated_at")
_sysRole.DeletedAt = field.NewField(tableName, "deleted_at")
_sysRole.Alias_ = field.NewString(tableName, "alias")
_sysRole.Name = field.NewString(tableName, "name")
_sysRole.ParentID = field.NewUint64(tableName, "parent_id")
_sysRole.DefaultRouter = field.NewString(tableName, "default_router")
_sysRole.fillFieldMap()
return _sysRole
}
type sysRole struct {
sysRoleDo sysRoleDo
ALL field.Asterisk
ID field.Uint64
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Alias_ field.String // 角色Alias
Name field.String // 角色名
ParentID field.Uint64 // 父角色ID
DefaultRouter field.String // 默认菜单
fieldMap map[string]field.Expr
}
func (s sysRole) Table(newTableName string) *sysRole {
s.sysRoleDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s sysRole) As(alias string) *sysRole {
s.sysRoleDo.DO = *(s.sysRoleDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *sysRole) updateTableName(table string) *sysRole {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewUint64(table, "id")
s.CreatedAt = field.NewTime(table, "created_at")
s.UpdatedAt = field.NewTime(table, "updated_at")
s.DeletedAt = field.NewField(table, "deleted_at")
s.Alias_ = field.NewString(table, "alias")
s.Name = field.NewString(table, "name")
s.ParentID = field.NewUint64(table, "parent_id")
s.DefaultRouter = field.NewString(table, "default_router")
s.fillFieldMap()
return s
}
func (s *sysRole) WithContext(ctx context.Context) ISysRoleDo { return s.sysRoleDo.WithContext(ctx) }
func (s sysRole) TableName() string { return s.sysRoleDo.TableName() }
func (s sysRole) Alias() string { return s.sysRoleDo.Alias() }
func (s *sysRole) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *sysRole) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 8)
s.fieldMap["id"] = s.ID
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["deleted_at"] = s.DeletedAt
s.fieldMap["alias"] = s.Alias_
s.fieldMap["name"] = s.Name
s.fieldMap["parent_id"] = s.ParentID
s.fieldMap["default_router"] = s.DefaultRouter
}
func (s sysRole) clone(db *gorm.DB) sysRole {
s.sysRoleDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s sysRole) replaceDB(db *gorm.DB) sysRole {
s.sysRoleDo.ReplaceDB(db)
return s
}
type sysRoleDo struct{ gen.DO }
type ISysRoleDo interface {
gen.SubQuery
Debug() ISysRoleDo
WithContext(ctx context.Context) ISysRoleDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISysRoleDo
WriteDB() ISysRoleDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISysRoleDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISysRoleDo
Not(conds ...gen.Condition) ISysRoleDo
Or(conds ...gen.Condition) ISysRoleDo
Select(conds ...field.Expr) ISysRoleDo
Where(conds ...gen.Condition) ISysRoleDo
Order(conds ...field.Expr) ISysRoleDo
Distinct(cols ...field.Expr) ISysRoleDo
Omit(cols ...field.Expr) ISysRoleDo
Join(table schema.Tabler, on ...field.Expr) ISysRoleDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISysRoleDo
RightJoin(table schema.Tabler, on ...field.Expr) ISysRoleDo
Group(cols ...field.Expr) ISysRoleDo
Having(conds ...gen.Condition) ISysRoleDo
Limit(limit int) ISysRoleDo
Offset(offset int) ISysRoleDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISysRoleDo
Unscoped() ISysRoleDo
Create(values ...*models.SysRole) error
CreateInBatches(values []*models.SysRole, batchSize int) error
Save(values ...*models.SysRole) error
First() (*models.SysRole, error)
Take() (*models.SysRole, error)
Last() (*models.SysRole, error)
Find() ([]*models.SysRole, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysRole, err error)
FindInBatches(result *[]*models.SysRole, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.SysRole) (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) ISysRoleDo
Assign(attrs ...field.AssignExpr) ISysRoleDo
Joins(fields ...field.RelationField) ISysRoleDo
Preload(fields ...field.RelationField) ISysRoleDo
FirstOrInit() (*models.SysRole, error)
FirstOrCreate() (*models.SysRole, error)
FindByPage(offset int, limit int) (result []*models.SysRole, 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) ISysRoleDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s sysRoleDo) Debug() ISysRoleDo {
return s.withDO(s.DO.Debug())
}
func (s sysRoleDo) WithContext(ctx context.Context) ISysRoleDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s sysRoleDo) ReadDB() ISysRoleDo {
return s.Clauses(dbresolver.Read)
}
func (s sysRoleDo) WriteDB() ISysRoleDo {
return s.Clauses(dbresolver.Write)
}
func (s sysRoleDo) Session(config *gorm.Session) ISysRoleDo {
return s.withDO(s.DO.Session(config))
}
func (s sysRoleDo) Clauses(conds ...clause.Expression) ISysRoleDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s sysRoleDo) Returning(value interface{}, columns ...string) ISysRoleDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s sysRoleDo) Not(conds ...gen.Condition) ISysRoleDo {
return s.withDO(s.DO.Not(conds...))
}
func (s sysRoleDo) Or(conds ...gen.Condition) ISysRoleDo {
return s.withDO(s.DO.Or(conds...))
}
func (s sysRoleDo) Select(conds ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.Select(conds...))
}
func (s sysRoleDo) Where(conds ...gen.Condition) ISysRoleDo {
return s.withDO(s.DO.Where(conds...))
}
func (s sysRoleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ISysRoleDo {
return s.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func (s sysRoleDo) Order(conds ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.Order(conds...))
}
func (s sysRoleDo) Distinct(cols ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s sysRoleDo) Omit(cols ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s sysRoleDo) Join(table schema.Tabler, on ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s sysRoleDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s sysRoleDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s sysRoleDo) Group(cols ...field.Expr) ISysRoleDo {
return s.withDO(s.DO.Group(cols...))
}
func (s sysRoleDo) Having(conds ...gen.Condition) ISysRoleDo {
return s.withDO(s.DO.Having(conds...))
}
func (s sysRoleDo) Limit(limit int) ISysRoleDo {
return s.withDO(s.DO.Limit(limit))
}
func (s sysRoleDo) Offset(offset int) ISysRoleDo {
return s.withDO(s.DO.Offset(offset))
}
func (s sysRoleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysRoleDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s sysRoleDo) Unscoped() ISysRoleDo {
return s.withDO(s.DO.Unscoped())
}
func (s sysRoleDo) Create(values ...*models.SysRole) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s sysRoleDo) CreateInBatches(values []*models.SysRole, batchSize int) error {
return s.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 (s sysRoleDo) Save(values ...*models.SysRole) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s sysRoleDo) First() (*models.SysRole, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.SysRole), nil
}
}
func (s sysRoleDo) Take() (*models.SysRole, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.SysRole), nil
}
}
func (s sysRoleDo) Last() (*models.SysRole, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.SysRole), nil
}
}
func (s sysRoleDo) Find() ([]*models.SysRole, error) {
result, err := s.DO.Find()
return result.([]*models.SysRole), err
}
func (s sysRoleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysRole, err error) {
buf := make([]*models.SysRole, 0, batchSize)
err = s.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 (s sysRoleDo) FindInBatches(result *[]*models.SysRole, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s sysRoleDo) Attrs(attrs ...field.AssignExpr) ISysRoleDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s sysRoleDo) Assign(attrs ...field.AssignExpr) ISysRoleDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s sysRoleDo) Joins(fields ...field.RelationField) ISysRoleDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s sysRoleDo) Preload(fields ...field.RelationField) ISysRoleDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s sysRoleDo) FirstOrInit() (*models.SysRole, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.SysRole), nil
}
}
func (s sysRoleDo) FirstOrCreate() (*models.SysRole, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.SysRole), nil
}
}
func (s sysRoleDo) FindByPage(offset int, limit int) (result []*models.SysRole, count int64, err error) {
result, err = s.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 = s.Offset(-1).Limit(-1).Count()
return
}
func (s sysRoleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s sysRoleDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s sysRoleDo) Delete(models ...*models.SysRole) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *sysRoleDo) withDO(do gen.Dao) *sysRoleDo {
s.DO = *do.(*gen.DO)
return s
}

View File

@@ -0,0 +1,394 @@
// 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 newUserRole(db *gorm.DB, opts ...gen.DOOption) userRole {
_userRole := userRole{}
_userRole.userRoleDo.UseDB(db, opts...)
_userRole.userRoleDo.UseModel(&models.UserRole{})
tableName := _userRole.userRoleDo.TableName()
_userRole.ALL = field.NewAsterisk(tableName)
_userRole.UserID = field.NewUint64(tableName, "user_id")
_userRole.RoleID = field.NewUint64(tableName, "role_id")
_userRole.fillFieldMap()
return _userRole
}
type userRole struct {
userRoleDo userRoleDo
ALL field.Asterisk
UserID field.Uint64
RoleID field.Uint64
fieldMap map[string]field.Expr
}
func (u userRole) Table(newTableName string) *userRole {
u.userRoleDo.UseTable(newTableName)
return u.updateTableName(newTableName)
}
func (u userRole) As(alias string) *userRole {
u.userRoleDo.DO = *(u.userRoleDo.As(alias).(*gen.DO))
return u.updateTableName(alias)
}
func (u *userRole) updateTableName(table string) *userRole {
u.ALL = field.NewAsterisk(table)
u.UserID = field.NewUint64(table, "user_id")
u.RoleID = field.NewUint64(table, "role_id")
u.fillFieldMap()
return u
}
func (u *userRole) WithContext(ctx context.Context) IUserRoleDo { return u.userRoleDo.WithContext(ctx) }
func (u userRole) TableName() string { return u.userRoleDo.TableName() }
func (u userRole) Alias() string { return u.userRoleDo.Alias() }
func (u *userRole) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := u.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (u *userRole) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 2)
u.fieldMap["user_id"] = u.UserID
u.fieldMap["role_id"] = u.RoleID
}
func (u userRole) clone(db *gorm.DB) userRole {
u.userRoleDo.ReplaceConnPool(db.Statement.ConnPool)
return u
}
func (u userRole) replaceDB(db *gorm.DB) userRole {
u.userRoleDo.ReplaceDB(db)
return u
}
type userRoleDo struct{ gen.DO }
type IUserRoleDo interface {
gen.SubQuery
Debug() IUserRoleDo
WithContext(ctx context.Context) IUserRoleDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IUserRoleDo
WriteDB() IUserRoleDo
As(alias string) gen.Dao
Session(config *gorm.Session) IUserRoleDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IUserRoleDo
Not(conds ...gen.Condition) IUserRoleDo
Or(conds ...gen.Condition) IUserRoleDo
Select(conds ...field.Expr) IUserRoleDo
Where(conds ...gen.Condition) IUserRoleDo
Order(conds ...field.Expr) IUserRoleDo
Distinct(cols ...field.Expr) IUserRoleDo
Omit(cols ...field.Expr) IUserRoleDo
Join(table schema.Tabler, on ...field.Expr) IUserRoleDo
LeftJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo
RightJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo
Group(cols ...field.Expr) IUserRoleDo
Having(conds ...gen.Condition) IUserRoleDo
Limit(limit int) IUserRoleDo
Offset(offset int) IUserRoleDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserRoleDo
Unscoped() IUserRoleDo
Create(values ...*models.UserRole) error
CreateInBatches(values []*models.UserRole, batchSize int) error
Save(values ...*models.UserRole) error
First() (*models.UserRole, error)
Take() (*models.UserRole, error)
Last() (*models.UserRole, error)
Find() ([]*models.UserRole, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.UserRole, err error)
FindInBatches(result *[]*models.UserRole, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.UserRole) (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) IUserRoleDo
Assign(attrs ...field.AssignExpr) IUserRoleDo
Joins(fields ...field.RelationField) IUserRoleDo
Preload(fields ...field.RelationField) IUserRoleDo
FirstOrInit() (*models.UserRole, error)
FirstOrCreate() (*models.UserRole, error)
FindByPage(offset int, limit int) (result []*models.UserRole, 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) IUserRoleDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (u userRoleDo) Debug() IUserRoleDo {
return u.withDO(u.DO.Debug())
}
func (u userRoleDo) WithContext(ctx context.Context) IUserRoleDo {
return u.withDO(u.DO.WithContext(ctx))
}
func (u userRoleDo) ReadDB() IUserRoleDo {
return u.Clauses(dbresolver.Read)
}
func (u userRoleDo) WriteDB() IUserRoleDo {
return u.Clauses(dbresolver.Write)
}
func (u userRoleDo) Session(config *gorm.Session) IUserRoleDo {
return u.withDO(u.DO.Session(config))
}
func (u userRoleDo) Clauses(conds ...clause.Expression) IUserRoleDo {
return u.withDO(u.DO.Clauses(conds...))
}
func (u userRoleDo) Returning(value interface{}, columns ...string) IUserRoleDo {
return u.withDO(u.DO.Returning(value, columns...))
}
func (u userRoleDo) Not(conds ...gen.Condition) IUserRoleDo {
return u.withDO(u.DO.Not(conds...))
}
func (u userRoleDo) Or(conds ...gen.Condition) IUserRoleDo {
return u.withDO(u.DO.Or(conds...))
}
func (u userRoleDo) Select(conds ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.Select(conds...))
}
func (u userRoleDo) Where(conds ...gen.Condition) IUserRoleDo {
return u.withDO(u.DO.Where(conds...))
}
func (u userRoleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IUserRoleDo {
return u.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func (u userRoleDo) Order(conds ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.Order(conds...))
}
func (u userRoleDo) Distinct(cols ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.Distinct(cols...))
}
func (u userRoleDo) Omit(cols ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.Omit(cols...))
}
func (u userRoleDo) Join(table schema.Tabler, on ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.Join(table, on...))
}
func (u userRoleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.LeftJoin(table, on...))
}
func (u userRoleDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.RightJoin(table, on...))
}
func (u userRoleDo) Group(cols ...field.Expr) IUserRoleDo {
return u.withDO(u.DO.Group(cols...))
}
func (u userRoleDo) Having(conds ...gen.Condition) IUserRoleDo {
return u.withDO(u.DO.Having(conds...))
}
func (u userRoleDo) Limit(limit int) IUserRoleDo {
return u.withDO(u.DO.Limit(limit))
}
func (u userRoleDo) Offset(offset int) IUserRoleDo {
return u.withDO(u.DO.Offset(offset))
}
func (u userRoleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserRoleDo {
return u.withDO(u.DO.Scopes(funcs...))
}
func (u userRoleDo) Unscoped() IUserRoleDo {
return u.withDO(u.DO.Unscoped())
}
func (u userRoleDo) Create(values ...*models.UserRole) error {
if len(values) == 0 {
return nil
}
return u.DO.Create(values)
}
func (u userRoleDo) CreateInBatches(values []*models.UserRole, batchSize int) error {
return u.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 (u userRoleDo) Save(values ...*models.UserRole) error {
if len(values) == 0 {
return nil
}
return u.DO.Save(values)
}
func (u userRoleDo) First() (*models.UserRole, error) {
if result, err := u.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.UserRole), nil
}
}
func (u userRoleDo) Take() (*models.UserRole, error) {
if result, err := u.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.UserRole), nil
}
}
func (u userRoleDo) Last() (*models.UserRole, error) {
if result, err := u.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.UserRole), nil
}
}
func (u userRoleDo) Find() ([]*models.UserRole, error) {
result, err := u.DO.Find()
return result.([]*models.UserRole), err
}
func (u userRoleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.UserRole, err error) {
buf := make([]*models.UserRole, 0, batchSize)
err = u.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 (u userRoleDo) FindInBatches(result *[]*models.UserRole, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return u.DO.FindInBatches(result, batchSize, fc)
}
func (u userRoleDo) Attrs(attrs ...field.AssignExpr) IUserRoleDo {
return u.withDO(u.DO.Attrs(attrs...))
}
func (u userRoleDo) Assign(attrs ...field.AssignExpr) IUserRoleDo {
return u.withDO(u.DO.Assign(attrs...))
}
func (u userRoleDo) Joins(fields ...field.RelationField) IUserRoleDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Joins(_f))
}
return &u
}
func (u userRoleDo) Preload(fields ...field.RelationField) IUserRoleDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Preload(_f))
}
return &u
}
func (u userRoleDo) FirstOrInit() (*models.UserRole, error) {
if result, err := u.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.UserRole), nil
}
}
func (u userRoleDo) FirstOrCreate() (*models.UserRole, error) {
if result, err := u.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.UserRole), nil
}
}
func (u userRoleDo) FindByPage(offset int, limit int) (result []*models.UserRole, count int64, err error) {
result, err = u.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 = u.Offset(-1).Limit(-1).Count()
return
}
func (u userRoleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = u.Count()
if err != nil {
return
}
err = u.Offset(offset).Limit(limit).Scan(result)
return
}
func (u userRoleDo) Scan(result interface{}) (err error) {
return u.DO.Scan(result)
}
func (u userRoleDo) Delete(models ...*models.UserRole) (result gen.ResultInfo, err error) {
return u.DO.Delete(models)
}
func (u *userRoleDo) withDO(do gen.Dao) *userRoleDo {
u.DO = *do.(*gen.DO)
return u
}

438
database/query/users.gen.go Normal file
View File

@@ -0,0 +1,438 @@
// 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 newUser(db *gorm.DB, opts ...gen.DOOption) user {
_user := user{}
_user.userDo.UseDB(db, opts...)
_user.userDo.UseModel(&models.User{})
tableName := _user.userDo.TableName()
_user.ALL = field.NewAsterisk(tableName)
_user.ID = field.NewUint64(tableName, "id")
_user.CreatedAt = field.NewTime(tableName, "created_at")
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
_user.DeletedAt = field.NewField(tableName, "deleted_at")
_user.UUID = field.NewString(tableName, "uuid")
_user.Username = field.NewString(tableName, "username")
_user.Password = field.NewString(tableName, "password")
_user.Nickname = field.NewString(tableName, "nickname")
_user.Avatar = field.NewString(tableName, "avatar")
_user.RoleID = field.NewUint64(tableName, "role_id")
_user.Phone = field.NewString(tableName, "phone")
_user.Email = field.NewString(tableName, "email")
_user.Status = field.NewString(tableName, "status")
_user.fillFieldMap()
return _user
}
type user struct {
userDo userDo
ALL field.Asterisk
ID field.Uint64
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
UUID field.String // UUID
Username field.String // 登录名
Password field.String // 登录密码
Nickname field.String // 昵称
Avatar field.String // 头像
RoleID field.Uint64 // 角色ID
Phone field.String // 手机号
Email field.String // 邮箱
Status field.String // 用户状态
fieldMap map[string]field.Expr
}
func (u user) Table(newTableName string) *user {
u.userDo.UseTable(newTableName)
return u.updateTableName(newTableName)
}
func (u user) As(alias string) *user {
u.userDo.DO = *(u.userDo.As(alias).(*gen.DO))
return u.updateTableName(alias)
}
func (u *user) updateTableName(table string) *user {
u.ALL = field.NewAsterisk(table)
u.ID = field.NewUint64(table, "id")
u.CreatedAt = field.NewTime(table, "created_at")
u.UpdatedAt = field.NewTime(table, "updated_at")
u.DeletedAt = field.NewField(table, "deleted_at")
u.UUID = field.NewString(table, "uuid")
u.Username = field.NewString(table, "username")
u.Password = field.NewString(table, "password")
u.Nickname = field.NewString(table, "nickname")
u.Avatar = field.NewString(table, "avatar")
u.RoleID = field.NewUint64(table, "role_id")
u.Phone = field.NewString(table, "phone")
u.Email = field.NewString(table, "email")
u.Status = field.NewString(table, "status")
u.fillFieldMap()
return u
}
func (u *user) WithContext(ctx context.Context) IUserDo { return u.userDo.WithContext(ctx) }
func (u user) TableName() string { return u.userDo.TableName() }
func (u user) Alias() string { return u.userDo.Alias() }
func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := u.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (u *user) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 13)
u.fieldMap["id"] = u.ID
u.fieldMap["created_at"] = u.CreatedAt
u.fieldMap["updated_at"] = u.UpdatedAt
u.fieldMap["deleted_at"] = u.DeletedAt
u.fieldMap["uuid"] = u.UUID
u.fieldMap["username"] = u.Username
u.fieldMap["password"] = u.Password
u.fieldMap["nickname"] = u.Nickname
u.fieldMap["avatar"] = u.Avatar
u.fieldMap["role_id"] = u.RoleID
u.fieldMap["phone"] = u.Phone
u.fieldMap["email"] = u.Email
u.fieldMap["status"] = u.Status
}
func (u user) clone(db *gorm.DB) user {
u.userDo.ReplaceConnPool(db.Statement.ConnPool)
return u
}
func (u user) replaceDB(db *gorm.DB) user {
u.userDo.ReplaceDB(db)
return u
}
type userDo struct{ gen.DO }
type IUserDo interface {
gen.SubQuery
Debug() IUserDo
WithContext(ctx context.Context) IUserDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IUserDo
WriteDB() IUserDo
As(alias string) gen.Dao
Session(config *gorm.Session) IUserDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IUserDo
Not(conds ...gen.Condition) IUserDo
Or(conds ...gen.Condition) IUserDo
Select(conds ...field.Expr) IUserDo
Where(conds ...gen.Condition) IUserDo
Order(conds ...field.Expr) IUserDo
Distinct(cols ...field.Expr) IUserDo
Omit(cols ...field.Expr) IUserDo
Join(table schema.Tabler, on ...field.Expr) IUserDo
LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo
RightJoin(table schema.Tabler, on ...field.Expr) IUserDo
Group(cols ...field.Expr) IUserDo
Having(conds ...gen.Condition) IUserDo
Limit(limit int) IUserDo
Offset(offset int) IUserDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo
Unscoped() IUserDo
Create(values ...*models.User) error
CreateInBatches(values []*models.User, batchSize int) error
Save(values ...*models.User) error
First() (*models.User, error)
Take() (*models.User, error)
Last() (*models.User, error)
Find() ([]*models.User, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.User, err error)
FindInBatches(result *[]*models.User, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.User) (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) IUserDo
Assign(attrs ...field.AssignExpr) IUserDo
Joins(fields ...field.RelationField) IUserDo
Preload(fields ...field.RelationField) IUserDo
FirstOrInit() (*models.User, error)
FirstOrCreate() (*models.User, error)
FindByPage(offset int, limit int) (result []*models.User, 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) IUserDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (u userDo) Debug() IUserDo {
return u.withDO(u.DO.Debug())
}
func (u userDo) WithContext(ctx context.Context) IUserDo {
return u.withDO(u.DO.WithContext(ctx))
}
func (u userDo) ReadDB() IUserDo {
return u.Clauses(dbresolver.Read)
}
func (u userDo) WriteDB() IUserDo {
return u.Clauses(dbresolver.Write)
}
func (u userDo) Session(config *gorm.Session) IUserDo {
return u.withDO(u.DO.Session(config))
}
func (u userDo) Clauses(conds ...clause.Expression) IUserDo {
return u.withDO(u.DO.Clauses(conds...))
}
func (u userDo) Returning(value interface{}, columns ...string) IUserDo {
return u.withDO(u.DO.Returning(value, columns...))
}
func (u userDo) Not(conds ...gen.Condition) IUserDo {
return u.withDO(u.DO.Not(conds...))
}
func (u userDo) Or(conds ...gen.Condition) IUserDo {
return u.withDO(u.DO.Or(conds...))
}
func (u userDo) Select(conds ...field.Expr) IUserDo {
return u.withDO(u.DO.Select(conds...))
}
func (u userDo) Where(conds ...gen.Condition) IUserDo {
return u.withDO(u.DO.Where(conds...))
}
func (u userDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IUserDo {
return u.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func (u userDo) Order(conds ...field.Expr) IUserDo {
return u.withDO(u.DO.Order(conds...))
}
func (u userDo) Distinct(cols ...field.Expr) IUserDo {
return u.withDO(u.DO.Distinct(cols...))
}
func (u userDo) Omit(cols ...field.Expr) IUserDo {
return u.withDO(u.DO.Omit(cols...))
}
func (u userDo) Join(table schema.Tabler, on ...field.Expr) IUserDo {
return u.withDO(u.DO.Join(table, on...))
}
func (u userDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo {
return u.withDO(u.DO.LeftJoin(table, on...))
}
func (u userDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserDo {
return u.withDO(u.DO.RightJoin(table, on...))
}
func (u userDo) Group(cols ...field.Expr) IUserDo {
return u.withDO(u.DO.Group(cols...))
}
func (u userDo) Having(conds ...gen.Condition) IUserDo {
return u.withDO(u.DO.Having(conds...))
}
func (u userDo) Limit(limit int) IUserDo {
return u.withDO(u.DO.Limit(limit))
}
func (u userDo) Offset(offset int) IUserDo {
return u.withDO(u.DO.Offset(offset))
}
func (u userDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo {
return u.withDO(u.DO.Scopes(funcs...))
}
func (u userDo) Unscoped() IUserDo {
return u.withDO(u.DO.Unscoped())
}
func (u userDo) Create(values ...*models.User) error {
if len(values) == 0 {
return nil
}
return u.DO.Create(values)
}
func (u userDo) CreateInBatches(values []*models.User, batchSize int) error {
return u.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 (u userDo) Save(values ...*models.User) error {
if len(values) == 0 {
return nil
}
return u.DO.Save(values)
}
func (u userDo) First() (*models.User, error) {
if result, err := u.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.User), nil
}
}
func (u userDo) Take() (*models.User, error) {
if result, err := u.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.User), nil
}
}
func (u userDo) Last() (*models.User, error) {
if result, err := u.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.User), nil
}
}
func (u userDo) Find() ([]*models.User, error) {
result, err := u.DO.Find()
return result.([]*models.User), err
}
func (u userDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.User, err error) {
buf := make([]*models.User, 0, batchSize)
err = u.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 (u userDo) FindInBatches(result *[]*models.User, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return u.DO.FindInBatches(result, batchSize, fc)
}
func (u userDo) Attrs(attrs ...field.AssignExpr) IUserDo {
return u.withDO(u.DO.Attrs(attrs...))
}
func (u userDo) Assign(attrs ...field.AssignExpr) IUserDo {
return u.withDO(u.DO.Assign(attrs...))
}
func (u userDo) Joins(fields ...field.RelationField) IUserDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Joins(_f))
}
return &u
}
func (u userDo) Preload(fields ...field.RelationField) IUserDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Preload(_f))
}
return &u
}
func (u userDo) FirstOrInit() (*models.User, error) {
if result, err := u.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.User), nil
}
}
func (u userDo) FirstOrCreate() (*models.User, error) {
if result, err := u.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.User), nil
}
}
func (u userDo) FindByPage(offset int, limit int) (result []*models.User, count int64, err error) {
result, err = u.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 = u.Offset(-1).Limit(-1).Count()
return
}
func (u userDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = u.Count()
if err != nil {
return
}
err = u.Offset(offset).Limit(limit).Scan(result)
return
}
func (u userDo) Scan(result interface{}) (err error) {
return u.DO.Scan(result)
}
func (u userDo) Delete(models ...*models.User) (result gen.ResultInfo, err error) {
return u.DO.Delete(models)
}
func (u *userDo) withDO(do gen.Dao) *userDo {
u.DO = *do.(*gen.DO)
return u
}