// 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" "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" "gorm.io/gen" "gorm.io/gen/field" "gorm.io/plugin/dbresolver" "github.com/rulego/gflow-engine/model" ) func newWfInstance(db *gorm.DB, opts ...gen.DOOption) wfInstance { _wfInstance := wfInstance{} _wfInstance.wfInstanceDo.UseDB(db, opts...) _wfInstance.wfInstanceDo.UseModel(&model.WfInstance{}) tableName := _wfInstance.wfInstanceDo.TableName() _wfInstance.ALL = field.NewAsterisk(tableName) _wfInstance.ID = field.NewString(tableName, "id") _wfInstance.ProcessID = field.NewString(tableName, "process_id") _wfInstance.BusinessKey = field.NewString(tableName, "business_key") _wfInstance.Name = field.NewString(tableName, "name") _wfInstance.StartUserID = field.NewString(tableName, "start_user_id") _wfInstance.Status = field.NewString(tableName, "status") _wfInstance.Variables = field.NewString(tableName, "variables") _wfInstance.CurrentActivity = field.NewString(tableName, "current_activity") _wfInstance.Priority = field.NewInt32(tableName, "priority") _wfInstance.ParentID = field.NewString(tableName, "parent_id") _wfInstance.TenantID = field.NewString(tableName, "tenant_id") _wfInstance.CreatedBy = field.NewString(tableName, "created_by") _wfInstance.CreatedAt = field.NewTime(tableName, "created_at") _wfInstance.UpdatedBy = field.NewString(tableName, "updated_by") _wfInstance.UpdatedAt = field.NewTime(tableName, "updated_at") _wfInstance.EndReason = field.NewString(tableName, "end_reason") _wfInstance.Duration = field.NewInt64(tableName, "duration") _wfInstance.EndedAt = field.NewTime(tableName, "ended_at") _wfInstance.Process = wfInstanceBelongsToProcess{ db: db.Session(&gorm.Session{}), RelationField: field.NewRelation("Process", "model.WfProcess"), } _wfInstance.fillFieldMap() return _wfInstance } type wfInstance struct { wfInstanceDo ALL field.Asterisk ID field.String // 主键UUID ProcessID field.String // 流程定义ID BusinessKey field.String // 业务键,业务系统唯一编号 Name field.String // 实例名称 StartUserID field.String // 流程发起人用户ID;系统触发时为空字符串 Status field.String // 生命周期状态:draft / active / completed / suspended / terminated / cancelled / failed Variables field.String // 流程变量 CurrentActivity field.String // 当前运行到的节点定义ID Priority field.Int32 // 优先级(数值越大越优先) ParentID field.String // 父流程实例ID(用于子流程) TenantID field.String // 租户ID(SaaS 多租户) CreatedBy field.String // 发起人用户ID CreatedAt field.Time // 实例创建时间 UpdatedBy field.String // 最后更新人 UpdatedAt field.Time // 最后更新时间 EndReason field.String // 完成/终止原因(包含错误信息) Duration field.Int64 EndedAt field.Time Process wfInstanceBelongsToProcess fieldMap map[string]field.Expr } func (w wfInstance) Table(newTableName string) *wfInstance { w.wfInstanceDo.UseTable(newTableName) return w.updateTableName(newTableName) } func (w wfInstance) As(alias string) *wfInstance { w.wfInstanceDo.DO = *(w.wfInstanceDo.As(alias).(*gen.DO)) return w.updateTableName(alias) } func (w *wfInstance) updateTableName(table string) *wfInstance { w.ALL = field.NewAsterisk(table) w.ID = field.NewString(table, "id") w.ProcessID = field.NewString(table, "process_id") w.BusinessKey = field.NewString(table, "business_key") w.Name = field.NewString(table, "name") w.StartUserID = field.NewString(table, "start_user_id") w.Status = field.NewString(table, "status") w.Variables = field.NewString(table, "variables") w.CurrentActivity = field.NewString(table, "current_activity") w.Priority = field.NewInt32(table, "priority") w.ParentID = field.NewString(table, "parent_id") w.TenantID = field.NewString(table, "tenant_id") w.CreatedBy = field.NewString(table, "created_by") w.CreatedAt = field.NewTime(table, "created_at") w.UpdatedBy = field.NewString(table, "updated_by") w.UpdatedAt = field.NewTime(table, "updated_at") w.EndReason = field.NewString(table, "end_reason") w.Duration = field.NewInt64(table, "duration") w.EndedAt = field.NewTime(table, "ended_at") w.fillFieldMap() return w } func (w *wfInstance) GetFieldByName(fieldName string) (field.OrderExpr, bool) { _f, ok := w.fieldMap[fieldName] if !ok || _f == nil { return nil, false } _oe, ok := _f.(field.OrderExpr) return _oe, ok } func (w *wfInstance) fillFieldMap() { w.fieldMap = make(map[string]field.Expr, 19) w.fieldMap["id"] = w.ID w.fieldMap["process_id"] = w.ProcessID w.fieldMap["business_key"] = w.BusinessKey w.fieldMap["name"] = w.Name w.fieldMap["start_user_id"] = w.StartUserID w.fieldMap["status"] = w.Status w.fieldMap["variables"] = w.Variables w.fieldMap["current_activity"] = w.CurrentActivity w.fieldMap["priority"] = w.Priority w.fieldMap["parent_id"] = w.ParentID w.fieldMap["tenant_id"] = w.TenantID w.fieldMap["created_by"] = w.CreatedBy w.fieldMap["created_at"] = w.CreatedAt w.fieldMap["updated_by"] = w.UpdatedBy w.fieldMap["updated_at"] = w.UpdatedAt w.fieldMap["end_reason"] = w.EndReason w.fieldMap["duration"] = w.Duration w.fieldMap["ended_at"] = w.EndedAt } func (w wfInstance) clone(db *gorm.DB) wfInstance { w.wfInstanceDo.ReplaceConnPool(db.Statement.ConnPool) w.Process.db = db.Session(&gorm.Session{Initialized: true}) w.Process.db.Statement.ConnPool = db.Statement.ConnPool return w } func (w wfInstance) replaceDB(db *gorm.DB) wfInstance { w.wfInstanceDo.ReplaceDB(db) w.Process.db = db.Session(&gorm.Session{}) return w } type wfInstanceBelongsToProcess struct { db *gorm.DB field.RelationField } func (a wfInstanceBelongsToProcess) Where(conds ...field.Expr) *wfInstanceBelongsToProcess { if len(conds) == 0 { return &a } exprs := make([]clause.Expression, 0, len(conds)) for _, cond := range conds { exprs = append(exprs, cond.BeCond().(clause.Expression)) } a.db = a.db.Clauses(clause.Where{Exprs: exprs}) return &a } func (a wfInstanceBelongsToProcess) WithContext(ctx context.Context) *wfInstanceBelongsToProcess { a.db = a.db.WithContext(ctx) return &a } func (a wfInstanceBelongsToProcess) Session(session *gorm.Session) *wfInstanceBelongsToProcess { a.db = a.db.Session(session) return &a } func (a wfInstanceBelongsToProcess) Model(m *model.WfInstance) *wfInstanceBelongsToProcessTx { return &wfInstanceBelongsToProcessTx{a.db.Model(m).Association(a.Name())} } func (a wfInstanceBelongsToProcess) Unscoped() *wfInstanceBelongsToProcess { a.db = a.db.Unscoped() return &a } type wfInstanceBelongsToProcessTx struct{ tx *gorm.Association } func (a wfInstanceBelongsToProcessTx) Find() (result *model.WfProcess, err error) { return result, a.tx.Find(&result) } func (a wfInstanceBelongsToProcessTx) Append(values ...*model.WfProcess) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Append(targetValues...) } func (a wfInstanceBelongsToProcessTx) Replace(values ...*model.WfProcess) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Replace(targetValues...) } func (a wfInstanceBelongsToProcessTx) Delete(values ...*model.WfProcess) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Delete(targetValues...) } func (a wfInstanceBelongsToProcessTx) Clear() error { return a.tx.Clear() } func (a wfInstanceBelongsToProcessTx) Count() int64 { return a.tx.Count() } func (a wfInstanceBelongsToProcessTx) Unscoped() *wfInstanceBelongsToProcessTx { a.tx = a.tx.Unscoped() return &a } type wfInstanceDo struct{ gen.DO } type IWfInstanceDo interface { gen.SubQuery Debug() IWfInstanceDo WithContext(ctx context.Context) IWfInstanceDo WithResult(fc func(tx gen.Dao)) gen.ResultInfo ReplaceDB(db *gorm.DB) ReadDB() IWfInstanceDo WriteDB() IWfInstanceDo As(alias string) gen.Dao Session(config *gorm.Session) IWfInstanceDo Columns(cols ...field.Expr) gen.Columns Clauses(conds ...clause.Expression) IWfInstanceDo Not(conds ...gen.Condition) IWfInstanceDo Or(conds ...gen.Condition) IWfInstanceDo Select(conds ...field.Expr) IWfInstanceDo Where(conds ...gen.Condition) IWfInstanceDo Order(conds ...field.Expr) IWfInstanceDo Distinct(cols ...field.Expr) IWfInstanceDo Omit(cols ...field.Expr) IWfInstanceDo Join(table schema.Tabler, on ...field.Expr) IWfInstanceDo LeftJoin(table schema.Tabler, on ...field.Expr) IWfInstanceDo RightJoin(table schema.Tabler, on ...field.Expr) IWfInstanceDo Group(cols ...field.Expr) IWfInstanceDo Having(conds ...gen.Condition) IWfInstanceDo Limit(limit int) IWfInstanceDo Offset(offset int) IWfInstanceDo Count() (count int64, err error) Scopes(funcs ...func(gen.Dao) gen.Dao) IWfInstanceDo Unscoped() IWfInstanceDo Create(values ...*model.WfInstance) error CreateInBatches(values []*model.WfInstance, batchSize int) error Save(values ...*model.WfInstance) error First() (*model.WfInstance, error) Take() (*model.WfInstance, error) Last() (*model.WfInstance, error) Find() ([]*model.WfInstance, error) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.WfInstance, err error) FindInBatches(result *[]*model.WfInstance, batchSize int, fc func(tx gen.Dao, batch int) error) error Pluck(column field.Expr, dest interface{}) error Delete(...*model.WfInstance) (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) IWfInstanceDo Assign(attrs ...field.AssignExpr) IWfInstanceDo Joins(fields ...field.RelationField) IWfInstanceDo Preload(fields ...field.RelationField) IWfInstanceDo FirstOrInit() (*model.WfInstance, error) FirstOrCreate() (*model.WfInstance, error) FindByPage(offset int, limit int) (result []*model.WfInstance, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) Rows() (*sql.Rows, error) Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IWfInstanceDo UnderlyingDB() *gorm.DB schema.Tabler } func (w wfInstanceDo) Debug() IWfInstanceDo { return w.withDO(w.DO.Debug()) } func (w wfInstanceDo) WithContext(ctx context.Context) IWfInstanceDo { return w.withDO(w.DO.WithContext(ctx)) } func (w wfInstanceDo) ReadDB() IWfInstanceDo { return w.Clauses(dbresolver.Read) } func (w wfInstanceDo) WriteDB() IWfInstanceDo { return w.Clauses(dbresolver.Write) } func (w wfInstanceDo) Session(config *gorm.Session) IWfInstanceDo { return w.withDO(w.DO.Session(config)) } func (w wfInstanceDo) Clauses(conds ...clause.Expression) IWfInstanceDo { return w.withDO(w.DO.Clauses(conds...)) } func (w wfInstanceDo) Returning(value interface{}, columns ...string) IWfInstanceDo { return w.withDO(w.DO.Returning(value, columns...)) } func (w wfInstanceDo) Not(conds ...gen.Condition) IWfInstanceDo { return w.withDO(w.DO.Not(conds...)) } func (w wfInstanceDo) Or(conds ...gen.Condition) IWfInstanceDo { return w.withDO(w.DO.Or(conds...)) } func (w wfInstanceDo) Select(conds ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.Select(conds...)) } func (w wfInstanceDo) Where(conds ...gen.Condition) IWfInstanceDo { return w.withDO(w.DO.Where(conds...)) } func (w wfInstanceDo) Order(conds ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.Order(conds...)) } func (w wfInstanceDo) Distinct(cols ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.Distinct(cols...)) } func (w wfInstanceDo) Omit(cols ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.Omit(cols...)) } func (w wfInstanceDo) Join(table schema.Tabler, on ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.Join(table, on...)) } func (w wfInstanceDo) LeftJoin(table schema.Tabler, on ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.LeftJoin(table, on...)) } func (w wfInstanceDo) RightJoin(table schema.Tabler, on ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.RightJoin(table, on...)) } func (w wfInstanceDo) Group(cols ...field.Expr) IWfInstanceDo { return w.withDO(w.DO.Group(cols...)) } func (w wfInstanceDo) Having(conds ...gen.Condition) IWfInstanceDo { return w.withDO(w.DO.Having(conds...)) } func (w wfInstanceDo) Limit(limit int) IWfInstanceDo { return w.withDO(w.DO.Limit(limit)) } func (w wfInstanceDo) Offset(offset int) IWfInstanceDo { return w.withDO(w.DO.Offset(offset)) } func (w wfInstanceDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWfInstanceDo { return w.withDO(w.DO.Scopes(funcs...)) } func (w wfInstanceDo) Unscoped() IWfInstanceDo { return w.withDO(w.DO.Unscoped()) } func (w wfInstanceDo) Create(values ...*model.WfInstance) error { if len(values) == 0 { return nil } return w.DO.Create(values) } func (w wfInstanceDo) CreateInBatches(values []*model.WfInstance, batchSize int) error { return w.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 (w wfInstanceDo) Save(values ...*model.WfInstance) error { if len(values) == 0 { return nil } return w.DO.Save(values) } func (w wfInstanceDo) First() (*model.WfInstance, error) { if result, err := w.DO.First(); err != nil { return nil, err } else { return result.(*model.WfInstance), nil } } func (w wfInstanceDo) Take() (*model.WfInstance, error) { if result, err := w.DO.Take(); err != nil { return nil, err } else { return result.(*model.WfInstance), nil } } func (w wfInstanceDo) Last() (*model.WfInstance, error) { if result, err := w.DO.Last(); err != nil { return nil, err } else { return result.(*model.WfInstance), nil } } func (w wfInstanceDo) Find() ([]*model.WfInstance, error) { result, err := w.DO.Find() return result.([]*model.WfInstance), err } func (w wfInstanceDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.WfInstance, err error) { buf := make([]*model.WfInstance, 0, batchSize) err = w.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 (w wfInstanceDo) FindInBatches(result *[]*model.WfInstance, batchSize int, fc func(tx gen.Dao, batch int) error) error { return w.DO.FindInBatches(result, batchSize, fc) } func (w wfInstanceDo) Attrs(attrs ...field.AssignExpr) IWfInstanceDo { return w.withDO(w.DO.Attrs(attrs...)) } func (w wfInstanceDo) Assign(attrs ...field.AssignExpr) IWfInstanceDo { return w.withDO(w.DO.Assign(attrs...)) } func (w wfInstanceDo) Joins(fields ...field.RelationField) IWfInstanceDo { for _, _f := range fields { w = *w.withDO(w.DO.Joins(_f)) } return &w } func (w wfInstanceDo) Preload(fields ...field.RelationField) IWfInstanceDo { for _, _f := range fields { w = *w.withDO(w.DO.Preload(_f)) } return &w } func (w wfInstanceDo) FirstOrInit() (*model.WfInstance, error) { if result, err := w.DO.FirstOrInit(); err != nil { return nil, err } else { return result.(*model.WfInstance), nil } } func (w wfInstanceDo) FirstOrCreate() (*model.WfInstance, error) { if result, err := w.DO.FirstOrCreate(); err != nil { return nil, err } else { return result.(*model.WfInstance), nil } } func (w wfInstanceDo) FindByPage(offset int, limit int) (result []*model.WfInstance, count int64, err error) { result, err = w.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 = w.Offset(-1).Limit(-1).Count() return } func (w wfInstanceDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { count, err = w.Count() if err != nil { return } err = w.Offset(offset).Limit(limit).Scan(result) return } func (w wfInstanceDo) Scan(result interface{}) (err error) { return w.DO.Scan(result) } func (w wfInstanceDo) Delete(models ...*model.WfInstance) (result gen.ResultInfo, err error) { return w.DO.Delete(models) } func (w *wfInstanceDo) withDO(do gen.Dao) *wfInstanceDo { w.DO = *do.(*gen.DO) return w }