feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
138
backend/domain/memory/database/internal/dal/agent_to_database.go
Normal file
138
backend/domain/memory/database/internal/dal/agent_to_database.go
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/table"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
)
|
||||
|
||||
var (
|
||||
agentToDatabaseOnce sync.Once
|
||||
singletonAgentToDb *AgentToDatabaseImpl
|
||||
)
|
||||
|
||||
type AgentToDatabaseImpl struct {
|
||||
IDGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewAgentToDatabaseDAO(db *gorm.DB, idGen idgen.IDGenerator) *AgentToDatabaseImpl {
|
||||
agentToDatabaseOnce.Do(func() {
|
||||
singletonAgentToDb = &AgentToDatabaseImpl{
|
||||
IDGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
})
|
||||
|
||||
return singletonAgentToDb
|
||||
}
|
||||
|
||||
func (d *AgentToDatabaseImpl) BatchCreate(ctx context.Context, relations []*database.AgentToDatabase) ([]int64, error) {
|
||||
if len(relations) == 0 {
|
||||
return []int64{}, nil
|
||||
}
|
||||
|
||||
ids, err := d.IDGen.GenMultiIDs(ctx, len(relations))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("generate IDs failed: %v", err)
|
||||
}
|
||||
|
||||
agentToDbs := make([]*model.AgentToDatabase, len(relations))
|
||||
for i, relation := range relations {
|
||||
agentToDbs[i] = &model.AgentToDatabase{
|
||||
ID: ids[i],
|
||||
AgentID: relation.AgentID,
|
||||
DatabaseID: relation.DatabaseID,
|
||||
IsDraft: relation.TableType == table.TableType_DraftTable,
|
||||
PromptDisable: relation.PromptDisabled,
|
||||
}
|
||||
}
|
||||
|
||||
res := d.query.AgentToDatabase
|
||||
err = res.WithContext(ctx).CreateInBatches(agentToDbs, 10)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("batch create agent to database relations failed: %v", err)
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (d *AgentToDatabaseImpl) BatchDelete(ctx context.Context, basicRelations []*database.AgentToDatabaseBasic) error {
|
||||
if len(basicRelations) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
res := d.query.AgentToDatabase
|
||||
|
||||
for _, relation := range basicRelations {
|
||||
q := res.WithContext(ctx).
|
||||
Where(res.AgentID.Eq(relation.AgentID)).
|
||||
Where(res.DatabaseID.Eq(relation.DatabaseID))
|
||||
|
||||
_, err := q.Delete()
|
||||
if err != nil {
|
||||
return fmt.Errorf("delete relation failed for agent=%d, database=%d: %v",
|
||||
relation.AgentID, relation.DatabaseID, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *AgentToDatabaseImpl) ListByAgentID(ctx context.Context, agentID int64, tableType table.TableType) ([]*database.AgentToDatabase, error) {
|
||||
res := d.query.AgentToDatabase
|
||||
|
||||
q := res.WithContext(ctx).Where(res.AgentID.Eq(agentID))
|
||||
|
||||
if tableType == table.TableType_DraftTable {
|
||||
q = q.Where(res.IsDraft.Is(true))
|
||||
} else {
|
||||
q = q.Where(res.IsDraft.Is(false))
|
||||
}
|
||||
|
||||
records, err := q.Find()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list agent to database relations failed: %v", err)
|
||||
}
|
||||
|
||||
relations := make([]*database.AgentToDatabase, 0, len(records))
|
||||
for _, info := range records {
|
||||
tType := table.TableType_OnlineTable
|
||||
if info.IsDraft {
|
||||
tType = table.TableType_DraftTable
|
||||
}
|
||||
relation := &database.AgentToDatabase{
|
||||
AgentID: info.AgentID,
|
||||
DatabaseID: info.DatabaseID,
|
||||
TableType: tType,
|
||||
PromptDisabled: info.PromptDisable,
|
||||
}
|
||||
relations = append(relations, relation)
|
||||
}
|
||||
|
||||
return relations, nil
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* 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"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/table"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
var (
|
||||
draftOnce sync.Once
|
||||
singletonDraft *DraftImpl
|
||||
)
|
||||
|
||||
type DraftImpl struct {
|
||||
IDGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewDraftDatabaseDAO(db *gorm.DB, idGen idgen.IDGenerator) *DraftImpl {
|
||||
draftOnce.Do(func() {
|
||||
singletonDraft = &DraftImpl{
|
||||
IDGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
})
|
||||
|
||||
return singletonDraft
|
||||
}
|
||||
|
||||
func (d *DraftImpl) CreateWithTX(ctx context.Context, tx *query.QueryTx, database *entity.Database, draftID, onlineID int64, physicalTableName string) (*entity.Database, error) {
|
||||
now := time.Now().UnixMilli()
|
||||
|
||||
draftInfo := &model.DraftDatabaseInfo{
|
||||
ID: draftID,
|
||||
AppID: database.AppID,
|
||||
SpaceID: database.SpaceID,
|
||||
RelatedOnlineID: onlineID,
|
||||
IsVisible: 1, // 默认可见
|
||||
PromptDisabled: func() int32 {
|
||||
if database.PromptDisabled {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}(),
|
||||
TableName_: database.TableName,
|
||||
TableDesc: database.TableDesc,
|
||||
TableField: database.FieldList,
|
||||
CreatorID: database.CreatorID,
|
||||
IconURI: database.IconURI,
|
||||
PhysicalTableName: physicalTableName,
|
||||
RwMode: int64(database.RwMode),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
table := tx.DraftDatabaseInfo
|
||||
|
||||
err := table.WithContext(ctx).Create(draftInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
database.CreatedAtMs = now
|
||||
database.UpdatedAtMs = now
|
||||
|
||||
return database, nil
|
||||
}
|
||||
|
||||
// Get 获取草稿数据库信息
|
||||
func (d *DraftImpl) Get(ctx context.Context, id int64) (*entity.Database, error) {
|
||||
res := d.query.DraftDatabaseInfo
|
||||
|
||||
info, err := res.WithContext(ctx).Where(res.ID.Eq(id)).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.New(errno.ErrMemoryDatabaseNotFoundCode)
|
||||
}
|
||||
return nil, fmt.Errorf("query draft database failed: %v", err)
|
||||
}
|
||||
|
||||
// 构建返回的数据库对象
|
||||
db := &entity.Database{
|
||||
ID: info.ID,
|
||||
SpaceID: info.SpaceID,
|
||||
CreatorID: info.CreatorID,
|
||||
IconURI: info.IconURI,
|
||||
|
||||
AppID: info.AppID,
|
||||
IsVisible: info.IsVisible == 1,
|
||||
PromptDisabled: info.PromptDisabled == 1,
|
||||
TableName: info.TableName_,
|
||||
TableDesc: info.TableDesc,
|
||||
FieldList: info.TableField,
|
||||
Status: table.BotTableStatus_Online,
|
||||
ActualTableName: info.PhysicalTableName,
|
||||
RwMode: table.BotTableRWMode(info.RwMode),
|
||||
OnlineID: &info.RelatedOnlineID,
|
||||
DraftID: &info.ID,
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func (d *DraftImpl) MGet(ctx context.Context, ids []int64) ([]*entity.Database, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*entity.Database{}, nil
|
||||
}
|
||||
|
||||
res := d.query.DraftDatabaseInfo
|
||||
|
||||
records, err := res.WithContext(ctx).
|
||||
Where(res.ID.In(ids...)).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("batch query draft database failed: %v", err)
|
||||
}
|
||||
|
||||
databases := make([]*entity.Database, 0, len(records))
|
||||
for _, info := range records {
|
||||
|
||||
db := &entity.Database{
|
||||
ID: info.ID,
|
||||
SpaceID: info.SpaceID,
|
||||
CreatorID: info.CreatorID,
|
||||
IconURI: info.IconURI,
|
||||
|
||||
AppID: info.AppID,
|
||||
IsVisible: info.IsVisible == 1,
|
||||
PromptDisabled: info.PromptDisabled == 1,
|
||||
TableName: info.TableName_,
|
||||
TableDesc: info.TableDesc,
|
||||
FieldList: info.TableField,
|
||||
Status: table.BotTableStatus_Online,
|
||||
ActualTableName: info.PhysicalTableName,
|
||||
RwMode: table.BotTableRWMode(info.RwMode),
|
||||
OnlineID: &info.RelatedOnlineID,
|
||||
DraftID: &info.ID,
|
||||
|
||||
CreatedAtMs: info.CreatedAt,
|
||||
UpdatedAtMs: info.UpdatedAt,
|
||||
}
|
||||
|
||||
databases = append(databases, db)
|
||||
}
|
||||
|
||||
return databases, nil
|
||||
}
|
||||
|
||||
// UpdateWithTX 使用事务更新草稿数据库信息
|
||||
func (d *DraftImpl) UpdateWithTX(ctx context.Context, tx *query.QueryTx, database *entity.Database) (*entity.Database, error) {
|
||||
fieldJson, err := json.Marshal(database.FieldList)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal field list failed: %v", err)
|
||||
}
|
||||
|
||||
fieldJsonStr := string(fieldJson)
|
||||
now := time.Now().UnixMilli()
|
||||
|
||||
updates := map[string]interface{}{
|
||||
"app_id": database.AppID,
|
||||
"table_name": database.TableName,
|
||||
"table_desc": database.TableDesc,
|
||||
"table_field": fieldJsonStr,
|
||||
"icon_uri": database.IconURI,
|
||||
"prompt_disabled": func() int32 {
|
||||
if database.PromptDisabled {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}(),
|
||||
"rw_mode": int64(database.RwMode),
|
||||
"updated_at": now,
|
||||
}
|
||||
|
||||
// 执行更新
|
||||
res := tx.DraftDatabaseInfo
|
||||
_, err = res.WithContext(ctx).Where(res.ID.Eq(database.ID)).Updates(updates)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update draft database failed: %v", err)
|
||||
}
|
||||
|
||||
database.UpdatedAtMs = now
|
||||
return database, nil
|
||||
}
|
||||
|
||||
func (d *DraftImpl) DeleteWithTX(ctx context.Context, tx *query.QueryTx, id int64) error {
|
||||
res := tx.DraftDatabaseInfo
|
||||
_, err := res.WithContext(ctx).Where(res.ID.Eq(id)).Delete(&model.DraftDatabaseInfo{})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errorx.New(errno.ErrMemoryDatabaseNotFoundCode)
|
||||
}
|
||||
return fmt.Errorf("delete draft database failed: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// List 列出符合条件的数据库信息
|
||||
func (d *DraftImpl) List(ctx context.Context, filter *entity.DatabaseFilter, page *entity.Pagination, orderBy []*database.OrderBy) ([]*entity.Database, int64, error) {
|
||||
res := d.query.DraftDatabaseInfo
|
||||
|
||||
q := res.WithContext(ctx)
|
||||
|
||||
// 添加过滤条件
|
||||
if filter != nil {
|
||||
if filter.CreatorID != nil {
|
||||
q = q.Where(res.CreatorID.Eq(*filter.CreatorID))
|
||||
}
|
||||
|
||||
if filter.SpaceID != nil {
|
||||
q = q.Where(res.SpaceID.Eq(*filter.SpaceID))
|
||||
}
|
||||
|
||||
if filter.AppID != nil {
|
||||
q = q.Where(res.AppID.Eq(*filter.AppID))
|
||||
}
|
||||
|
||||
if filter.TableName != nil {
|
||||
q = q.Where(res.TableName_.Like("%" + *filter.TableName + "%"))
|
||||
}
|
||||
|
||||
q = q.Where(res.IsVisible.Eq(1))
|
||||
}
|
||||
|
||||
count, err := q.Count()
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("count online database failed: %v", err)
|
||||
}
|
||||
|
||||
limit := int64(50)
|
||||
if page != nil && page.Limit > 0 {
|
||||
limit = int64(page.Limit)
|
||||
}
|
||||
|
||||
offset := 0
|
||||
if page != nil && page.Offset > 0 {
|
||||
offset = page.Offset
|
||||
}
|
||||
|
||||
if len(orderBy) > 0 {
|
||||
for _, order := range orderBy {
|
||||
switch order.Field {
|
||||
case "created_at":
|
||||
if order.Direction == table.SortDirection_Desc {
|
||||
q = q.Order(res.CreatedAt.Desc())
|
||||
} else {
|
||||
q = q.Order(res.CreatedAt)
|
||||
}
|
||||
case "updated_at":
|
||||
if order.Direction == table.SortDirection_Desc {
|
||||
q = q.Order(res.UpdatedAt.Desc())
|
||||
} else {
|
||||
q = q.Order(res.UpdatedAt)
|
||||
}
|
||||
default:
|
||||
q = q.Order(res.CreatedAt.Desc())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
q = q.Order(res.CreatedAt.Desc())
|
||||
}
|
||||
|
||||
records, err := q.Limit(int(limit)).Offset(offset).Find()
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("list online database failed: %v", err)
|
||||
}
|
||||
|
||||
databases := make([]*entity.Database, 0, len(records))
|
||||
for _, info := range records {
|
||||
db := &entity.Database{
|
||||
ID: info.ID,
|
||||
SpaceID: info.SpaceID,
|
||||
CreatorID: info.CreatorID,
|
||||
IconURI: info.IconURI,
|
||||
|
||||
AppID: info.AppID,
|
||||
IsVisible: info.IsVisible == 1,
|
||||
PromptDisabled: info.PromptDisabled == 1,
|
||||
TableName: info.TableName_,
|
||||
TableDesc: info.TableDesc,
|
||||
FieldList: info.TableField,
|
||||
Status: table.BotTableStatus_Online,
|
||||
ActualTableName: info.PhysicalTableName,
|
||||
RwMode: table.BotTableRWMode(info.RwMode),
|
||||
TableType: ptr.Of(table.TableType_DraftTable),
|
||||
OnlineID: &info.RelatedOnlineID,
|
||||
DraftID: &info.ID,
|
||||
}
|
||||
|
||||
databases = append(databases, db)
|
||||
}
|
||||
|
||||
return databases, count, nil
|
||||
}
|
||||
|
||||
func (d *DraftImpl) BatchDeleteWithTX(ctx context.Context, tx *query.QueryTx, ids []int64) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
res := tx.DraftDatabaseInfo
|
||||
_, err := res.WithContext(ctx).Where(res.ID.In(ids...)).Delete()
|
||||
if err != nil {
|
||||
return fmt.Errorf("batch delete draft database failed: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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
|
||||
|
||||
const TableNameAgentToDatabase = "agent_to_database"
|
||||
|
||||
// AgentToDatabase agent_to_database info
|
||||
type AgentToDatabase struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:ID" json:"id"` // ID
|
||||
AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID
|
||||
DatabaseID int64 `gorm:"column:database_id;not null;comment:ID of database_info" json:"database_id"` // ID of database_info
|
||||
IsDraft bool `gorm:"column:is_draft;not null;comment:Is draft" json:"is_draft"` // Is draft
|
||||
PromptDisable bool `gorm:"column:prompt_disable;not null;comment:Support prompt calls: 1 not supported, 0 supported" json:"prompt_disable"` // Support prompt calls: 1 not supported, 0 supported
|
||||
}
|
||||
|
||||
// TableName AgentToDatabase's table name
|
||||
func (*AgentToDatabase) TableName() string {
|
||||
return TableNameAgentToDatabase
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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/database"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameDraftDatabaseInfo = "draft_database_info"
|
||||
|
||||
// DraftDatabaseInfo draft database info
|
||||
type DraftDatabaseInfo struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:ID" json:"id"` // ID
|
||||
AppID int64 `gorm:"column:app_id;comment:App ID" json:"app_id"` // App ID
|
||||
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
|
||||
RelatedOnlineID int64 `gorm:"column:related_online_id;not null;comment:The primary key ID of online_database_info table" json:"related_online_id"` // The primary key ID of online_database_info table
|
||||
IsVisible int32 `gorm:"column:is_visible;not null;default:1;comment:Visibility: 0 invisible, 1 visible" json:"is_visible"` // Visibility: 0 invisible, 1 visible
|
||||
PromptDisabled int32 `gorm:"column:prompt_disabled;not null;comment:Support prompt calls: 1 not supported, 0 supported" json:"prompt_disabled"` // Support prompt calls: 1 not supported, 0 supported
|
||||
TableName_ string `gorm:"column:table_name;not null;comment:Table name" json:"table_name"` // Table name
|
||||
TableDesc string `gorm:"column:table_desc;comment:Table description" json:"table_desc"` // Table description
|
||||
TableField []*database.FieldItem `gorm:"column:table_field;comment:Table field info;serializer:json" json:"table_field"` // Table field info
|
||||
CreatorID int64 `gorm:"column:creator_id;not null;comment:Creator ID" json:"creator_id"` // Creator ID
|
||||
IconURI string `gorm:"column:icon_uri;not null;comment:Icon Uri" json:"icon_uri"` // Icon Uri
|
||||
PhysicalTableName string `gorm:"column:physical_table_name;comment:The name of the real physical table" json:"physical_table_name"` // The name of the real physical table
|
||||
RwMode int64 `gorm:"column:rw_mode;not null;default:1;comment:Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode" json:"rw_mode"` // Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode
|
||||
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 DraftDatabaseInfo's table name
|
||||
func (*DraftDatabaseInfo) TableName() string {
|
||||
return TableNameDraftDatabaseInfo
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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/database"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameOnlineDatabaseInfo = "online_database_info"
|
||||
|
||||
// OnlineDatabaseInfo online database info
|
||||
type OnlineDatabaseInfo struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:ID" json:"id"` // ID
|
||||
AppID int64 `gorm:"column:app_id;comment:App ID" json:"app_id"` // App ID
|
||||
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
|
||||
RelatedDraftID int64 `gorm:"column:related_draft_id;not null;comment:The primary key ID of draft_database_info table" json:"related_draft_id"` // The primary key ID of draft_database_info table
|
||||
IsVisible int32 `gorm:"column:is_visible;not null;default:1;comment:Visibility: 0 invisible, 1 visible" json:"is_visible"` // Visibility: 0 invisible, 1 visible
|
||||
PromptDisabled int32 `gorm:"column:prompt_disabled;not null;comment:Support prompt calls: 1 not supported, 0 supported" json:"prompt_disabled"` // Support prompt calls: 1 not supported, 0 supported
|
||||
TableName_ string `gorm:"column:table_name;not null;comment:Table name" json:"table_name"` // Table name
|
||||
TableDesc string `gorm:"column:table_desc;comment:Table description" json:"table_desc"` // Table description
|
||||
TableField []*database.FieldItem `gorm:"column:table_field;comment:Table field info;serializer:json" json:"table_field"` // Table field info
|
||||
CreatorID int64 `gorm:"column:creator_id;not null;comment:Creator ID" json:"creator_id"` // Creator ID
|
||||
IconURI string `gorm:"column:icon_uri;not null;comment:Icon Uri" json:"icon_uri"` // Icon Uri
|
||||
PhysicalTableName string `gorm:"column:physical_table_name;comment:The name of the real physical table" json:"physical_table_name"` // The name of the real physical table
|
||||
RwMode int64 `gorm:"column:rw_mode;not null;default:1;comment:Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode" json:"rw_mode"` // Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode
|
||||
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 OnlineDatabaseInfo's table name
|
||||
func (*OnlineDatabaseInfo) TableName() string {
|
||||
return TableNameOnlineDatabaseInfo
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* 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"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/table"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/memory/database/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
var (
|
||||
onlineOnce sync.Once
|
||||
singletonOnline *OlineImpl
|
||||
)
|
||||
|
||||
type OlineImpl struct {
|
||||
IDGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewOnlineDatabaseDAO(db *gorm.DB, idGen idgen.IDGenerator) *OlineImpl {
|
||||
onlineOnce.Do(func() {
|
||||
singletonOnline = &OlineImpl{
|
||||
IDGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
})
|
||||
|
||||
return singletonOnline
|
||||
}
|
||||
|
||||
func (o *OlineImpl) CreateWithTX(ctx context.Context, tx *query.QueryTx, database *entity.Database, draftID, onlineID int64, physicalTableName string) (*entity.Database, error) {
|
||||
now := time.Now().UnixMilli()
|
||||
onlineInfo := &model.OnlineDatabaseInfo{
|
||||
ID: onlineID,
|
||||
AppID: database.AppID,
|
||||
SpaceID: database.SpaceID,
|
||||
RelatedDraftID: draftID,
|
||||
IsVisible: 1, // 默认可见
|
||||
PromptDisabled: func() int32 {
|
||||
if database.PromptDisabled {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}(),
|
||||
TableName_: database.TableName,
|
||||
TableDesc: database.TableDesc,
|
||||
TableField: database.FieldList,
|
||||
CreatorID: database.CreatorID,
|
||||
IconURI: database.IconURI,
|
||||
PhysicalTableName: physicalTableName,
|
||||
RwMode: int64(database.RwMode),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
table := tx.OnlineDatabaseInfo
|
||||
|
||||
err := table.WithContext(ctx).Create(onlineInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
database.CreatedAtMs = now
|
||||
database.UpdatedAtMs = now
|
||||
|
||||
return database, nil
|
||||
}
|
||||
|
||||
// Get 获取线上数据库信息
|
||||
func (o *OlineImpl) Get(ctx context.Context, id int64) (*entity.Database, error) {
|
||||
res := o.query.OnlineDatabaseInfo
|
||||
|
||||
info, err := res.WithContext(ctx).Where(res.ID.Eq(id)).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.New(errno.ErrMemoryDatabaseNotFoundCode)
|
||||
}
|
||||
return nil, fmt.Errorf("query online database failed: %v", err)
|
||||
}
|
||||
|
||||
db := &entity.Database{
|
||||
ID: info.ID,
|
||||
SpaceID: info.SpaceID,
|
||||
CreatorID: info.CreatorID,
|
||||
IconURI: info.IconURI,
|
||||
|
||||
AppID: info.AppID,
|
||||
DraftID: &info.RelatedDraftID,
|
||||
OnlineID: &info.ID,
|
||||
IsVisible: info.IsVisible == 1,
|
||||
PromptDisabled: info.PromptDisabled == 1,
|
||||
TableName: info.TableName_,
|
||||
TableDesc: info.TableDesc,
|
||||
FieldList: info.TableField,
|
||||
Status: table.BotTableStatus_Online,
|
||||
ActualTableName: info.PhysicalTableName,
|
||||
RwMode: table.BotTableRWMode(info.RwMode),
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// UpdateWithTX 使用事务更新线上数据库信息
|
||||
func (o *OlineImpl) UpdateWithTX(ctx context.Context, tx *query.QueryTx, database *entity.Database) (*entity.Database, error) {
|
||||
fieldJson, err := json.Marshal(database.FieldList)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal field list failed: %v", err)
|
||||
}
|
||||
|
||||
fieldJsonStr := string(fieldJson)
|
||||
now := time.Now().UnixMilli()
|
||||
|
||||
// 构建更新内容
|
||||
updates := map[string]interface{}{
|
||||
"app_id": database.AppID,
|
||||
"table_name": database.TableName,
|
||||
"table_desc": database.TableDesc,
|
||||
"table_field": fieldJsonStr,
|
||||
"icon_uri": database.IconURI,
|
||||
"prompt_disabled": func() int32 {
|
||||
if database.PromptDisabled {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}(),
|
||||
"rw_mode": int64(database.RwMode),
|
||||
"updated_at": now,
|
||||
}
|
||||
|
||||
// 执行更新
|
||||
res := tx.OnlineDatabaseInfo
|
||||
_, err = res.WithContext(ctx).Where(res.ID.Eq(database.ID)).Updates(updates)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update online database failed: %v", err)
|
||||
}
|
||||
|
||||
_, err = res.WithContext(ctx).Where(res.ID.In(database.ID)).Updates(updates)
|
||||
|
||||
database.UpdatedAtMs = now
|
||||
return database, nil
|
||||
}
|
||||
|
||||
func (o *OlineImpl) DeleteWithTX(ctx context.Context, tx *query.QueryTx, id int64) error {
|
||||
res := tx.OnlineDatabaseInfo
|
||||
_, err := res.WithContext(ctx).Where(res.ID.Eq(id)).Delete(&model.OnlineDatabaseInfo{})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errorx.New(errno.ErrMemoryDatabaseNotFoundCode)
|
||||
}
|
||||
return fmt.Errorf("delete online database failed: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MGet 批量获取在线数据库信息
|
||||
func (o *OlineImpl) MGet(ctx context.Context, ids []int64) ([]*entity.Database, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*entity.Database{}, nil
|
||||
}
|
||||
|
||||
res := o.query.OnlineDatabaseInfo
|
||||
|
||||
// 查询未删除的、ID在给定列表中的记录
|
||||
records, err := res.WithContext(ctx).
|
||||
Where(res.ID.In(ids...)).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("batch query online database failed: %v", err)
|
||||
}
|
||||
|
||||
// 构建返回结果
|
||||
databases := make([]*entity.Database, 0, len(records))
|
||||
for _, info := range records {
|
||||
db := &entity.Database{
|
||||
ID: info.ID,
|
||||
SpaceID: info.SpaceID,
|
||||
CreatorID: info.CreatorID,
|
||||
IconURI: info.IconURI,
|
||||
|
||||
AppID: info.AppID,
|
||||
DraftID: &info.RelatedDraftID,
|
||||
OnlineID: &info.ID,
|
||||
IsVisible: info.IsVisible == 1,
|
||||
PromptDisabled: info.PromptDisabled == 1,
|
||||
TableName: info.TableName_,
|
||||
TableDesc: info.TableDesc,
|
||||
FieldList: info.TableField,
|
||||
Status: table.BotTableStatus_Online,
|
||||
ActualTableName: info.PhysicalTableName,
|
||||
RwMode: table.BotTableRWMode(info.RwMode),
|
||||
|
||||
CreatedAtMs: info.CreatedAt,
|
||||
UpdatedAtMs: info.UpdatedAt,
|
||||
}
|
||||
|
||||
databases = append(databases, db)
|
||||
}
|
||||
|
||||
return databases, nil
|
||||
}
|
||||
|
||||
// List 列出符合条件的数据库信息
|
||||
func (o *OlineImpl) List(ctx context.Context, filter *entity.DatabaseFilter, page *entity.Pagination, orderBy []*database.OrderBy) ([]*entity.Database, int64, error) {
|
||||
res := o.query.OnlineDatabaseInfo
|
||||
|
||||
// 构建基础查询
|
||||
q := res.WithContext(ctx)
|
||||
|
||||
// 添加过滤条件
|
||||
if filter != nil {
|
||||
if filter.CreatorID != nil {
|
||||
q = q.Where(res.CreatorID.Eq(*filter.CreatorID))
|
||||
}
|
||||
|
||||
if filter.SpaceID != nil {
|
||||
q = q.Where(res.SpaceID.Eq(*filter.SpaceID))
|
||||
}
|
||||
|
||||
if filter.AppID != nil {
|
||||
q = q.Where(res.AppID.Eq(*filter.AppID))
|
||||
}
|
||||
|
||||
if filter.TableName != nil {
|
||||
q = q.Where(res.TableName_.Like("%" + *filter.TableName + "%"))
|
||||
}
|
||||
|
||||
q = q.Where(res.IsVisible.Eq(1))
|
||||
}
|
||||
|
||||
count, err := q.Count()
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("count online database failed: %v", err)
|
||||
}
|
||||
|
||||
limit := int64(50) // default
|
||||
if page != nil && page.Limit > 0 {
|
||||
limit = int64(page.Limit)
|
||||
}
|
||||
|
||||
offset := 0
|
||||
if page != nil && page.Offset > 0 {
|
||||
offset = page.Offset
|
||||
}
|
||||
|
||||
// 处理排序
|
||||
if len(orderBy) > 0 {
|
||||
for _, order := range orderBy {
|
||||
switch order.Field {
|
||||
case "created_at":
|
||||
if order.Direction == table.SortDirection_Desc {
|
||||
q = q.Order(res.CreatedAt.Desc())
|
||||
} else {
|
||||
q = q.Order(res.CreatedAt)
|
||||
}
|
||||
case "updated_at":
|
||||
if order.Direction == table.SortDirection_Desc {
|
||||
q = q.Order(res.UpdatedAt.Desc())
|
||||
} else {
|
||||
q = q.Order(res.UpdatedAt)
|
||||
}
|
||||
default:
|
||||
q = q.Order(res.CreatedAt.Desc())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
q = q.Order(res.CreatedAt.Desc())
|
||||
}
|
||||
|
||||
records, err := q.Limit(int(limit)).Offset(offset).Find()
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("list online database failed: %v", err)
|
||||
}
|
||||
|
||||
databases := make([]*entity.Database, 0, len(records))
|
||||
for _, info := range records {
|
||||
d := &entity.Database{
|
||||
ID: info.ID,
|
||||
SpaceID: info.SpaceID,
|
||||
CreatorID: info.CreatorID,
|
||||
IconURI: info.IconURI,
|
||||
|
||||
AppID: info.AppID,
|
||||
DraftID: &info.RelatedDraftID,
|
||||
OnlineID: &info.ID,
|
||||
IsVisible: info.IsVisible == 1,
|
||||
PromptDisabled: info.PromptDisabled == 1,
|
||||
TableName: info.TableName_,
|
||||
TableDesc: info.TableDesc,
|
||||
FieldList: info.TableField,
|
||||
Status: table.BotTableStatus_Online,
|
||||
ActualTableName: info.PhysicalTableName,
|
||||
RwMode: table.BotTableRWMode(info.RwMode),
|
||||
TableType: ptr.Of(table.TableType_OnlineTable),
|
||||
}
|
||||
|
||||
databases = append(databases, d)
|
||||
}
|
||||
|
||||
return databases, count, nil
|
||||
}
|
||||
|
||||
func (o *OlineImpl) BatchDeleteWithTX(ctx context.Context, tx *query.QueryTx, ids []int64) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
res := tx.OnlineDatabaseInfo
|
||||
_, err := res.WithContext(ctx).Where(res.ID.In(ids...)).Delete()
|
||||
if err != nil {
|
||||
return fmt.Errorf("batch delete online database failed: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
// 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/memory/database/internal/dal/model"
|
||||
)
|
||||
|
||||
func newAgentToDatabase(db *gorm.DB, opts ...gen.DOOption) agentToDatabase {
|
||||
_agentToDatabase := agentToDatabase{}
|
||||
|
||||
_agentToDatabase.agentToDatabaseDo.UseDB(db, opts...)
|
||||
_agentToDatabase.agentToDatabaseDo.UseModel(&model.AgentToDatabase{})
|
||||
|
||||
tableName := _agentToDatabase.agentToDatabaseDo.TableName()
|
||||
_agentToDatabase.ALL = field.NewAsterisk(tableName)
|
||||
_agentToDatabase.ID = field.NewInt64(tableName, "id")
|
||||
_agentToDatabase.AgentID = field.NewInt64(tableName, "agent_id")
|
||||
_agentToDatabase.DatabaseID = field.NewInt64(tableName, "database_id")
|
||||
_agentToDatabase.IsDraft = field.NewBool(tableName, "is_draft")
|
||||
_agentToDatabase.PromptDisable = field.NewBool(tableName, "prompt_disable")
|
||||
|
||||
_agentToDatabase.fillFieldMap()
|
||||
|
||||
return _agentToDatabase
|
||||
}
|
||||
|
||||
// agentToDatabase agent_to_database info
|
||||
type agentToDatabase struct {
|
||||
agentToDatabaseDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // ID
|
||||
AgentID field.Int64 // Agent ID
|
||||
DatabaseID field.Int64 // ID of database_info
|
||||
IsDraft field.Bool // Is draft
|
||||
PromptDisable field.Bool // Support prompt calls: 1 not supported, 0 supported
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (a agentToDatabase) Table(newTableName string) *agentToDatabase {
|
||||
a.agentToDatabaseDo.UseTable(newTableName)
|
||||
return a.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (a agentToDatabase) As(alias string) *agentToDatabase {
|
||||
a.agentToDatabaseDo.DO = *(a.agentToDatabaseDo.As(alias).(*gen.DO))
|
||||
return a.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (a *agentToDatabase) updateTableName(table string) *agentToDatabase {
|
||||
a.ALL = field.NewAsterisk(table)
|
||||
a.ID = field.NewInt64(table, "id")
|
||||
a.AgentID = field.NewInt64(table, "agent_id")
|
||||
a.DatabaseID = field.NewInt64(table, "database_id")
|
||||
a.IsDraft = field.NewBool(table, "is_draft")
|
||||
a.PromptDisable = field.NewBool(table, "prompt_disable")
|
||||
|
||||
a.fillFieldMap()
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *agentToDatabase) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := a.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (a *agentToDatabase) fillFieldMap() {
|
||||
a.fieldMap = make(map[string]field.Expr, 5)
|
||||
a.fieldMap["id"] = a.ID
|
||||
a.fieldMap["agent_id"] = a.AgentID
|
||||
a.fieldMap["database_id"] = a.DatabaseID
|
||||
a.fieldMap["is_draft"] = a.IsDraft
|
||||
a.fieldMap["prompt_disable"] = a.PromptDisable
|
||||
}
|
||||
|
||||
func (a agentToDatabase) clone(db *gorm.DB) agentToDatabase {
|
||||
a.agentToDatabaseDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a agentToDatabase) replaceDB(db *gorm.DB) agentToDatabase {
|
||||
a.agentToDatabaseDo.ReplaceDB(db)
|
||||
return a
|
||||
}
|
||||
|
||||
type agentToDatabaseDo struct{ gen.DO }
|
||||
|
||||
type IAgentToDatabaseDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IAgentToDatabaseDo
|
||||
WithContext(ctx context.Context) IAgentToDatabaseDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IAgentToDatabaseDo
|
||||
WriteDB() IAgentToDatabaseDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IAgentToDatabaseDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IAgentToDatabaseDo
|
||||
Not(conds ...gen.Condition) IAgentToDatabaseDo
|
||||
Or(conds ...gen.Condition) IAgentToDatabaseDo
|
||||
Select(conds ...field.Expr) IAgentToDatabaseDo
|
||||
Where(conds ...gen.Condition) IAgentToDatabaseDo
|
||||
Order(conds ...field.Expr) IAgentToDatabaseDo
|
||||
Distinct(cols ...field.Expr) IAgentToDatabaseDo
|
||||
Omit(cols ...field.Expr) IAgentToDatabaseDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IAgentToDatabaseDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IAgentToDatabaseDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IAgentToDatabaseDo
|
||||
Group(cols ...field.Expr) IAgentToDatabaseDo
|
||||
Having(conds ...gen.Condition) IAgentToDatabaseDo
|
||||
Limit(limit int) IAgentToDatabaseDo
|
||||
Offset(offset int) IAgentToDatabaseDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IAgentToDatabaseDo
|
||||
Unscoped() IAgentToDatabaseDo
|
||||
Create(values ...*model.AgentToDatabase) error
|
||||
CreateInBatches(values []*model.AgentToDatabase, batchSize int) error
|
||||
Save(values ...*model.AgentToDatabase) error
|
||||
First() (*model.AgentToDatabase, error)
|
||||
Take() (*model.AgentToDatabase, error)
|
||||
Last() (*model.AgentToDatabase, error)
|
||||
Find() ([]*model.AgentToDatabase, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AgentToDatabase, err error)
|
||||
FindInBatches(result *[]*model.AgentToDatabase, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.AgentToDatabase) (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) IAgentToDatabaseDo
|
||||
Assign(attrs ...field.AssignExpr) IAgentToDatabaseDo
|
||||
Joins(fields ...field.RelationField) IAgentToDatabaseDo
|
||||
Preload(fields ...field.RelationField) IAgentToDatabaseDo
|
||||
FirstOrInit() (*model.AgentToDatabase, error)
|
||||
FirstOrCreate() (*model.AgentToDatabase, error)
|
||||
FindByPage(offset int, limit int) (result []*model.AgentToDatabase, 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) IAgentToDatabaseDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Debug() IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Debug())
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) WithContext(ctx context.Context) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) ReadDB() IAgentToDatabaseDo {
|
||||
return a.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) WriteDB() IAgentToDatabaseDo {
|
||||
return a.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Session(config *gorm.Session) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Session(config))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Clauses(conds ...clause.Expression) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Returning(value interface{}, columns ...string) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Not(conds ...gen.Condition) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Or(conds ...gen.Condition) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Select(conds ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Where(conds ...gen.Condition) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Order(conds ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Distinct(cols ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Omit(cols ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Join(table schema.Tabler, on ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) RightJoin(table schema.Tabler, on ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Group(cols ...field.Expr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Having(conds ...gen.Condition) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Limit(limit int) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Offset(offset int) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Unscoped() IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Create(values ...*model.AgentToDatabase) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Create(values)
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) CreateInBatches(values []*model.AgentToDatabase, batchSize int) error {
|
||||
return a.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 (a agentToDatabaseDo) Save(values ...*model.AgentToDatabase) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Save(values)
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) First() (*model.AgentToDatabase, error) {
|
||||
if result, err := a.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToDatabase), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Take() (*model.AgentToDatabase, error) {
|
||||
if result, err := a.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToDatabase), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Last() (*model.AgentToDatabase, error) {
|
||||
if result, err := a.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToDatabase), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Find() ([]*model.AgentToDatabase, error) {
|
||||
result, err := a.DO.Find()
|
||||
return result.([]*model.AgentToDatabase), err
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AgentToDatabase, err error) {
|
||||
buf := make([]*model.AgentToDatabase, 0, batchSize)
|
||||
err = a.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 (a agentToDatabaseDo) FindInBatches(result *[]*model.AgentToDatabase, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return a.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Attrs(attrs ...field.AssignExpr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Assign(attrs ...field.AssignExpr) IAgentToDatabaseDo {
|
||||
return a.withDO(a.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Joins(fields ...field.RelationField) IAgentToDatabaseDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Joins(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Preload(fields ...field.RelationField) IAgentToDatabaseDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Preload(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) FirstOrInit() (*model.AgentToDatabase, error) {
|
||||
if result, err := a.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToDatabase), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) FirstOrCreate() (*model.AgentToDatabase, error) {
|
||||
if result, err := a.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToDatabase), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) FindByPage(offset int, limit int) (result []*model.AgentToDatabase, count int64, err error) {
|
||||
result, err = a.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 = a.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = a.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = a.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Scan(result interface{}) (err error) {
|
||||
return a.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (a agentToDatabaseDo) Delete(models ...*model.AgentToDatabase) (result gen.ResultInfo, err error) {
|
||||
return a.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (a *agentToDatabaseDo) withDO(do gen.Dao) *agentToDatabaseDo {
|
||||
a.DO = *do.(*gen.DO)
|
||||
return a
|
||||
}
|
||||
@@ -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/memory/database/internal/dal/model"
|
||||
)
|
||||
|
||||
func newDraftDatabaseInfo(db *gorm.DB, opts ...gen.DOOption) draftDatabaseInfo {
|
||||
_draftDatabaseInfo := draftDatabaseInfo{}
|
||||
|
||||
_draftDatabaseInfo.draftDatabaseInfoDo.UseDB(db, opts...)
|
||||
_draftDatabaseInfo.draftDatabaseInfoDo.UseModel(&model.DraftDatabaseInfo{})
|
||||
|
||||
tableName := _draftDatabaseInfo.draftDatabaseInfoDo.TableName()
|
||||
_draftDatabaseInfo.ALL = field.NewAsterisk(tableName)
|
||||
_draftDatabaseInfo.ID = field.NewInt64(tableName, "id")
|
||||
_draftDatabaseInfo.AppID = field.NewInt64(tableName, "app_id")
|
||||
_draftDatabaseInfo.SpaceID = field.NewInt64(tableName, "space_id")
|
||||
_draftDatabaseInfo.RelatedOnlineID = field.NewInt64(tableName, "related_online_id")
|
||||
_draftDatabaseInfo.IsVisible = field.NewInt32(tableName, "is_visible")
|
||||
_draftDatabaseInfo.PromptDisabled = field.NewInt32(tableName, "prompt_disabled")
|
||||
_draftDatabaseInfo.TableName_ = field.NewString(tableName, "table_name")
|
||||
_draftDatabaseInfo.TableDesc = field.NewString(tableName, "table_desc")
|
||||
_draftDatabaseInfo.TableField = field.NewField(tableName, "table_field")
|
||||
_draftDatabaseInfo.CreatorID = field.NewInt64(tableName, "creator_id")
|
||||
_draftDatabaseInfo.IconURI = field.NewString(tableName, "icon_uri")
|
||||
_draftDatabaseInfo.PhysicalTableName = field.NewString(tableName, "physical_table_name")
|
||||
_draftDatabaseInfo.RwMode = field.NewInt64(tableName, "rw_mode")
|
||||
_draftDatabaseInfo.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_draftDatabaseInfo.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_draftDatabaseInfo.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_draftDatabaseInfo.fillFieldMap()
|
||||
|
||||
return _draftDatabaseInfo
|
||||
}
|
||||
|
||||
// draftDatabaseInfo draft database info
|
||||
type draftDatabaseInfo struct {
|
||||
draftDatabaseInfoDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // ID
|
||||
AppID field.Int64 // App ID
|
||||
SpaceID field.Int64 // Space ID
|
||||
RelatedOnlineID field.Int64 // The primary key ID of online_database_info table
|
||||
IsVisible field.Int32 // Visibility: 0 invisible, 1 visible
|
||||
PromptDisabled field.Int32 // Support prompt calls: 1 not supported, 0 supported
|
||||
TableName_ field.String // Table name
|
||||
TableDesc field.String // Table description
|
||||
TableField field.Field // Table field info
|
||||
CreatorID field.Int64 // Creator ID
|
||||
IconURI field.String // Icon Uri
|
||||
PhysicalTableName field.String // The name of the real physical table
|
||||
RwMode field.Int64 // Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode
|
||||
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 (d draftDatabaseInfo) Table(newTableName string) *draftDatabaseInfo {
|
||||
d.draftDatabaseInfoDo.UseTable(newTableName)
|
||||
return d.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfo) As(alias string) *draftDatabaseInfo {
|
||||
d.draftDatabaseInfoDo.DO = *(d.draftDatabaseInfoDo.As(alias).(*gen.DO))
|
||||
return d.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (d *draftDatabaseInfo) updateTableName(table string) *draftDatabaseInfo {
|
||||
d.ALL = field.NewAsterisk(table)
|
||||
d.ID = field.NewInt64(table, "id")
|
||||
d.AppID = field.NewInt64(table, "app_id")
|
||||
d.SpaceID = field.NewInt64(table, "space_id")
|
||||
d.RelatedOnlineID = field.NewInt64(table, "related_online_id")
|
||||
d.IsVisible = field.NewInt32(table, "is_visible")
|
||||
d.PromptDisabled = field.NewInt32(table, "prompt_disabled")
|
||||
d.TableName_ = field.NewString(table, "table_name")
|
||||
d.TableDesc = field.NewString(table, "table_desc")
|
||||
d.TableField = field.NewField(table, "table_field")
|
||||
d.CreatorID = field.NewInt64(table, "creator_id")
|
||||
d.IconURI = field.NewString(table, "icon_uri")
|
||||
d.PhysicalTableName = field.NewString(table, "physical_table_name")
|
||||
d.RwMode = field.NewInt64(table, "rw_mode")
|
||||
d.CreatedAt = field.NewInt64(table, "created_at")
|
||||
d.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
d.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
d.fillFieldMap()
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *draftDatabaseInfo) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := d.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (d *draftDatabaseInfo) fillFieldMap() {
|
||||
d.fieldMap = make(map[string]field.Expr, 16)
|
||||
d.fieldMap["id"] = d.ID
|
||||
d.fieldMap["app_id"] = d.AppID
|
||||
d.fieldMap["space_id"] = d.SpaceID
|
||||
d.fieldMap["related_online_id"] = d.RelatedOnlineID
|
||||
d.fieldMap["is_visible"] = d.IsVisible
|
||||
d.fieldMap["prompt_disabled"] = d.PromptDisabled
|
||||
d.fieldMap["table_name"] = d.TableName_
|
||||
d.fieldMap["table_desc"] = d.TableDesc
|
||||
d.fieldMap["table_field"] = d.TableField
|
||||
d.fieldMap["creator_id"] = d.CreatorID
|
||||
d.fieldMap["icon_uri"] = d.IconURI
|
||||
d.fieldMap["physical_table_name"] = d.PhysicalTableName
|
||||
d.fieldMap["rw_mode"] = d.RwMode
|
||||
d.fieldMap["created_at"] = d.CreatedAt
|
||||
d.fieldMap["updated_at"] = d.UpdatedAt
|
||||
d.fieldMap["deleted_at"] = d.DeletedAt
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfo) clone(db *gorm.DB) draftDatabaseInfo {
|
||||
d.draftDatabaseInfoDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return d
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfo) replaceDB(db *gorm.DB) draftDatabaseInfo {
|
||||
d.draftDatabaseInfoDo.ReplaceDB(db)
|
||||
return d
|
||||
}
|
||||
|
||||
type draftDatabaseInfoDo struct{ gen.DO }
|
||||
|
||||
type IDraftDatabaseInfoDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IDraftDatabaseInfoDo
|
||||
WithContext(ctx context.Context) IDraftDatabaseInfoDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IDraftDatabaseInfoDo
|
||||
WriteDB() IDraftDatabaseInfoDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IDraftDatabaseInfoDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IDraftDatabaseInfoDo
|
||||
Not(conds ...gen.Condition) IDraftDatabaseInfoDo
|
||||
Or(conds ...gen.Condition) IDraftDatabaseInfoDo
|
||||
Select(conds ...field.Expr) IDraftDatabaseInfoDo
|
||||
Where(conds ...gen.Condition) IDraftDatabaseInfoDo
|
||||
Order(conds ...field.Expr) IDraftDatabaseInfoDo
|
||||
Distinct(cols ...field.Expr) IDraftDatabaseInfoDo
|
||||
Omit(cols ...field.Expr) IDraftDatabaseInfoDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IDraftDatabaseInfoDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IDraftDatabaseInfoDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IDraftDatabaseInfoDo
|
||||
Group(cols ...field.Expr) IDraftDatabaseInfoDo
|
||||
Having(conds ...gen.Condition) IDraftDatabaseInfoDo
|
||||
Limit(limit int) IDraftDatabaseInfoDo
|
||||
Offset(offset int) IDraftDatabaseInfoDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IDraftDatabaseInfoDo
|
||||
Unscoped() IDraftDatabaseInfoDo
|
||||
Create(values ...*model.DraftDatabaseInfo) error
|
||||
CreateInBatches(values []*model.DraftDatabaseInfo, batchSize int) error
|
||||
Save(values ...*model.DraftDatabaseInfo) error
|
||||
First() (*model.DraftDatabaseInfo, error)
|
||||
Take() (*model.DraftDatabaseInfo, error)
|
||||
Last() (*model.DraftDatabaseInfo, error)
|
||||
Find() ([]*model.DraftDatabaseInfo, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.DraftDatabaseInfo, err error)
|
||||
FindInBatches(result *[]*model.DraftDatabaseInfo, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.DraftDatabaseInfo) (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) IDraftDatabaseInfoDo
|
||||
Assign(attrs ...field.AssignExpr) IDraftDatabaseInfoDo
|
||||
Joins(fields ...field.RelationField) IDraftDatabaseInfoDo
|
||||
Preload(fields ...field.RelationField) IDraftDatabaseInfoDo
|
||||
FirstOrInit() (*model.DraftDatabaseInfo, error)
|
||||
FirstOrCreate() (*model.DraftDatabaseInfo, error)
|
||||
FindByPage(offset int, limit int) (result []*model.DraftDatabaseInfo, 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) IDraftDatabaseInfoDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Debug() IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Debug())
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) WithContext(ctx context.Context) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) ReadDB() IDraftDatabaseInfoDo {
|
||||
return d.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) WriteDB() IDraftDatabaseInfoDo {
|
||||
return d.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Session(config *gorm.Session) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Session(config))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Clauses(conds ...clause.Expression) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Returning(value interface{}, columns ...string) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Not(conds ...gen.Condition) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Or(conds ...gen.Condition) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Select(conds ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Where(conds ...gen.Condition) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Order(conds ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Distinct(cols ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Omit(cols ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Join(table schema.Tabler, on ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) LeftJoin(table schema.Tabler, on ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) RightJoin(table schema.Tabler, on ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Group(cols ...field.Expr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Having(conds ...gen.Condition) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Limit(limit int) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Offset(offset int) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Unscoped() IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Create(values ...*model.DraftDatabaseInfo) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return d.DO.Create(values)
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) CreateInBatches(values []*model.DraftDatabaseInfo, batchSize int) error {
|
||||
return d.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 (d draftDatabaseInfoDo) Save(values ...*model.DraftDatabaseInfo) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return d.DO.Save(values)
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) First() (*model.DraftDatabaseInfo, error) {
|
||||
if result, err := d.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.DraftDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Take() (*model.DraftDatabaseInfo, error) {
|
||||
if result, err := d.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.DraftDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Last() (*model.DraftDatabaseInfo, error) {
|
||||
if result, err := d.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.DraftDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Find() ([]*model.DraftDatabaseInfo, error) {
|
||||
result, err := d.DO.Find()
|
||||
return result.([]*model.DraftDatabaseInfo), err
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.DraftDatabaseInfo, err error) {
|
||||
buf := make([]*model.DraftDatabaseInfo, 0, batchSize)
|
||||
err = d.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 (d draftDatabaseInfoDo) FindInBatches(result *[]*model.DraftDatabaseInfo, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return d.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Attrs(attrs ...field.AssignExpr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Assign(attrs ...field.AssignExpr) IDraftDatabaseInfoDo {
|
||||
return d.withDO(d.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Joins(fields ...field.RelationField) IDraftDatabaseInfoDo {
|
||||
for _, _f := range fields {
|
||||
d = *d.withDO(d.DO.Joins(_f))
|
||||
}
|
||||
return &d
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Preload(fields ...field.RelationField) IDraftDatabaseInfoDo {
|
||||
for _, _f := range fields {
|
||||
d = *d.withDO(d.DO.Preload(_f))
|
||||
}
|
||||
return &d
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) FirstOrInit() (*model.DraftDatabaseInfo, error) {
|
||||
if result, err := d.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.DraftDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) FirstOrCreate() (*model.DraftDatabaseInfo, error) {
|
||||
if result, err := d.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.DraftDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) FindByPage(offset int, limit int) (result []*model.DraftDatabaseInfo, count int64, err error) {
|
||||
result, err = d.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 = d.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = d.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = d.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Scan(result interface{}) (err error) {
|
||||
return d.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (d draftDatabaseInfoDo) Delete(models ...*model.DraftDatabaseInfo) (result gen.ResultInfo, err error) {
|
||||
return d.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (d *draftDatabaseInfoDo) withDO(do gen.Dao) *draftDatabaseInfoDo {
|
||||
d.DO = *do.(*gen.DO)
|
||||
return d
|
||||
}
|
||||
119
backend/domain/memory/database/internal/dal/query/gen.go
Normal file
119
backend/domain/memory/database/internal/dal/query/gen.go
Normal file
@@ -0,0 +1,119 @@
|
||||
// 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)
|
||||
AgentToDatabase *agentToDatabase
|
||||
DraftDatabaseInfo *draftDatabaseInfo
|
||||
OnlineDatabaseInfo *onlineDatabaseInfo
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
AgentToDatabase = &Q.AgentToDatabase
|
||||
DraftDatabaseInfo = &Q.DraftDatabaseInfo
|
||||
OnlineDatabaseInfo = &Q.OnlineDatabaseInfo
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
AgentToDatabase: newAgentToDatabase(db, opts...),
|
||||
DraftDatabaseInfo: newDraftDatabaseInfo(db, opts...),
|
||||
OnlineDatabaseInfo: newOnlineDatabaseInfo(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
AgentToDatabase agentToDatabase
|
||||
DraftDatabaseInfo draftDatabaseInfo
|
||||
OnlineDatabaseInfo onlineDatabaseInfo
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
AgentToDatabase: q.AgentToDatabase.clone(db),
|
||||
DraftDatabaseInfo: q.DraftDatabaseInfo.clone(db),
|
||||
OnlineDatabaseInfo: q.OnlineDatabaseInfo.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,
|
||||
AgentToDatabase: q.AgentToDatabase.replaceDB(db),
|
||||
DraftDatabaseInfo: q.DraftDatabaseInfo.replaceDB(db),
|
||||
OnlineDatabaseInfo: q.OnlineDatabaseInfo.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
AgentToDatabase IAgentToDatabaseDo
|
||||
DraftDatabaseInfo IDraftDatabaseInfoDo
|
||||
OnlineDatabaseInfo IOnlineDatabaseInfoDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
AgentToDatabase: q.AgentToDatabase.WithContext(ctx),
|
||||
DraftDatabaseInfo: q.DraftDatabaseInfo.WithContext(ctx),
|
||||
OnlineDatabaseInfo: q.OnlineDatabaseInfo.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
|
||||
}
|
||||
@@ -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/memory/database/internal/dal/model"
|
||||
)
|
||||
|
||||
func newOnlineDatabaseInfo(db *gorm.DB, opts ...gen.DOOption) onlineDatabaseInfo {
|
||||
_onlineDatabaseInfo := onlineDatabaseInfo{}
|
||||
|
||||
_onlineDatabaseInfo.onlineDatabaseInfoDo.UseDB(db, opts...)
|
||||
_onlineDatabaseInfo.onlineDatabaseInfoDo.UseModel(&model.OnlineDatabaseInfo{})
|
||||
|
||||
tableName := _onlineDatabaseInfo.onlineDatabaseInfoDo.TableName()
|
||||
_onlineDatabaseInfo.ALL = field.NewAsterisk(tableName)
|
||||
_onlineDatabaseInfo.ID = field.NewInt64(tableName, "id")
|
||||
_onlineDatabaseInfo.AppID = field.NewInt64(tableName, "app_id")
|
||||
_onlineDatabaseInfo.SpaceID = field.NewInt64(tableName, "space_id")
|
||||
_onlineDatabaseInfo.RelatedDraftID = field.NewInt64(tableName, "related_draft_id")
|
||||
_onlineDatabaseInfo.IsVisible = field.NewInt32(tableName, "is_visible")
|
||||
_onlineDatabaseInfo.PromptDisabled = field.NewInt32(tableName, "prompt_disabled")
|
||||
_onlineDatabaseInfo.TableName_ = field.NewString(tableName, "table_name")
|
||||
_onlineDatabaseInfo.TableDesc = field.NewString(tableName, "table_desc")
|
||||
_onlineDatabaseInfo.TableField = field.NewField(tableName, "table_field")
|
||||
_onlineDatabaseInfo.CreatorID = field.NewInt64(tableName, "creator_id")
|
||||
_onlineDatabaseInfo.IconURI = field.NewString(tableName, "icon_uri")
|
||||
_onlineDatabaseInfo.PhysicalTableName = field.NewString(tableName, "physical_table_name")
|
||||
_onlineDatabaseInfo.RwMode = field.NewInt64(tableName, "rw_mode")
|
||||
_onlineDatabaseInfo.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_onlineDatabaseInfo.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_onlineDatabaseInfo.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_onlineDatabaseInfo.fillFieldMap()
|
||||
|
||||
return _onlineDatabaseInfo
|
||||
}
|
||||
|
||||
// onlineDatabaseInfo online database info
|
||||
type onlineDatabaseInfo struct {
|
||||
onlineDatabaseInfoDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // ID
|
||||
AppID field.Int64 // App ID
|
||||
SpaceID field.Int64 // Space ID
|
||||
RelatedDraftID field.Int64 // The primary key ID of draft_database_info table
|
||||
IsVisible field.Int32 // Visibility: 0 invisible, 1 visible
|
||||
PromptDisabled field.Int32 // Support prompt calls: 1 not supported, 0 supported
|
||||
TableName_ field.String // Table name
|
||||
TableDesc field.String // Table description
|
||||
TableField field.Field // Table field info
|
||||
CreatorID field.Int64 // Creator ID
|
||||
IconURI field.String // Icon Uri
|
||||
PhysicalTableName field.String // The name of the real physical table
|
||||
RwMode field.Int64 // Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode
|
||||
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 (o onlineDatabaseInfo) Table(newTableName string) *onlineDatabaseInfo {
|
||||
o.onlineDatabaseInfoDo.UseTable(newTableName)
|
||||
return o.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfo) As(alias string) *onlineDatabaseInfo {
|
||||
o.onlineDatabaseInfoDo.DO = *(o.onlineDatabaseInfoDo.As(alias).(*gen.DO))
|
||||
return o.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (o *onlineDatabaseInfo) updateTableName(table string) *onlineDatabaseInfo {
|
||||
o.ALL = field.NewAsterisk(table)
|
||||
o.ID = field.NewInt64(table, "id")
|
||||
o.AppID = field.NewInt64(table, "app_id")
|
||||
o.SpaceID = field.NewInt64(table, "space_id")
|
||||
o.RelatedDraftID = field.NewInt64(table, "related_draft_id")
|
||||
o.IsVisible = field.NewInt32(table, "is_visible")
|
||||
o.PromptDisabled = field.NewInt32(table, "prompt_disabled")
|
||||
o.TableName_ = field.NewString(table, "table_name")
|
||||
o.TableDesc = field.NewString(table, "table_desc")
|
||||
o.TableField = field.NewField(table, "table_field")
|
||||
o.CreatorID = field.NewInt64(table, "creator_id")
|
||||
o.IconURI = field.NewString(table, "icon_uri")
|
||||
o.PhysicalTableName = field.NewString(table, "physical_table_name")
|
||||
o.RwMode = field.NewInt64(table, "rw_mode")
|
||||
o.CreatedAt = field.NewInt64(table, "created_at")
|
||||
o.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
o.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
o.fillFieldMap()
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *onlineDatabaseInfo) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := o.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (o *onlineDatabaseInfo) fillFieldMap() {
|
||||
o.fieldMap = make(map[string]field.Expr, 16)
|
||||
o.fieldMap["id"] = o.ID
|
||||
o.fieldMap["app_id"] = o.AppID
|
||||
o.fieldMap["space_id"] = o.SpaceID
|
||||
o.fieldMap["related_draft_id"] = o.RelatedDraftID
|
||||
o.fieldMap["is_visible"] = o.IsVisible
|
||||
o.fieldMap["prompt_disabled"] = o.PromptDisabled
|
||||
o.fieldMap["table_name"] = o.TableName_
|
||||
o.fieldMap["table_desc"] = o.TableDesc
|
||||
o.fieldMap["table_field"] = o.TableField
|
||||
o.fieldMap["creator_id"] = o.CreatorID
|
||||
o.fieldMap["icon_uri"] = o.IconURI
|
||||
o.fieldMap["physical_table_name"] = o.PhysicalTableName
|
||||
o.fieldMap["rw_mode"] = o.RwMode
|
||||
o.fieldMap["created_at"] = o.CreatedAt
|
||||
o.fieldMap["updated_at"] = o.UpdatedAt
|
||||
o.fieldMap["deleted_at"] = o.DeletedAt
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfo) clone(db *gorm.DB) onlineDatabaseInfo {
|
||||
o.onlineDatabaseInfoDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfo) replaceDB(db *gorm.DB) onlineDatabaseInfo {
|
||||
o.onlineDatabaseInfoDo.ReplaceDB(db)
|
||||
return o
|
||||
}
|
||||
|
||||
type onlineDatabaseInfoDo struct{ gen.DO }
|
||||
|
||||
type IOnlineDatabaseInfoDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IOnlineDatabaseInfoDo
|
||||
WithContext(ctx context.Context) IOnlineDatabaseInfoDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IOnlineDatabaseInfoDo
|
||||
WriteDB() IOnlineDatabaseInfoDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IOnlineDatabaseInfoDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IOnlineDatabaseInfoDo
|
||||
Not(conds ...gen.Condition) IOnlineDatabaseInfoDo
|
||||
Or(conds ...gen.Condition) IOnlineDatabaseInfoDo
|
||||
Select(conds ...field.Expr) IOnlineDatabaseInfoDo
|
||||
Where(conds ...gen.Condition) IOnlineDatabaseInfoDo
|
||||
Order(conds ...field.Expr) IOnlineDatabaseInfoDo
|
||||
Distinct(cols ...field.Expr) IOnlineDatabaseInfoDo
|
||||
Omit(cols ...field.Expr) IOnlineDatabaseInfoDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IOnlineDatabaseInfoDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IOnlineDatabaseInfoDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IOnlineDatabaseInfoDo
|
||||
Group(cols ...field.Expr) IOnlineDatabaseInfoDo
|
||||
Having(conds ...gen.Condition) IOnlineDatabaseInfoDo
|
||||
Limit(limit int) IOnlineDatabaseInfoDo
|
||||
Offset(offset int) IOnlineDatabaseInfoDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IOnlineDatabaseInfoDo
|
||||
Unscoped() IOnlineDatabaseInfoDo
|
||||
Create(values ...*model.OnlineDatabaseInfo) error
|
||||
CreateInBatches(values []*model.OnlineDatabaseInfo, batchSize int) error
|
||||
Save(values ...*model.OnlineDatabaseInfo) error
|
||||
First() (*model.OnlineDatabaseInfo, error)
|
||||
Take() (*model.OnlineDatabaseInfo, error)
|
||||
Last() (*model.OnlineDatabaseInfo, error)
|
||||
Find() ([]*model.OnlineDatabaseInfo, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.OnlineDatabaseInfo, err error)
|
||||
FindInBatches(result *[]*model.OnlineDatabaseInfo, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.OnlineDatabaseInfo) (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) IOnlineDatabaseInfoDo
|
||||
Assign(attrs ...field.AssignExpr) IOnlineDatabaseInfoDo
|
||||
Joins(fields ...field.RelationField) IOnlineDatabaseInfoDo
|
||||
Preload(fields ...field.RelationField) IOnlineDatabaseInfoDo
|
||||
FirstOrInit() (*model.OnlineDatabaseInfo, error)
|
||||
FirstOrCreate() (*model.OnlineDatabaseInfo, error)
|
||||
FindByPage(offset int, limit int) (result []*model.OnlineDatabaseInfo, 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) IOnlineDatabaseInfoDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Debug() IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Debug())
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) WithContext(ctx context.Context) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) ReadDB() IOnlineDatabaseInfoDo {
|
||||
return o.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) WriteDB() IOnlineDatabaseInfoDo {
|
||||
return o.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Session(config *gorm.Session) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Session(config))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Clauses(conds ...clause.Expression) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Returning(value interface{}, columns ...string) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Not(conds ...gen.Condition) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Or(conds ...gen.Condition) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Select(conds ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Where(conds ...gen.Condition) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Order(conds ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Distinct(cols ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Omit(cols ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Join(table schema.Tabler, on ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) LeftJoin(table schema.Tabler, on ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) RightJoin(table schema.Tabler, on ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Group(cols ...field.Expr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Having(conds ...gen.Condition) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Limit(limit int) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Offset(offset int) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Unscoped() IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Create(values ...*model.OnlineDatabaseInfo) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return o.DO.Create(values)
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) CreateInBatches(values []*model.OnlineDatabaseInfo, batchSize int) error {
|
||||
return o.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 (o onlineDatabaseInfoDo) Save(values ...*model.OnlineDatabaseInfo) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return o.DO.Save(values)
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) First() (*model.OnlineDatabaseInfo, error) {
|
||||
if result, err := o.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.OnlineDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Take() (*model.OnlineDatabaseInfo, error) {
|
||||
if result, err := o.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.OnlineDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Last() (*model.OnlineDatabaseInfo, error) {
|
||||
if result, err := o.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.OnlineDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Find() ([]*model.OnlineDatabaseInfo, error) {
|
||||
result, err := o.DO.Find()
|
||||
return result.([]*model.OnlineDatabaseInfo), err
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.OnlineDatabaseInfo, err error) {
|
||||
buf := make([]*model.OnlineDatabaseInfo, 0, batchSize)
|
||||
err = o.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 (o onlineDatabaseInfoDo) FindInBatches(result *[]*model.OnlineDatabaseInfo, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return o.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Attrs(attrs ...field.AssignExpr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Assign(attrs ...field.AssignExpr) IOnlineDatabaseInfoDo {
|
||||
return o.withDO(o.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Joins(fields ...field.RelationField) IOnlineDatabaseInfoDo {
|
||||
for _, _f := range fields {
|
||||
o = *o.withDO(o.DO.Joins(_f))
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Preload(fields ...field.RelationField) IOnlineDatabaseInfoDo {
|
||||
for _, _f := range fields {
|
||||
o = *o.withDO(o.DO.Preload(_f))
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) FirstOrInit() (*model.OnlineDatabaseInfo, error) {
|
||||
if result, err := o.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.OnlineDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) FirstOrCreate() (*model.OnlineDatabaseInfo, error) {
|
||||
if result, err := o.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.OnlineDatabaseInfo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) FindByPage(offset int, limit int) (result []*model.OnlineDatabaseInfo, count int64, err error) {
|
||||
result, err = o.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 = o.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = o.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = o.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Scan(result interface{}) (err error) {
|
||||
return o.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (o onlineDatabaseInfoDo) Delete(models ...*model.OnlineDatabaseInfo) (result gen.ResultInfo, err error) {
|
||||
return o.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (o *onlineDatabaseInfoDo) withDO(do gen.Dao) *onlineDatabaseInfoDo {
|
||||
o.DO = *do.(*gen.DO)
|
||||
return o
|
||||
}
|
||||
Reference in New Issue
Block a user