feat: Support for Chat Flow & Agent Support for binding a single chat flow (#765)
Co-authored-by: Yu Yang <72337138+tomasyu985@users.noreply.github.com> Co-authored-by: zengxiaohui <csu.zengxiaohui@gmail.com> Co-authored-by: lijunwen.gigoo <lijunwen.gigoo@bytedance.com> Co-authored-by: lvxinyu.1117 <lvxinyu.1117@bytedance.com> Co-authored-by: liuyunchao.0510 <liuyunchao.0510@bytedance.com> Co-authored-by: haozhenfei <37089575+haozhenfei@users.noreply.github.com> Co-authored-by: July <jiangxujin@bytedance.com> Co-authored-by: tecvan-fe <fanwenjie.fe@bytedance.com>
This commit is contained in:
113
backend/domain/upload/internal/dal/dao/files.go
Normal file
113
backend/domain/upload/internal/dal/dao/files.go
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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 dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
type FilesDAO struct {
|
||||
DB *gorm.DB
|
||||
Query *query.Query
|
||||
}
|
||||
|
||||
func NewFilesDAO(db *gorm.DB) *FilesDAO {
|
||||
return &FilesDAO{
|
||||
DB: db,
|
||||
Query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *FilesDAO) Create(ctx context.Context, file *entity.File) error {
|
||||
f := dao.fromEntityToModel(file)
|
||||
return dao.Query.Files.WithContext(ctx).Create(f)
|
||||
}
|
||||
|
||||
func (dao *FilesDAO) BatchCreate(ctx context.Context, files []*entity.File) error {
|
||||
if len(files) == 0 {
|
||||
return nil
|
||||
}
|
||||
return dao.Query.Files.WithContext(ctx).CreateInBatches(slices.Transform(files, dao.fromEntityToModel), len(files))
|
||||
}
|
||||
|
||||
func (dao *FilesDAO) Delete(ctx context.Context, id int64) error {
|
||||
_, err := dao.Query.Files.WithContext(ctx).Where(dao.Query.Files.ID.Eq(id)).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func (dao *FilesDAO) GetByID(ctx context.Context, id int64) (*entity.File, error) {
|
||||
file, err := dao.Query.Files.WithContext(ctx).Where(dao.Query.Files.ID.Eq(id)).First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dao.fromModelToEntity(file), nil
|
||||
}
|
||||
|
||||
func (dao *FilesDAO) MGetByIDs(ctx context.Context, ids []int64) ([]*entity.File, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
files, err := dao.Query.Files.WithContext(ctx).Where(dao.Query.Files.ID.In(ids...)).Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return slices.Transform(files, dao.fromModelToEntity), nil
|
||||
}
|
||||
|
||||
func (dao *FilesDAO) fromModelToEntity(model *model.Files) *entity.File {
|
||||
if model == nil {
|
||||
return nil
|
||||
}
|
||||
return &entity.File{
|
||||
ID: model.ID,
|
||||
Name: model.Name,
|
||||
FileSize: model.FileSize,
|
||||
TosURI: model.TosURI,
|
||||
Status: entity.FileStatus(model.Status),
|
||||
Comment: model.Comment,
|
||||
Source: entity.FileSource(model.Source),
|
||||
CreatorID: model.CreatorID,
|
||||
CozeAccountID: model.CozeAccountID,
|
||||
ContentType: model.ContentType,
|
||||
CreatedAt: model.CreatedAt,
|
||||
UpdatedAt: model.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (dao *FilesDAO) fromEntityToModel(entity *entity.File) *model.Files {
|
||||
return &model.Files{
|
||||
ID: entity.ID,
|
||||
Name: entity.Name,
|
||||
FileSize: entity.FileSize,
|
||||
TosURI: entity.TosURI,
|
||||
Status: int32(entity.Status),
|
||||
Comment: entity.Comment,
|
||||
Source: int32(entity.Source),
|
||||
CreatorID: entity.CreatorID,
|
||||
CozeAccountID: entity.CozeAccountID,
|
||||
ContentType: entity.ContentType,
|
||||
CreatedAt: entity.CreatedAt,
|
||||
UpdatedAt: entity.UpdatedAt,
|
||||
}
|
||||
}
|
||||
49
backend/domain/upload/internal/dal/model/files.gen.go
Normal file
49
backend/domain/upload/internal/dal/model/files.gen.go
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// 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 (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameFiles = "files"
|
||||
|
||||
// Files file resource table
|
||||
type Files struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:id" json:"id"` // id
|
||||
Name string `gorm:"column:name;not null;comment:file name" json:"name"` // file name
|
||||
FileSize int64 `gorm:"column:file_size;not null;comment:file size" json:"file_size"` // file size
|
||||
TosURI string `gorm:"column:tos_uri;not null;comment:TOS URI" json:"tos_uri"` // TOS URI
|
||||
Status int32 `gorm:"column:status;not null;comment:status,0invalid,1valid" json:"status"` // status,0invalid,1valid
|
||||
Comment string `gorm:"column:comment;not null;comment:file comment" json:"comment"` // file comment
|
||||
Source int32 `gorm:"column:source;not null;comment:source:1 from API," json:"source"` // source:1 from API,
|
||||
CreatorID string `gorm:"column:creator_id;not null;comment:creator id" json:"creator_id"` // creator id
|
||||
ContentType string `gorm:"column:content_type;not null;comment:content type" json:"content_type"` // content type
|
||||
CozeAccountID int64 `gorm:"column:coze_account_id;not null;comment:coze account id" json:"coze_account_id"` // coze account id
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
|
||||
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time
|
||||
}
|
||||
|
||||
// TableName Files's table name
|
||||
func (*Files) TableName() string {
|
||||
return TableNameFiles
|
||||
}
|
||||
445
backend/domain/upload/internal/dal/query/files.gen.go
Normal file
445
backend/domain/upload/internal/dal/query/files.gen.go
Normal file
@@ -0,0 +1,445 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// 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/upload/internal/dal/model"
|
||||
)
|
||||
|
||||
func newFiles(db *gorm.DB, opts ...gen.DOOption) files {
|
||||
_files := files{}
|
||||
|
||||
_files.filesDo.UseDB(db, opts...)
|
||||
_files.filesDo.UseModel(&model.Files{})
|
||||
|
||||
tableName := _files.filesDo.TableName()
|
||||
_files.ALL = field.NewAsterisk(tableName)
|
||||
_files.ID = field.NewInt64(tableName, "id")
|
||||
_files.Name = field.NewString(tableName, "name")
|
||||
_files.FileSize = field.NewInt64(tableName, "file_size")
|
||||
_files.TosURI = field.NewString(tableName, "tos_uri")
|
||||
_files.Status = field.NewInt32(tableName, "status")
|
||||
_files.Comment = field.NewString(tableName, "comment")
|
||||
_files.Source = field.NewInt32(tableName, "source")
|
||||
_files.CreatorID = field.NewString(tableName, "creator_id")
|
||||
_files.ContentType = field.NewString(tableName, "content_type")
|
||||
_files.CozeAccountID = field.NewInt64(tableName, "coze_account_id")
|
||||
_files.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_files.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_files.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_files.fillFieldMap()
|
||||
|
||||
return _files
|
||||
}
|
||||
|
||||
// files file resource table
|
||||
type files struct {
|
||||
filesDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // id
|
||||
Name field.String // file name
|
||||
FileSize field.Int64 // file size
|
||||
TosURI field.String // TOS URI
|
||||
Status field.Int32 // status,0invalid,1valid
|
||||
Comment field.String // file comment
|
||||
Source field.Int32 // source:1 from API,
|
||||
CreatorID field.String // creator id
|
||||
ContentType field.String // content type
|
||||
CozeAccountID field.Int64 // coze account id
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
DeletedAt field.Field // Delete Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (f files) Table(newTableName string) *files {
|
||||
f.filesDo.UseTable(newTableName)
|
||||
return f.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (f files) As(alias string) *files {
|
||||
f.filesDo.DO = *(f.filesDo.As(alias).(*gen.DO))
|
||||
return f.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (f *files) updateTableName(table string) *files {
|
||||
f.ALL = field.NewAsterisk(table)
|
||||
f.ID = field.NewInt64(table, "id")
|
||||
f.Name = field.NewString(table, "name")
|
||||
f.FileSize = field.NewInt64(table, "file_size")
|
||||
f.TosURI = field.NewString(table, "tos_uri")
|
||||
f.Status = field.NewInt32(table, "status")
|
||||
f.Comment = field.NewString(table, "comment")
|
||||
f.Source = field.NewInt32(table, "source")
|
||||
f.CreatorID = field.NewString(table, "creator_id")
|
||||
f.ContentType = field.NewString(table, "content_type")
|
||||
f.CozeAccountID = field.NewInt64(table, "coze_account_id")
|
||||
f.CreatedAt = field.NewInt64(table, "created_at")
|
||||
f.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
f.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
f.fillFieldMap()
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *files) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := f.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (f *files) fillFieldMap() {
|
||||
f.fieldMap = make(map[string]field.Expr, 13)
|
||||
f.fieldMap["id"] = f.ID
|
||||
f.fieldMap["name"] = f.Name
|
||||
f.fieldMap["file_size"] = f.FileSize
|
||||
f.fieldMap["tos_uri"] = f.TosURI
|
||||
f.fieldMap["status"] = f.Status
|
||||
f.fieldMap["comment"] = f.Comment
|
||||
f.fieldMap["source"] = f.Source
|
||||
f.fieldMap["creator_id"] = f.CreatorID
|
||||
f.fieldMap["content_type"] = f.ContentType
|
||||
f.fieldMap["coze_account_id"] = f.CozeAccountID
|
||||
f.fieldMap["created_at"] = f.CreatedAt
|
||||
f.fieldMap["updated_at"] = f.UpdatedAt
|
||||
f.fieldMap["deleted_at"] = f.DeletedAt
|
||||
}
|
||||
|
||||
func (f files) clone(db *gorm.DB) files {
|
||||
f.filesDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return f
|
||||
}
|
||||
|
||||
func (f files) replaceDB(db *gorm.DB) files {
|
||||
f.filesDo.ReplaceDB(db)
|
||||
return f
|
||||
}
|
||||
|
||||
type filesDo struct{ gen.DO }
|
||||
|
||||
type IFilesDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IFilesDo
|
||||
WithContext(ctx context.Context) IFilesDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IFilesDo
|
||||
WriteDB() IFilesDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IFilesDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IFilesDo
|
||||
Not(conds ...gen.Condition) IFilesDo
|
||||
Or(conds ...gen.Condition) IFilesDo
|
||||
Select(conds ...field.Expr) IFilesDo
|
||||
Where(conds ...gen.Condition) IFilesDo
|
||||
Order(conds ...field.Expr) IFilesDo
|
||||
Distinct(cols ...field.Expr) IFilesDo
|
||||
Omit(cols ...field.Expr) IFilesDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IFilesDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IFilesDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IFilesDo
|
||||
Group(cols ...field.Expr) IFilesDo
|
||||
Having(conds ...gen.Condition) IFilesDo
|
||||
Limit(limit int) IFilesDo
|
||||
Offset(offset int) IFilesDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IFilesDo
|
||||
Unscoped() IFilesDo
|
||||
Create(values ...*model.Files) error
|
||||
CreateInBatches(values []*model.Files, batchSize int) error
|
||||
Save(values ...*model.Files) error
|
||||
First() (*model.Files, error)
|
||||
Take() (*model.Files, error)
|
||||
Last() (*model.Files, error)
|
||||
Find() ([]*model.Files, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Files, err error)
|
||||
FindInBatches(result *[]*model.Files, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.Files) (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) IFilesDo
|
||||
Assign(attrs ...field.AssignExpr) IFilesDo
|
||||
Joins(fields ...field.RelationField) IFilesDo
|
||||
Preload(fields ...field.RelationField) IFilesDo
|
||||
FirstOrInit() (*model.Files, error)
|
||||
FirstOrCreate() (*model.Files, error)
|
||||
FindByPage(offset int, limit int) (result []*model.Files, 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) IFilesDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (f filesDo) Debug() IFilesDo {
|
||||
return f.withDO(f.DO.Debug())
|
||||
}
|
||||
|
||||
func (f filesDo) WithContext(ctx context.Context) IFilesDo {
|
||||
return f.withDO(f.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (f filesDo) ReadDB() IFilesDo {
|
||||
return f.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (f filesDo) WriteDB() IFilesDo {
|
||||
return f.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (f filesDo) Session(config *gorm.Session) IFilesDo {
|
||||
return f.withDO(f.DO.Session(config))
|
||||
}
|
||||
|
||||
func (f filesDo) Clauses(conds ...clause.Expression) IFilesDo {
|
||||
return f.withDO(f.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (f filesDo) Returning(value interface{}, columns ...string) IFilesDo {
|
||||
return f.withDO(f.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (f filesDo) Not(conds ...gen.Condition) IFilesDo {
|
||||
return f.withDO(f.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (f filesDo) Or(conds ...gen.Condition) IFilesDo {
|
||||
return f.withDO(f.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (f filesDo) Select(conds ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (f filesDo) Where(conds ...gen.Condition) IFilesDo {
|
||||
return f.withDO(f.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (f filesDo) Order(conds ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (f filesDo) Distinct(cols ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (f filesDo) Omit(cols ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (f filesDo) Join(table schema.Tabler, on ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (f filesDo) LeftJoin(table schema.Tabler, on ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (f filesDo) RightJoin(table schema.Tabler, on ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (f filesDo) Group(cols ...field.Expr) IFilesDo {
|
||||
return f.withDO(f.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (f filesDo) Having(conds ...gen.Condition) IFilesDo {
|
||||
return f.withDO(f.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (f filesDo) Limit(limit int) IFilesDo {
|
||||
return f.withDO(f.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (f filesDo) Offset(offset int) IFilesDo {
|
||||
return f.withDO(f.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (f filesDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IFilesDo {
|
||||
return f.withDO(f.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (f filesDo) Unscoped() IFilesDo {
|
||||
return f.withDO(f.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (f filesDo) Create(values ...*model.Files) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return f.DO.Create(values)
|
||||
}
|
||||
|
||||
func (f filesDo) CreateInBatches(values []*model.Files, batchSize int) error {
|
||||
return f.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 (f filesDo) Save(values ...*model.Files) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return f.DO.Save(values)
|
||||
}
|
||||
|
||||
func (f filesDo) First() (*model.Files, error) {
|
||||
if result, err := f.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Files), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesDo) Take() (*model.Files, error) {
|
||||
if result, err := f.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Files), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesDo) Last() (*model.Files, error) {
|
||||
if result, err := f.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Files), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesDo) Find() ([]*model.Files, error) {
|
||||
result, err := f.DO.Find()
|
||||
return result.([]*model.Files), err
|
||||
}
|
||||
|
||||
func (f filesDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Files, err error) {
|
||||
buf := make([]*model.Files, 0, batchSize)
|
||||
err = f.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 (f filesDo) FindInBatches(result *[]*model.Files, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return f.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (f filesDo) Attrs(attrs ...field.AssignExpr) IFilesDo {
|
||||
return f.withDO(f.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (f filesDo) Assign(attrs ...field.AssignExpr) IFilesDo {
|
||||
return f.withDO(f.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (f filesDo) Joins(fields ...field.RelationField) IFilesDo {
|
||||
for _, _f := range fields {
|
||||
f = *f.withDO(f.DO.Joins(_f))
|
||||
}
|
||||
return &f
|
||||
}
|
||||
|
||||
func (f filesDo) Preload(fields ...field.RelationField) IFilesDo {
|
||||
for _, _f := range fields {
|
||||
f = *f.withDO(f.DO.Preload(_f))
|
||||
}
|
||||
return &f
|
||||
}
|
||||
|
||||
func (f filesDo) FirstOrInit() (*model.Files, error) {
|
||||
if result, err := f.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Files), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesDo) FirstOrCreate() (*model.Files, error) {
|
||||
if result, err := f.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Files), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesDo) FindByPage(offset int, limit int) (result []*model.Files, count int64, err error) {
|
||||
result, err = f.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 = f.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (f filesDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = f.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = f.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (f filesDo) Scan(result interface{}) (err error) {
|
||||
return f.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (f filesDo) Delete(models ...*model.Files) (result gen.ResultInfo, err error) {
|
||||
return f.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (f *filesDo) withDO(do gen.Dao) *filesDo {
|
||||
f.DO = *do.(*gen.DO)
|
||||
return f
|
||||
}
|
||||
119
backend/domain/upload/internal/dal/query/gen.go
Normal file
119
backend/domain/upload/internal/dal/query/gen.go
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// 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)
|
||||
Files *files
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
Files = &Q.Files
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Files: newFiles(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
Files files
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Files: q.Files.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,
|
||||
Files: q.Files.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
Files IFilesDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
Files: q.Files.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
|
||||
}
|
||||
Reference in New Issue
Block a user