feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,167 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"encoding/json"
"time"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/logs"
)
type RunRecordDAO struct {
db *gorm.DB
query *query.Query
idGen idgen.IDGenerator
}
func NewRunRecordDAO(db *gorm.DB, idGen idgen.IDGenerator) *RunRecordDAO {
return &RunRecordDAO{
db: db,
idGen: idGen,
query: query.Use(db),
}
}
func (dao *RunRecordDAO) Create(ctx context.Context, runMeta *entity.AgentRunMeta) (*entity.RunRecordMeta, error) {
createPO, err := dao.buildCreatePO(ctx, runMeta)
if err != nil {
return nil, err
}
createErr := dao.query.RunRecord.WithContext(ctx).Create(createPO)
if createErr != nil {
return nil, createErr
}
return dao.buildPo2Do(createPO), nil
}
func (dao *RunRecordDAO) GetByID(ctx context.Context, id int64) (*model.RunRecord, error) {
return dao.query.RunRecord.WithContext(ctx).Where(dao.query.RunRecord.ID.Eq(id)).First()
}
func (dao *RunRecordDAO) UpdateByID(ctx context.Context, id int64, updateMeta *entity.UpdateMeta) error {
po := &model.RunRecord{
ID: id,
}
if updateMeta.Status != "" {
po.Status = string(updateMeta.Status)
}
if updateMeta.LastError != nil {
errString, err := json.Marshal(updateMeta.LastError)
if err != nil {
return err
}
po.LastError = string(errString)
}
if updateMeta.CompletedAt != 0 {
po.CompletedAt = updateMeta.CompletedAt
}
if updateMeta.FailedAt != 0 {
po.FailedAt = updateMeta.FailedAt
}
if updateMeta.Usage != nil {
po.Usage = updateMeta.Usage
}
po.UpdatedAt = time.Now().UnixMilli()
_, err := dao.query.RunRecord.WithContext(ctx).Where(dao.query.RunRecord.ID.Eq(id)).Updates(po)
return err
}
func (dao *RunRecordDAO) Delete(ctx context.Context, id []int64) error {
_, err := dao.query.RunRecord.WithContext(ctx).Where(dao.query.RunRecord.ID.In(id...)).UpdateColumns(map[string]interface{}{
"updated_at": time.Now().UnixMilli(),
"status": entity.RunStatusDeleted,
})
return err
}
func (dao *RunRecordDAO) List(ctx context.Context, conversationID int64, sectionID int64, limit int32) ([]*model.RunRecord, error) {
logs.CtxInfof(ctx, "list run record req:%v, sectionID:%v, limit:%v", conversationID, sectionID, limit)
m := dao.query.RunRecord
do := m.WithContext(ctx).Where(m.ConversationID.Eq(conversationID)).Debug().Where(m.Status.NotIn(string(entity.RunStatusDeleted)))
if sectionID > 0 {
do = do.Where(m.SectionID.Eq(sectionID))
}
if limit > 0 {
do = do.Limit(int(limit))
}
runRecords, err := do.Order(m.CreatedAt.Desc()).Find()
return runRecords, err
}
func (dao *RunRecordDAO) buildCreatePO(ctx context.Context, runMeta *entity.AgentRunMeta) (*model.RunRecord, error) {
runID, err := dao.idGen.GenID(ctx)
if err != nil {
return nil, err
}
reqOrigin, err := json.Marshal(runMeta)
if err != nil {
return nil, err
}
timeNow := time.Now().UnixMilli()
return &model.RunRecord{
ID: runID,
ConversationID: runMeta.ConversationID,
SectionID: runMeta.SectionID,
AgentID: runMeta.AgentID,
Status: string(entity.RunStatusCreated),
ChatRequest: string(reqOrigin),
UserID: runMeta.UserID,
CreatedAt: timeNow,
}, nil
}
func (dao *RunRecordDAO) buildPo2Do(po *model.RunRecord) *entity.RunRecordMeta {
runMeta := &entity.RunRecordMeta{
ID: po.ID,
ConversationID: po.ConversationID,
SectionID: po.SectionID,
AgentID: po.AgentID,
Status: entity.RunStatus(po.Status),
Ext: po.Ext,
CreatedAt: po.CreatedAt,
UpdatedAt: po.UpdatedAt,
CompletedAt: po.CompletedAt,
FailedAt: po.FailedAt,
Usage: po.Usage,
}
return runMeta
}

View File

@@ -0,0 +1,34 @@
// 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 model
import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
const TableNameRunRecord = "run_record"
// RunRecord 执行记录表
type RunRecord struct {
ID int64 `gorm:"column:id;primaryKey;comment:主键ID" json:"id"` // 主键ID
ConversationID int64 `gorm:"column:conversation_id;not null;comment:会话 ID" json:"conversation_id"` // 会话 ID
SectionID int64 `gorm:"column:section_id;not null;comment:section ID" json:"section_id"` // section ID
AgentID int64 `gorm:"column:agent_id;not null;comment:agent_id" json:"agent_id"` // agent_id
UserID string `gorm:"column:user_id;not null;comment:user id" json:"user_id"` // user id
Source int32 `gorm:"column:source;not null;comment:执行来源 0 API," json:"source"` // 执行来源 0 API,
Status string `gorm:"column:status;not null;comment:状态,0 Unknown, 1-Created,2-InProgress,3-Completed,4-Failed,5-Expired,6-Cancelled,7-RequiresAction" json:"status"` // 状态,0 Unknown, 1-Created,2-InProgress,3-Completed,4-Failed,5-Expired,6-Cancelled,7-RequiresAction
CreatorID int64 `gorm:"column:creator_id;not null;comment:创建者标识" json:"creator_id"` // 创建者标识
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:创建时间" json:"created_at"` // 创建时间
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:更新时间" json:"updated_at"` // 更新时间
FailedAt int64 `gorm:"column:failed_at;not null;comment:失败时间" json:"failed_at"` // 失败时间
LastError string `gorm:"column:last_error;comment:error message" json:"last_error"` // error message
CompletedAt int64 `gorm:"column:completed_at;not null;comment:结束时间" json:"completed_at"` // 结束时间
ChatRequest string `gorm:"column:chat_request;comment:保存原始请求的部分字段" json:"chat_request"` // 保存原始请求的部分字段
Ext string `gorm:"column:ext;comment:扩展字段" json:"ext"` // 扩展字段
Usage *agentrun.Usage `gorm:"column:usage;comment:usage;serializer:json" json:"usage"` // usage
}
// TableName RunRecord's table name
func (*RunRecord) TableName() string {
return TableNameRunRecord
}

View File

@@ -0,0 +1,103 @@
// 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/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
RunRecord *runRecord
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
RunRecord = &Q.RunRecord
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
RunRecord: newRunRecord(db, opts...),
}
}
type Query struct {
db *gorm.DB
RunRecord runRecord
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
RunRecord: q.RunRecord.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
RunRecord: q.RunRecord.replaceDB(db),
}
}
type queryCtx struct {
RunRecord IRunRecordDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
RunRecord: q.RunRecord.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
tx := q.db.Begin(opts...)
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}
type QueryTx struct {
*Query
Error error
}
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}

View File

@@ -0,0 +1,441 @@
// 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"
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal/model"
)
func newRunRecord(db *gorm.DB, opts ...gen.DOOption) runRecord {
_runRecord := runRecord{}
_runRecord.runRecordDo.UseDB(db, opts...)
_runRecord.runRecordDo.UseModel(&model.RunRecord{})
tableName := _runRecord.runRecordDo.TableName()
_runRecord.ALL = field.NewAsterisk(tableName)
_runRecord.ID = field.NewInt64(tableName, "id")
_runRecord.ConversationID = field.NewInt64(tableName, "conversation_id")
_runRecord.SectionID = field.NewInt64(tableName, "section_id")
_runRecord.AgentID = field.NewInt64(tableName, "agent_id")
_runRecord.UserID = field.NewString(tableName, "user_id")
_runRecord.Source = field.NewInt32(tableName, "source")
_runRecord.Status = field.NewString(tableName, "status")
_runRecord.CreatorID = field.NewInt64(tableName, "creator_id")
_runRecord.CreatedAt = field.NewInt64(tableName, "created_at")
_runRecord.UpdatedAt = field.NewInt64(tableName, "updated_at")
_runRecord.FailedAt = field.NewInt64(tableName, "failed_at")
_runRecord.LastError = field.NewString(tableName, "last_error")
_runRecord.CompletedAt = field.NewInt64(tableName, "completed_at")
_runRecord.ChatRequest = field.NewString(tableName, "chat_request")
_runRecord.Ext = field.NewString(tableName, "ext")
_runRecord.Usage = field.NewField(tableName, "usage")
_runRecord.fillFieldMap()
return _runRecord
}
// runRecord 执行记录表
type runRecord struct {
runRecordDo
ALL field.Asterisk
ID field.Int64 // 主键ID
ConversationID field.Int64 // 会话 ID
SectionID field.Int64 // section ID
AgentID field.Int64 // agent_id
UserID field.String // user id
Source field.Int32 // 执行来源 0 API,
Status field.String // 状态,0 Unknown, 1-Created,2-InProgress,3-Completed,4-Failed,5-Expired,6-Cancelled,7-RequiresAction
CreatorID field.Int64 // 创建者标识
CreatedAt field.Int64 // 创建时间
UpdatedAt field.Int64 // 更新时间
FailedAt field.Int64 // 失败时间
LastError field.String // error message
CompletedAt field.Int64 // 结束时间
ChatRequest field.String // 保存原始请求的部分字段
Ext field.String // 扩展字段
Usage field.Field // usage
fieldMap map[string]field.Expr
}
func (r runRecord) Table(newTableName string) *runRecord {
r.runRecordDo.UseTable(newTableName)
return r.updateTableName(newTableName)
}
func (r runRecord) As(alias string) *runRecord {
r.runRecordDo.DO = *(r.runRecordDo.As(alias).(*gen.DO))
return r.updateTableName(alias)
}
func (r *runRecord) updateTableName(table string) *runRecord {
r.ALL = field.NewAsterisk(table)
r.ID = field.NewInt64(table, "id")
r.ConversationID = field.NewInt64(table, "conversation_id")
r.SectionID = field.NewInt64(table, "section_id")
r.AgentID = field.NewInt64(table, "agent_id")
r.UserID = field.NewString(table, "user_id")
r.Source = field.NewInt32(table, "source")
r.Status = field.NewString(table, "status")
r.CreatorID = field.NewInt64(table, "creator_id")
r.CreatedAt = field.NewInt64(table, "created_at")
r.UpdatedAt = field.NewInt64(table, "updated_at")
r.FailedAt = field.NewInt64(table, "failed_at")
r.LastError = field.NewString(table, "last_error")
r.CompletedAt = field.NewInt64(table, "completed_at")
r.ChatRequest = field.NewString(table, "chat_request")
r.Ext = field.NewString(table, "ext")
r.Usage = field.NewField(table, "usage")
r.fillFieldMap()
return r
}
func (r *runRecord) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := r.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (r *runRecord) fillFieldMap() {
r.fieldMap = make(map[string]field.Expr, 16)
r.fieldMap["id"] = r.ID
r.fieldMap["conversation_id"] = r.ConversationID
r.fieldMap["section_id"] = r.SectionID
r.fieldMap["agent_id"] = r.AgentID
r.fieldMap["user_id"] = r.UserID
r.fieldMap["source"] = r.Source
r.fieldMap["status"] = r.Status
r.fieldMap["creator_id"] = r.CreatorID
r.fieldMap["created_at"] = r.CreatedAt
r.fieldMap["updated_at"] = r.UpdatedAt
r.fieldMap["failed_at"] = r.FailedAt
r.fieldMap["last_error"] = r.LastError
r.fieldMap["completed_at"] = r.CompletedAt
r.fieldMap["chat_request"] = r.ChatRequest
r.fieldMap["ext"] = r.Ext
r.fieldMap["usage"] = r.Usage
}
func (r runRecord) clone(db *gorm.DB) runRecord {
r.runRecordDo.ReplaceConnPool(db.Statement.ConnPool)
return r
}
func (r runRecord) replaceDB(db *gorm.DB) runRecord {
r.runRecordDo.ReplaceDB(db)
return r
}
type runRecordDo struct{ gen.DO }
type IRunRecordDo interface {
gen.SubQuery
Debug() IRunRecordDo
WithContext(ctx context.Context) IRunRecordDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IRunRecordDo
WriteDB() IRunRecordDo
As(alias string) gen.Dao
Session(config *gorm.Session) IRunRecordDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IRunRecordDo
Not(conds ...gen.Condition) IRunRecordDo
Or(conds ...gen.Condition) IRunRecordDo
Select(conds ...field.Expr) IRunRecordDo
Where(conds ...gen.Condition) IRunRecordDo
Order(conds ...field.Expr) IRunRecordDo
Distinct(cols ...field.Expr) IRunRecordDo
Omit(cols ...field.Expr) IRunRecordDo
Join(table schema.Tabler, on ...field.Expr) IRunRecordDo
LeftJoin(table schema.Tabler, on ...field.Expr) IRunRecordDo
RightJoin(table schema.Tabler, on ...field.Expr) IRunRecordDo
Group(cols ...field.Expr) IRunRecordDo
Having(conds ...gen.Condition) IRunRecordDo
Limit(limit int) IRunRecordDo
Offset(offset int) IRunRecordDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IRunRecordDo
Unscoped() IRunRecordDo
Create(values ...*model.RunRecord) error
CreateInBatches(values []*model.RunRecord, batchSize int) error
Save(values ...*model.RunRecord) error
First() (*model.RunRecord, error)
Take() (*model.RunRecord, error)
Last() (*model.RunRecord, error)
Find() ([]*model.RunRecord, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.RunRecord, err error)
FindInBatches(result *[]*model.RunRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.RunRecord) (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) IRunRecordDo
Assign(attrs ...field.AssignExpr) IRunRecordDo
Joins(fields ...field.RelationField) IRunRecordDo
Preload(fields ...field.RelationField) IRunRecordDo
FirstOrInit() (*model.RunRecord, error)
FirstOrCreate() (*model.RunRecord, error)
FindByPage(offset int, limit int) (result []*model.RunRecord, 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) IRunRecordDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (r runRecordDo) Debug() IRunRecordDo {
return r.withDO(r.DO.Debug())
}
func (r runRecordDo) WithContext(ctx context.Context) IRunRecordDo {
return r.withDO(r.DO.WithContext(ctx))
}
func (r runRecordDo) ReadDB() IRunRecordDo {
return r.Clauses(dbresolver.Read)
}
func (r runRecordDo) WriteDB() IRunRecordDo {
return r.Clauses(dbresolver.Write)
}
func (r runRecordDo) Session(config *gorm.Session) IRunRecordDo {
return r.withDO(r.DO.Session(config))
}
func (r runRecordDo) Clauses(conds ...clause.Expression) IRunRecordDo {
return r.withDO(r.DO.Clauses(conds...))
}
func (r runRecordDo) Returning(value interface{}, columns ...string) IRunRecordDo {
return r.withDO(r.DO.Returning(value, columns...))
}
func (r runRecordDo) Not(conds ...gen.Condition) IRunRecordDo {
return r.withDO(r.DO.Not(conds...))
}
func (r runRecordDo) Or(conds ...gen.Condition) IRunRecordDo {
return r.withDO(r.DO.Or(conds...))
}
func (r runRecordDo) Select(conds ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.Select(conds...))
}
func (r runRecordDo) Where(conds ...gen.Condition) IRunRecordDo {
return r.withDO(r.DO.Where(conds...))
}
func (r runRecordDo) Order(conds ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.Order(conds...))
}
func (r runRecordDo) Distinct(cols ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.Distinct(cols...))
}
func (r runRecordDo) Omit(cols ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.Omit(cols...))
}
func (r runRecordDo) Join(table schema.Tabler, on ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.Join(table, on...))
}
func (r runRecordDo) LeftJoin(table schema.Tabler, on ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.LeftJoin(table, on...))
}
func (r runRecordDo) RightJoin(table schema.Tabler, on ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.RightJoin(table, on...))
}
func (r runRecordDo) Group(cols ...field.Expr) IRunRecordDo {
return r.withDO(r.DO.Group(cols...))
}
func (r runRecordDo) Having(conds ...gen.Condition) IRunRecordDo {
return r.withDO(r.DO.Having(conds...))
}
func (r runRecordDo) Limit(limit int) IRunRecordDo {
return r.withDO(r.DO.Limit(limit))
}
func (r runRecordDo) Offset(offset int) IRunRecordDo {
return r.withDO(r.DO.Offset(offset))
}
func (r runRecordDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IRunRecordDo {
return r.withDO(r.DO.Scopes(funcs...))
}
func (r runRecordDo) Unscoped() IRunRecordDo {
return r.withDO(r.DO.Unscoped())
}
func (r runRecordDo) Create(values ...*model.RunRecord) error {
if len(values) == 0 {
return nil
}
return r.DO.Create(values)
}
func (r runRecordDo) CreateInBatches(values []*model.RunRecord, batchSize int) error {
return r.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 (r runRecordDo) Save(values ...*model.RunRecord) error {
if len(values) == 0 {
return nil
}
return r.DO.Save(values)
}
func (r runRecordDo) First() (*model.RunRecord, error) {
if result, err := r.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.RunRecord), nil
}
}
func (r runRecordDo) Take() (*model.RunRecord, error) {
if result, err := r.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.RunRecord), nil
}
}
func (r runRecordDo) Last() (*model.RunRecord, error) {
if result, err := r.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.RunRecord), nil
}
}
func (r runRecordDo) Find() ([]*model.RunRecord, error) {
result, err := r.DO.Find()
return result.([]*model.RunRecord), err
}
func (r runRecordDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.RunRecord, err error) {
buf := make([]*model.RunRecord, 0, batchSize)
err = r.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 (r runRecordDo) FindInBatches(result *[]*model.RunRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return r.DO.FindInBatches(result, batchSize, fc)
}
func (r runRecordDo) Attrs(attrs ...field.AssignExpr) IRunRecordDo {
return r.withDO(r.DO.Attrs(attrs...))
}
func (r runRecordDo) Assign(attrs ...field.AssignExpr) IRunRecordDo {
return r.withDO(r.DO.Assign(attrs...))
}
func (r runRecordDo) Joins(fields ...field.RelationField) IRunRecordDo {
for _, _f := range fields {
r = *r.withDO(r.DO.Joins(_f))
}
return &r
}
func (r runRecordDo) Preload(fields ...field.RelationField) IRunRecordDo {
for _, _f := range fields {
r = *r.withDO(r.DO.Preload(_f))
}
return &r
}
func (r runRecordDo) FirstOrInit() (*model.RunRecord, error) {
if result, err := r.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.RunRecord), nil
}
}
func (r runRecordDo) FirstOrCreate() (*model.RunRecord, error) {
if result, err := r.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.RunRecord), nil
}
}
func (r runRecordDo) FindByPage(offset int, limit int) (result []*model.RunRecord, count int64, err error) {
result, err = r.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 = r.Offset(-1).Limit(-1).Count()
return
}
func (r runRecordDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = r.Count()
if err != nil {
return
}
err = r.Offset(offset).Limit(limit).Scan(result)
return
}
func (r runRecordDo) Scan(result interface{}) (err error) {
return r.DO.Scan(result)
}
func (r runRecordDo) Delete(models ...*model.RunRecord) (result gen.ResultInfo, err error) {
return r.DO.Delete(models)
}
func (r *runRecordDo) withDO(do gen.Dao) *runRecordDo {
r.DO = *do.(*gen.DO)
return r
}