123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- 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"
- "wechat-api/database/dao/wechat/model"
- )
- func newLabelRelationship(db *gorm.DB, opts ...gen.DOOption) labelRelationship {
- _labelRelationship := labelRelationship{}
- _labelRelationship.labelRelationshipDo.UseDB(db, opts...)
- _labelRelationship.labelRelationshipDo.UseModel(&model.LabelRelationship{})
- tableName := _labelRelationship.labelRelationshipDo.TableName()
- _labelRelationship.ALL = field.NewAsterisk(tableName)
- _labelRelationship.ID = field.NewInt64(tableName, "id")
- _labelRelationship.CreatedAt = field.NewTime(tableName, "created_at")
- _labelRelationship.UpdatedAt = field.NewTime(tableName, "updated_at")
- _labelRelationship.Status = field.NewInt64(tableName, "status")
- _labelRelationship.DeletedAt = field.NewField(tableName, "deleted_at")
- _labelRelationship.LabelID = field.NewInt64(tableName, "label_id")
- _labelRelationship.ContactID = field.NewInt64(tableName, "contact_id")
- _labelRelationship.OrganizationID = field.NewInt64(tableName, "organization_id")
- _labelRelationship.fillFieldMap()
- return _labelRelationship
- }
- type labelRelationship struct {
- labelRelationshipDo
- ALL field.Asterisk
- ID field.Int64
- CreatedAt field.Time
- UpdatedAt field.Time
- Status field.Int64
- DeletedAt field.Field
- LabelID field.Int64
- ContactID field.Int64
- OrganizationID field.Int64
- fieldMap map[string]field.Expr
- }
- func (l labelRelationship) Table(newTableName string) *labelRelationship {
- l.labelRelationshipDo.UseTable(newTableName)
- return l.updateTableName(newTableName)
- }
- func (l labelRelationship) As(alias string) *labelRelationship {
- l.labelRelationshipDo.DO = *(l.labelRelationshipDo.As(alias).(*gen.DO))
- return l.updateTableName(alias)
- }
- func (l *labelRelationship) updateTableName(table string) *labelRelationship {
- l.ALL = field.NewAsterisk(table)
- l.ID = field.NewInt64(table, "id")
- l.CreatedAt = field.NewTime(table, "created_at")
- l.UpdatedAt = field.NewTime(table, "updated_at")
- l.Status = field.NewInt64(table, "status")
- l.DeletedAt = field.NewField(table, "deleted_at")
- l.LabelID = field.NewInt64(table, "label_id")
- l.ContactID = field.NewInt64(table, "contact_id")
- l.OrganizationID = field.NewInt64(table, "organization_id")
- l.fillFieldMap()
- return l
- }
- func (l *labelRelationship) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
- _f, ok := l.fieldMap[fieldName]
- if !ok || _f == nil {
- return nil, false
- }
- _oe, ok := _f.(field.OrderExpr)
- return _oe, ok
- }
- func (l *labelRelationship) fillFieldMap() {
- l.fieldMap = make(map[string]field.Expr, 8)
- l.fieldMap["id"] = l.ID
- l.fieldMap["created_at"] = l.CreatedAt
- l.fieldMap["updated_at"] = l.UpdatedAt
- l.fieldMap["status"] = l.Status
- l.fieldMap["deleted_at"] = l.DeletedAt
- l.fieldMap["label_id"] = l.LabelID
- l.fieldMap["contact_id"] = l.ContactID
- l.fieldMap["organization_id"] = l.OrganizationID
- }
- func (l labelRelationship) clone(db *gorm.DB) labelRelationship {
- l.labelRelationshipDo.ReplaceConnPool(db.Statement.ConnPool)
- return l
- }
- func (l labelRelationship) replaceDB(db *gorm.DB) labelRelationship {
- l.labelRelationshipDo.ReplaceDB(db)
- return l
- }
- type labelRelationshipDo struct{ gen.DO }
- type ILabelRelationshipDo interface {
- gen.SubQuery
- Debug() ILabelRelationshipDo
- WithContext(ctx context.Context) ILabelRelationshipDo
- WithResult(fc func(tx gen.Dao)) gen.ResultInfo
- ReplaceDB(db *gorm.DB)
- ReadDB() ILabelRelationshipDo
- WriteDB() ILabelRelationshipDo
- As(alias string) gen.Dao
- Session(config *gorm.Session) ILabelRelationshipDo
- Columns(cols ...field.Expr) gen.Columns
- Clauses(conds ...clause.Expression) ILabelRelationshipDo
- Not(conds ...gen.Condition) ILabelRelationshipDo
- Or(conds ...gen.Condition) ILabelRelationshipDo
- Select(conds ...field.Expr) ILabelRelationshipDo
- Where(conds ...gen.Condition) ILabelRelationshipDo
- Order(conds ...field.Expr) ILabelRelationshipDo
- Distinct(cols ...field.Expr) ILabelRelationshipDo
- Omit(cols ...field.Expr) ILabelRelationshipDo
- Join(table schema.Tabler, on ...field.Expr) ILabelRelationshipDo
- LeftJoin(table schema.Tabler, on ...field.Expr) ILabelRelationshipDo
- RightJoin(table schema.Tabler, on ...field.Expr) ILabelRelationshipDo
- Group(cols ...field.Expr) ILabelRelationshipDo
- Having(conds ...gen.Condition) ILabelRelationshipDo
- Limit(limit int) ILabelRelationshipDo
- Offset(offset int) ILabelRelationshipDo
- Count() (count int64, err error)
- Scopes(funcs ...func(gen.Dao) gen.Dao) ILabelRelationshipDo
- Unscoped() ILabelRelationshipDo
- Create(values ...*model.LabelRelationship) error
- CreateInBatches(values []*model.LabelRelationship, batchSize int) error
- Save(values ...*model.LabelRelationship) error
- First() (*model.LabelRelationship, error)
- Take() (*model.LabelRelationship, error)
- Last() (*model.LabelRelationship, error)
- Find() ([]*model.LabelRelationship, error)
- FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.LabelRelationship, err error)
- FindInBatches(result *[]*model.LabelRelationship, batchSize int, fc func(tx gen.Dao, batch int) error) error
- Pluck(column field.Expr, dest interface{}) error
- Delete(...*model.LabelRelationship) (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) ILabelRelationshipDo
- Assign(attrs ...field.AssignExpr) ILabelRelationshipDo
- Joins(fields ...field.RelationField) ILabelRelationshipDo
- Preload(fields ...field.RelationField) ILabelRelationshipDo
- FirstOrInit() (*model.LabelRelationship, error)
- FirstOrCreate() (*model.LabelRelationship, error)
- FindByPage(offset int, limit int) (result []*model.LabelRelationship, 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) ILabelRelationshipDo
- UnderlyingDB() *gorm.DB
- schema.Tabler
- }
- func (l labelRelationshipDo) Debug() ILabelRelationshipDo {
- return l.withDO(l.DO.Debug())
- }
- func (l labelRelationshipDo) WithContext(ctx context.Context) ILabelRelationshipDo {
- return l.withDO(l.DO.WithContext(ctx))
- }
- func (l labelRelationshipDo) ReadDB() ILabelRelationshipDo {
- return l.Clauses(dbresolver.Read)
- }
- func (l labelRelationshipDo) WriteDB() ILabelRelationshipDo {
- return l.Clauses(dbresolver.Write)
- }
- func (l labelRelationshipDo) Session(config *gorm.Session) ILabelRelationshipDo {
- return l.withDO(l.DO.Session(config))
- }
- func (l labelRelationshipDo) Clauses(conds ...clause.Expression) ILabelRelationshipDo {
- return l.withDO(l.DO.Clauses(conds...))
- }
- func (l labelRelationshipDo) Returning(value interface{}, columns ...string) ILabelRelationshipDo {
- return l.withDO(l.DO.Returning(value, columns...))
- }
- func (l labelRelationshipDo) Not(conds ...gen.Condition) ILabelRelationshipDo {
- return l.withDO(l.DO.Not(conds...))
- }
- func (l labelRelationshipDo) Or(conds ...gen.Condition) ILabelRelationshipDo {
- return l.withDO(l.DO.Or(conds...))
- }
- func (l labelRelationshipDo) Select(conds ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.Select(conds...))
- }
- func (l labelRelationshipDo) Where(conds ...gen.Condition) ILabelRelationshipDo {
- return l.withDO(l.DO.Where(conds...))
- }
- func (l labelRelationshipDo) Order(conds ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.Order(conds...))
- }
- func (l labelRelationshipDo) Distinct(cols ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.Distinct(cols...))
- }
- func (l labelRelationshipDo) Omit(cols ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.Omit(cols...))
- }
- func (l labelRelationshipDo) Join(table schema.Tabler, on ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.Join(table, on...))
- }
- func (l labelRelationshipDo) LeftJoin(table schema.Tabler, on ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.LeftJoin(table, on...))
- }
- func (l labelRelationshipDo) RightJoin(table schema.Tabler, on ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.RightJoin(table, on...))
- }
- func (l labelRelationshipDo) Group(cols ...field.Expr) ILabelRelationshipDo {
- return l.withDO(l.DO.Group(cols...))
- }
- func (l labelRelationshipDo) Having(conds ...gen.Condition) ILabelRelationshipDo {
- return l.withDO(l.DO.Having(conds...))
- }
- func (l labelRelationshipDo) Limit(limit int) ILabelRelationshipDo {
- return l.withDO(l.DO.Limit(limit))
- }
- func (l labelRelationshipDo) Offset(offset int) ILabelRelationshipDo {
- return l.withDO(l.DO.Offset(offset))
- }
- func (l labelRelationshipDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ILabelRelationshipDo {
- return l.withDO(l.DO.Scopes(funcs...))
- }
- func (l labelRelationshipDo) Unscoped() ILabelRelationshipDo {
- return l.withDO(l.DO.Unscoped())
- }
- func (l labelRelationshipDo) Create(values ...*model.LabelRelationship) error {
- if len(values) == 0 {
- return nil
- }
- return l.DO.Create(values)
- }
- func (l labelRelationshipDo) CreateInBatches(values []*model.LabelRelationship, batchSize int) error {
- return l.DO.CreateInBatches(values, batchSize)
- }
- func (l labelRelationshipDo) Save(values ...*model.LabelRelationship) error {
- if len(values) == 0 {
- return nil
- }
- return l.DO.Save(values)
- }
- func (l labelRelationshipDo) First() (*model.LabelRelationship, error) {
- if result, err := l.DO.First(); err != nil {
- return nil, err
- } else {
- return result.(*model.LabelRelationship), nil
- }
- }
- func (l labelRelationshipDo) Take() (*model.LabelRelationship, error) {
- if result, err := l.DO.Take(); err != nil {
- return nil, err
- } else {
- return result.(*model.LabelRelationship), nil
- }
- }
- func (l labelRelationshipDo) Last() (*model.LabelRelationship, error) {
- if result, err := l.DO.Last(); err != nil {
- return nil, err
- } else {
- return result.(*model.LabelRelationship), nil
- }
- }
- func (l labelRelationshipDo) Find() ([]*model.LabelRelationship, error) {
- result, err := l.DO.Find()
- return result.([]*model.LabelRelationship), err
- }
- func (l labelRelationshipDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.LabelRelationship, err error) {
- buf := make([]*model.LabelRelationship, 0, batchSize)
- err = l.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 (l labelRelationshipDo) FindInBatches(result *[]*model.LabelRelationship, batchSize int, fc func(tx gen.Dao, batch int) error) error {
- return l.DO.FindInBatches(result, batchSize, fc)
- }
- func (l labelRelationshipDo) Attrs(attrs ...field.AssignExpr) ILabelRelationshipDo {
- return l.withDO(l.DO.Attrs(attrs...))
- }
- func (l labelRelationshipDo) Assign(attrs ...field.AssignExpr) ILabelRelationshipDo {
- return l.withDO(l.DO.Assign(attrs...))
- }
- func (l labelRelationshipDo) Joins(fields ...field.RelationField) ILabelRelationshipDo {
- for _, _f := range fields {
- l = *l.withDO(l.DO.Joins(_f))
- }
- return &l
- }
- func (l labelRelationshipDo) Preload(fields ...field.RelationField) ILabelRelationshipDo {
- for _, _f := range fields {
- l = *l.withDO(l.DO.Preload(_f))
- }
- return &l
- }
- func (l labelRelationshipDo) FirstOrInit() (*model.LabelRelationship, error) {
- if result, err := l.DO.FirstOrInit(); err != nil {
- return nil, err
- } else {
- return result.(*model.LabelRelationship), nil
- }
- }
- func (l labelRelationshipDo) FirstOrCreate() (*model.LabelRelationship, error) {
- if result, err := l.DO.FirstOrCreate(); err != nil {
- return nil, err
- } else {
- return result.(*model.LabelRelationship), nil
- }
- }
- func (l labelRelationshipDo) FindByPage(offset int, limit int) (result []*model.LabelRelationship, count int64, err error) {
- result, err = l.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 = l.Offset(-1).Limit(-1).Count()
- return
- }
- func (l labelRelationshipDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
- count, err = l.Count()
- if err != nil {
- return
- }
- err = l.Offset(offset).Limit(limit).Scan(result)
- return
- }
- func (l labelRelationshipDo) Scan(result interface{}) (err error) {
- return l.DO.Scan(result)
- }
- func (l labelRelationshipDo) Delete(models ...*model.LabelRelationship) (result gen.ResultInfo, err error) {
- return l.DO.Delete(models)
- }
- func (l *labelRelationshipDo) withDO(do gen.Dao) *labelRelationshipDo {
- l.DO = *do.(*gen.DO)
- return l
- }
|