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,204 @@
/*
* 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"
"errors"
"time"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/entity"
"github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
"github.com/coze-dev/coze-studio/backend/pkg/logs"
)
type ShortCutCmdDAO struct {
db *gorm.DB
query *query.Query
idgen idgen.IDGenerator
}
func NewShortCutCmdDAO(db *gorm.DB, idgen idgen.IDGenerator) *ShortCutCmdDAO {
return &ShortCutCmdDAO{
db: db,
query: query.Use(db),
idgen: idgen,
}
}
func (dao *ShortCutCmdDAO) Create(ctx context.Context, shortcut *entity.ShortcutCmd) (*entity.ShortcutCmd, error) {
createPO, err := dao.buildCreatePO(ctx, shortcut)
if err != nil {
return nil, err
}
createErr := dao.query.ShortcutCommand.WithContext(ctx).Debug().Create(createPO)
logs.CtxInfof(ctx, "ShortcutCommand %v, err:%v", conv.DebugJsonToStr(createPO), err)
if createErr != nil {
return nil, createErr
}
return createPO, nil
}
func (dao *ShortCutCmdDAO) buildCreatePO(ctx context.Context, shortcut *entity.ShortcutCmd) (*model.ShortcutCommand, error) {
cmdID, err := dao.idgen.GenID(ctx)
if err != nil {
return nil, err
}
po := &model.ShortcutCommand{
ObjectID: shortcut.ObjectID,
CommandID: cmdID,
CommandName: shortcut.CommandName,
ShortcutCommand: shortcut.ShortcutCommand,
Description: shortcut.Description,
SendType: shortcut.SendType,
ToolType: shortcut.ToolType,
WorkFlowID: shortcut.WorkFlowID,
PluginID: shortcut.PluginID,
PluginToolName: shortcut.PluginToolName,
TemplateQuery: shortcut.TemplateQuery,
Components: shortcut.Components,
CardSchema: shortcut.CardSchema,
ToolInfo: shortcut.ToolInfo,
Status: 1,
CreatorID: shortcut.CreatorID,
CreatedAt: time.Now().UnixMilli(),
UpdatedAt: time.Now().UnixMilli(),
AgentID: shortcut.AgentID,
ShortcutIcon: shortcut.ShortcutIcon,
PluginToolID: shortcut.PluginToolID,
}
return po, nil
}
func (dao *ShortCutCmdDAO) Update(ctx context.Context, shortcut *entity.ShortcutCmd) (*entity.ShortcutCmd, error) {
updatePO := dao.buildUpdatePO(ctx, shortcut)
_, updateErr := dao.query.ShortcutCommand.WithContext(ctx).Debug().Where(dao.query.ShortcutCommand.CommandID.Eq(shortcut.CommandID)).Updates(updatePO)
if updateErr != nil {
return nil, updateErr
}
return updatePO, nil
}
func (dao *ShortCutCmdDAO) buildUpdatePO(ctx context.Context, shortcut *entity.ShortcutCmd) *model.ShortcutCommand {
po := shortcut
po.UpdatedAt = time.Now().UnixMilli()
return po
}
func (dao *ShortCutCmdDAO) List(ctx context.Context, lm *entity.ListMeta) ([]*entity.ShortcutCmd, error) {
if len(lm.CommandIDs) == 0 {
return nil, nil
}
do := dao.query.ShortcutCommand.WithContext(ctx).Where(dao.query.ShortcutCommand.ObjectID.Eq(lm.ObjectID)).Debug().
Where(dao.query.ShortcutCommand.CommandID.In(lm.CommandIDs...)).
Where(dao.query.ShortcutCommand.IsOnline.Eq(lm.IsOnline))
poList, err := do.Find()
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
return slices.Transform(poList, func(po *model.ShortcutCommand) *entity.ShortcutCmd {
return po
}), nil
}
func (dao *ShortCutCmdDAO) GetByCmdID(ctx context.Context, cmdID int64, isOnline int32) (*entity.ShortcutCmd, error) {
po, err := dao.query.ShortcutCommand.WithContext(ctx).Where(dao.query.ShortcutCommand.CommandID.Eq(cmdID)).
Where(dao.query.ShortcutCommand.IsOnline.Eq(isOnline)).Debug().
First()
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
return po, nil
}
func (dao *ShortCutCmdDAO) PublishCMDs(ctx context.Context, objID int64, cmdIDs []int64) error {
if len(cmdIDs) == 0 {
return nil
}
draftCmds, err := dao.query.ShortcutCommand.WithContext(ctx).Debug().
Where(dao.query.ShortcutCommand.ObjectID.Eq(objID)).
Where(dao.query.ShortcutCommand.CommandID.In(cmdIDs...)).
Where(dao.query.ShortcutCommand.IsOnline.Eq(0)).
Find()
if err != nil {
return err
}
tx := dao.query.Begin()
defer func() {
if tx.Error != nil {
rbErr := tx.Rollback()
if rbErr != nil {
logs.CtxErrorf(ctx, "rollback failed, err:%v", rbErr)
}
}
cErr := tx.Commit()
if cErr != nil {
logs.CtxErrorf(ctx, "commit failed, err:%v", cErr)
}
}()
onlineCmds, err := dao.query.ShortcutCommand.WithContext(ctx).Debug().
Where(dao.query.ShortcutCommand.ObjectID.Eq(objID)).
Where(dao.query.ShortcutCommand.CommandID.In(cmdIDs...)).
Where(dao.query.ShortcutCommand.IsOnline.Eq(1)).Find()
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
onelineCmdMap := make(map[int64]*model.ShortcutCommand)
for _, one := range onlineCmds {
onelineCmdMap[one.CommandID] = one
}
for _, item := range draftCmds {
item.IsOnline = 1
item.UpdatedAt = time.Now().UnixMilli()
item.ID = 0
var opErr error
if _, ok := onelineCmdMap[item.CommandID]; !ok {
opErr = tx.ShortcutCommand.WithContext(ctx).Debug().Create(item)
} else {
opErr = tx.ShortcutCommand.WithContext(ctx).Debug().
Where(dao.query.ShortcutCommand.ObjectID.Eq(item.ObjectID)).
Where(dao.query.ShortcutCommand.CommandID.Eq(item.CommandID)).
Where(dao.query.ShortcutCommand.IsOnline.Eq(item.IsOnline)).
Save(item)
}
logs.CtxInfof(ctx, "publish cmd %v, err:%v", conv.DebugJsonToStr(item), opErr)
if opErr != nil {
return opErr
}
}
return nil
}

View File

@@ -0,0 +1,41 @@
// 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/ocean/cloud/playground"
const TableNameShortcutCommand = "shortcut_command"
// ShortcutCommand bot快捷指令表
type ShortcutCommand struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键ID" json:"id"` // 主键ID
ObjectID int64 `gorm:"column:object_id;not null;comment:实体ID,该实体可用这个指令" json:"object_id"` // 实体ID,该实体可用这个指令
CommandID int64 `gorm:"column:command_id;not null;comment:命令ID" json:"command_id"` // 命令ID
CommandName string `gorm:"column:command_name;not null;comment:命令名称" json:"command_name"` // 命令名称
ShortcutCommand string `gorm:"column:shortcut_command;not null;comment:快捷指令" json:"shortcut_command"` // 快捷指令
Description string `gorm:"column:description;not null;comment:命令描述" json:"description"` // 命令描述
SendType int32 `gorm:"column:send_type;not null;comment:发送类型 0:query 1:panel" json:"send_type"` // 发送类型 0:query 1:panel
ToolType int32 `gorm:"column:tool_type;not null;comment:使用工具的type 1:workFlow 2:插件" json:"tool_type"` // 使用工具的type 1:workFlow 2:插件
WorkFlowID int64 `gorm:"column:work_flow_id;not null;comment:使用workFlow的id" json:"work_flow_id"` // 使用workFlow的id
PluginID int64 `gorm:"column:plugin_id;not null;comment:使用插件的id" json:"plugin_id"` // 使用插件的id
PluginToolName string `gorm:"column:plugin_tool_name;not null;comment:使用插件的api_name" json:"plugin_tool_name"` // 使用插件的api_name
TemplateQuery string `gorm:"column:template_query;comment:query模板" json:"template_query"` // query模板
Components []*playground.Components `gorm:"column:components;comment:panel参数;serializer:json" json:"components"` // panel参数
CardSchema string `gorm:"column:card_schema;comment:卡片schema" json:"card_schema"` // 卡片schema
ToolInfo *playground.ToolInfo `gorm:"column:tool_info;comment:工具信息 包含name+变量列表;serializer:json" json:"tool_info"` // 工具信息 包含name+变量列表
Status int32 `gorm:"column:status;not null;comment:状态,0无效,1有效" json:"status"` // 状态,0无效,1有效
CreatorID int64 `gorm:"column:creator_id;comment:创建者ID" json:"creator_id"` // 创建者ID
IsOnline int32 `gorm:"column:is_online;not null;comment:是否为线上信息 0草稿 1线上" json:"is_online"` // 是否为线上信息 0草稿 1线上
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"` // 更新时间
AgentID int64 `gorm:"column:agent_id;not null;comment:multi的指令时该指令由哪个节点执行" json:"agent_id"` // multi的指令时该指令由哪个节点执行
ShortcutIcon *playground.ShortcutFileInfo `gorm:"column:shortcut_icon;comment:快捷指令图标;serializer:json" json:"shortcut_icon"` // 快捷指令图标
PluginToolID int64 `gorm:"column:plugin_tool_id;not null;comment:tool_id" json:"plugin_tool_id"` // tool_id
}
// TableName ShortcutCommand's table name
func (*ShortcutCommand) TableName() string {
return TableNameShortcutCommand
}

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)
ShortcutCommand *shortcutCommand
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
ShortcutCommand = &Q.ShortcutCommand
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
ShortcutCommand: newShortcutCommand(db, opts...),
}
}
type Query struct {
db *gorm.DB
ShortcutCommand shortcutCommand
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
ShortcutCommand: q.ShortcutCommand.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,
ShortcutCommand: q.ShortcutCommand.replaceDB(db),
}
}
type queryCtx struct {
ShortcutCommand IShortcutCommandDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
ShortcutCommand: q.ShortcutCommand.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,469 @@
// 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/shortcutcmd/internal/dal/model"
)
func newShortcutCommand(db *gorm.DB, opts ...gen.DOOption) shortcutCommand {
_shortcutCommand := shortcutCommand{}
_shortcutCommand.shortcutCommandDo.UseDB(db, opts...)
_shortcutCommand.shortcutCommandDo.UseModel(&model.ShortcutCommand{})
tableName := _shortcutCommand.shortcutCommandDo.TableName()
_shortcutCommand.ALL = field.NewAsterisk(tableName)
_shortcutCommand.ID = field.NewInt64(tableName, "id")
_shortcutCommand.ObjectID = field.NewInt64(tableName, "object_id")
_shortcutCommand.CommandID = field.NewInt64(tableName, "command_id")
_shortcutCommand.CommandName = field.NewString(tableName, "command_name")
_shortcutCommand.ShortcutCommand = field.NewString(tableName, "shortcut_command")
_shortcutCommand.Description = field.NewString(tableName, "description")
_shortcutCommand.SendType = field.NewInt32(tableName, "send_type")
_shortcutCommand.ToolType = field.NewInt32(tableName, "tool_type")
_shortcutCommand.WorkFlowID = field.NewInt64(tableName, "work_flow_id")
_shortcutCommand.PluginID = field.NewInt64(tableName, "plugin_id")
_shortcutCommand.PluginToolName = field.NewString(tableName, "plugin_tool_name")
_shortcutCommand.TemplateQuery = field.NewString(tableName, "template_query")
_shortcutCommand.Components = field.NewField(tableName, "components")
_shortcutCommand.CardSchema = field.NewString(tableName, "card_schema")
_shortcutCommand.ToolInfo = field.NewField(tableName, "tool_info")
_shortcutCommand.Status = field.NewInt32(tableName, "status")
_shortcutCommand.CreatorID = field.NewInt64(tableName, "creator_id")
_shortcutCommand.IsOnline = field.NewInt32(tableName, "is_online")
_shortcutCommand.CreatedAt = field.NewInt64(tableName, "created_at")
_shortcutCommand.UpdatedAt = field.NewInt64(tableName, "updated_at")
_shortcutCommand.AgentID = field.NewInt64(tableName, "agent_id")
_shortcutCommand.ShortcutIcon = field.NewField(tableName, "shortcut_icon")
_shortcutCommand.PluginToolID = field.NewInt64(tableName, "plugin_tool_id")
_shortcutCommand.fillFieldMap()
return _shortcutCommand
}
// shortcutCommand bot快捷指令表
type shortcutCommand struct {
shortcutCommandDo
ALL field.Asterisk
ID field.Int64 // 主键ID
ObjectID field.Int64 // 实体ID,该实体可用这个指令
CommandID field.Int64 // 命令ID
CommandName field.String // 命令名称
ShortcutCommand field.String // 快捷指令
Description field.String // 命令描述
SendType field.Int32 // 发送类型 0:query 1:panel
ToolType field.Int32 // 使用工具的type 1:workFlow 2:插件
WorkFlowID field.Int64 // 使用workFlow的id
PluginID field.Int64 // 使用插件的id
PluginToolName field.String // 使用插件的api_name
TemplateQuery field.String // query模板
Components field.Field // panel参数
CardSchema field.String // 卡片schema
ToolInfo field.Field // 工具信息 包含name+变量列表
Status field.Int32 // 状态,0无效,1有效
CreatorID field.Int64 // 创建者ID
IsOnline field.Int32 // 是否为线上信息 0草稿 1线上
CreatedAt field.Int64 // 创建时间
UpdatedAt field.Int64 // 更新时间
AgentID field.Int64 // multi的指令时该指令由哪个节点执行
ShortcutIcon field.Field // 快捷指令图标
PluginToolID field.Int64 // tool_id
fieldMap map[string]field.Expr
}
func (s shortcutCommand) Table(newTableName string) *shortcutCommand {
s.shortcutCommandDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s shortcutCommand) As(alias string) *shortcutCommand {
s.shortcutCommandDo.DO = *(s.shortcutCommandDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *shortcutCommand) updateTableName(table string) *shortcutCommand {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewInt64(table, "id")
s.ObjectID = field.NewInt64(table, "object_id")
s.CommandID = field.NewInt64(table, "command_id")
s.CommandName = field.NewString(table, "command_name")
s.ShortcutCommand = field.NewString(table, "shortcut_command")
s.Description = field.NewString(table, "description")
s.SendType = field.NewInt32(table, "send_type")
s.ToolType = field.NewInt32(table, "tool_type")
s.WorkFlowID = field.NewInt64(table, "work_flow_id")
s.PluginID = field.NewInt64(table, "plugin_id")
s.PluginToolName = field.NewString(table, "plugin_tool_name")
s.TemplateQuery = field.NewString(table, "template_query")
s.Components = field.NewField(table, "components")
s.CardSchema = field.NewString(table, "card_schema")
s.ToolInfo = field.NewField(table, "tool_info")
s.Status = field.NewInt32(table, "status")
s.CreatorID = field.NewInt64(table, "creator_id")
s.IsOnline = field.NewInt32(table, "is_online")
s.CreatedAt = field.NewInt64(table, "created_at")
s.UpdatedAt = field.NewInt64(table, "updated_at")
s.AgentID = field.NewInt64(table, "agent_id")
s.ShortcutIcon = field.NewField(table, "shortcut_icon")
s.PluginToolID = field.NewInt64(table, "plugin_tool_id")
s.fillFieldMap()
return s
}
func (s *shortcutCommand) 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 *shortcutCommand) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 23)
s.fieldMap["id"] = s.ID
s.fieldMap["object_id"] = s.ObjectID
s.fieldMap["command_id"] = s.CommandID
s.fieldMap["command_name"] = s.CommandName
s.fieldMap["shortcut_command"] = s.ShortcutCommand
s.fieldMap["description"] = s.Description
s.fieldMap["send_type"] = s.SendType
s.fieldMap["tool_type"] = s.ToolType
s.fieldMap["work_flow_id"] = s.WorkFlowID
s.fieldMap["plugin_id"] = s.PluginID
s.fieldMap["plugin_tool_name"] = s.PluginToolName
s.fieldMap["template_query"] = s.TemplateQuery
s.fieldMap["components"] = s.Components
s.fieldMap["card_schema"] = s.CardSchema
s.fieldMap["tool_info"] = s.ToolInfo
s.fieldMap["status"] = s.Status
s.fieldMap["creator_id"] = s.CreatorID
s.fieldMap["is_online"] = s.IsOnline
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["agent_id"] = s.AgentID
s.fieldMap["shortcut_icon"] = s.ShortcutIcon
s.fieldMap["plugin_tool_id"] = s.PluginToolID
}
func (s shortcutCommand) clone(db *gorm.DB) shortcutCommand {
s.shortcutCommandDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s shortcutCommand) replaceDB(db *gorm.DB) shortcutCommand {
s.shortcutCommandDo.ReplaceDB(db)
return s
}
type shortcutCommandDo struct{ gen.DO }
type IShortcutCommandDo interface {
gen.SubQuery
Debug() IShortcutCommandDo
WithContext(ctx context.Context) IShortcutCommandDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IShortcutCommandDo
WriteDB() IShortcutCommandDo
As(alias string) gen.Dao
Session(config *gorm.Session) IShortcutCommandDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IShortcutCommandDo
Not(conds ...gen.Condition) IShortcutCommandDo
Or(conds ...gen.Condition) IShortcutCommandDo
Select(conds ...field.Expr) IShortcutCommandDo
Where(conds ...gen.Condition) IShortcutCommandDo
Order(conds ...field.Expr) IShortcutCommandDo
Distinct(cols ...field.Expr) IShortcutCommandDo
Omit(cols ...field.Expr) IShortcutCommandDo
Join(table schema.Tabler, on ...field.Expr) IShortcutCommandDo
LeftJoin(table schema.Tabler, on ...field.Expr) IShortcutCommandDo
RightJoin(table schema.Tabler, on ...field.Expr) IShortcutCommandDo
Group(cols ...field.Expr) IShortcutCommandDo
Having(conds ...gen.Condition) IShortcutCommandDo
Limit(limit int) IShortcutCommandDo
Offset(offset int) IShortcutCommandDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IShortcutCommandDo
Unscoped() IShortcutCommandDo
Create(values ...*model.ShortcutCommand) error
CreateInBatches(values []*model.ShortcutCommand, batchSize int) error
Save(values ...*model.ShortcutCommand) error
First() (*model.ShortcutCommand, error)
Take() (*model.ShortcutCommand, error)
Last() (*model.ShortcutCommand, error)
Find() ([]*model.ShortcutCommand, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ShortcutCommand, err error)
FindInBatches(result *[]*model.ShortcutCommand, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.ShortcutCommand) (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) IShortcutCommandDo
Assign(attrs ...field.AssignExpr) IShortcutCommandDo
Joins(fields ...field.RelationField) IShortcutCommandDo
Preload(fields ...field.RelationField) IShortcutCommandDo
FirstOrInit() (*model.ShortcutCommand, error)
FirstOrCreate() (*model.ShortcutCommand, error)
FindByPage(offset int, limit int) (result []*model.ShortcutCommand, 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) IShortcutCommandDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s shortcutCommandDo) Debug() IShortcutCommandDo {
return s.withDO(s.DO.Debug())
}
func (s shortcutCommandDo) WithContext(ctx context.Context) IShortcutCommandDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s shortcutCommandDo) ReadDB() IShortcutCommandDo {
return s.Clauses(dbresolver.Read)
}
func (s shortcutCommandDo) WriteDB() IShortcutCommandDo {
return s.Clauses(dbresolver.Write)
}
func (s shortcutCommandDo) Session(config *gorm.Session) IShortcutCommandDo {
return s.withDO(s.DO.Session(config))
}
func (s shortcutCommandDo) Clauses(conds ...clause.Expression) IShortcutCommandDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s shortcutCommandDo) Returning(value interface{}, columns ...string) IShortcutCommandDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s shortcutCommandDo) Not(conds ...gen.Condition) IShortcutCommandDo {
return s.withDO(s.DO.Not(conds...))
}
func (s shortcutCommandDo) Or(conds ...gen.Condition) IShortcutCommandDo {
return s.withDO(s.DO.Or(conds...))
}
func (s shortcutCommandDo) Select(conds ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.Select(conds...))
}
func (s shortcutCommandDo) Where(conds ...gen.Condition) IShortcutCommandDo {
return s.withDO(s.DO.Where(conds...))
}
func (s shortcutCommandDo) Order(conds ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.Order(conds...))
}
func (s shortcutCommandDo) Distinct(cols ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s shortcutCommandDo) Omit(cols ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s shortcutCommandDo) Join(table schema.Tabler, on ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s shortcutCommandDo) LeftJoin(table schema.Tabler, on ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s shortcutCommandDo) RightJoin(table schema.Tabler, on ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s shortcutCommandDo) Group(cols ...field.Expr) IShortcutCommandDo {
return s.withDO(s.DO.Group(cols...))
}
func (s shortcutCommandDo) Having(conds ...gen.Condition) IShortcutCommandDo {
return s.withDO(s.DO.Having(conds...))
}
func (s shortcutCommandDo) Limit(limit int) IShortcutCommandDo {
return s.withDO(s.DO.Limit(limit))
}
func (s shortcutCommandDo) Offset(offset int) IShortcutCommandDo {
return s.withDO(s.DO.Offset(offset))
}
func (s shortcutCommandDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IShortcutCommandDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s shortcutCommandDo) Unscoped() IShortcutCommandDo {
return s.withDO(s.DO.Unscoped())
}
func (s shortcutCommandDo) Create(values ...*model.ShortcutCommand) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s shortcutCommandDo) CreateInBatches(values []*model.ShortcutCommand, 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 shortcutCommandDo) Save(values ...*model.ShortcutCommand) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s shortcutCommandDo) First() (*model.ShortcutCommand, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.ShortcutCommand), nil
}
}
func (s shortcutCommandDo) Take() (*model.ShortcutCommand, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.ShortcutCommand), nil
}
}
func (s shortcutCommandDo) Last() (*model.ShortcutCommand, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.ShortcutCommand), nil
}
}
func (s shortcutCommandDo) Find() ([]*model.ShortcutCommand, error) {
result, err := s.DO.Find()
return result.([]*model.ShortcutCommand), err
}
func (s shortcutCommandDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ShortcutCommand, err error) {
buf := make([]*model.ShortcutCommand, 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 shortcutCommandDo) FindInBatches(result *[]*model.ShortcutCommand, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s shortcutCommandDo) Attrs(attrs ...field.AssignExpr) IShortcutCommandDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s shortcutCommandDo) Assign(attrs ...field.AssignExpr) IShortcutCommandDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s shortcutCommandDo) Joins(fields ...field.RelationField) IShortcutCommandDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s shortcutCommandDo) Preload(fields ...field.RelationField) IShortcutCommandDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s shortcutCommandDo) FirstOrInit() (*model.ShortcutCommand, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.ShortcutCommand), nil
}
}
func (s shortcutCommandDo) FirstOrCreate() (*model.ShortcutCommand, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.ShortcutCommand), nil
}
}
func (s shortcutCommandDo) FindByPage(offset int, limit int) (result []*model.ShortcutCommand, 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 shortcutCommandDo) 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 shortcutCommandDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s shortcutCommandDo) Delete(models ...*model.ShortcutCommand) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *shortcutCommandDo) withDO(do gen.Dao) *shortcutCommandDo {
s.DO = *do.(*gen.DO)
return s
}