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,76 @@
package database
type OperateType int64
const (
OperateType_Custom OperateType = 0
OperateType_Insert OperateType = 1
OperateType_Update OperateType = 2
OperateType_Delete OperateType = 3
OperateType_Select OperateType = 4
)
type Operation int64
const (
Operation_EQUAL Operation = 1
Operation_NOT_EQUAL Operation = 2
Operation_GREATER_THAN Operation = 3
Operation_LESS_THAN Operation = 4
Operation_GREATER_EQUAL Operation = 5
Operation_LESS_EQUAL Operation = 6
Operation_IN Operation = 7
Operation_NOT_IN Operation = 8
Operation_IS_NULL Operation = 9
Operation_IS_NOT_NULL Operation = 10
Operation_LIKE Operation = 11
Operation_NOT_LIKE Operation = 12
)
type Logic int64
const (
Logic_And Logic = 1
Logic_Or Logic = 2
)
// SQLType indicates the type of SQL, e.g., parameterized (with '?') or raw SQL.
type SQLType int32
const (
SQLType_Parameterized SQLType = 0
SQLType_Raw SQLType = 1 // Complete/raw SQL
)
type DocumentSourceType int64
const (
DocumentSourceType_Document DocumentSourceType = 0
)
type TableReadDataMethod int
var (
TableReadDataMethodOnlyHeader TableReadDataMethod = 1
TableReadDataMethodPreview TableReadDataMethod = 2
TableReadDataMethodAll TableReadDataMethod = 3
TableReadDataMethodHead TableReadDataMethod = 4
)
type ColumnTypeCategory int64
const (
ColumnTypeCategoryText ColumnTypeCategory = 0
ColumnTypeCategoryNumber ColumnTypeCategory = 1
)
const (
DefaultCreateTimeColName = "bstudio_create_time"
DefaultCidColName = "bstudio_connector_id"
DefaultUidColName = "bstudio_connector_uid"
DefaultIDColName = "bstudio_id"
DefaultCreateTimeDisplayColName = "bstudio_create_time"
DefaultUidDisplayColName = "uuid"
DefaultIDDisplayColName = "id"
)

View File

@@ -0,0 +1,190 @@
package database
import (
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_common"
"github.com/coze-dev/coze-studio/backend/api/model/table"
)
type ExecuteSQLRequest struct {
SQL *string // set if OperateType is 0.
SQLType SQLType // SQLType indicates the type of SQL: parameterized or raw SQL. It takes effect if OperateType is 0.
DatabaseID int64
UserID string
SpaceID int64
ConnectorID *int64
SQLParams []*SQLParamVal
TableType table.TableType
OperateType OperateType
// set the following values if OperateType is not 0.
SelectFieldList *SelectFieldList
OrderByList []OrderBy
Limit *int64
Offset *int64
Condition *ComplexCondition
UpsertRows []*UpsertRow
}
type ExecuteSQLResponse struct {
// Records contains the query result, where each map represents a row.
// The map's key is the column name, and the value is the raw data from the database.
// The caller is responsible for type assertion and conversion to the desired format.
// Common types returned by database drivers include:
// - Text: []uint8 (can be converted to string)
// - Number: int64
// - Float: float64
// - Boolean: bool
// - Date: time.Time
Records []map[string]any
FieldList []*FieldItem
RowsAffected *int64
}
type PublishDatabaseRequest struct {
AgentID int64
}
type PublishDatabaseResponse struct {
OnlineDatabases []*bot_common.Database
}
type SQLParamVal struct {
ValueType table.FieldItemType
ISNull bool
Value *string
Name *string
}
type OrderBy struct {
Field string
Direction table.SortDirection
}
type UpsertRow struct {
Records []*Record
}
type Record struct {
FieldId string
FieldValue string
}
type SelectFieldList struct {
FieldID []string
IsDistinct bool
}
type ComplexCondition struct {
Conditions []*Condition
// NestedConditions *ComplexCondition
Logic Logic
}
type Condition struct {
Left string
Operation Operation
Right string
}
type FieldItem struct {
Name string
Desc string
Type table.FieldItemType
MustRequired bool
AlterID int64
IsSystemField bool
PhysicalName string
// ID int64
}
type Database struct {
ID int64
IconURI string
CreatorID int64
SpaceID int64
CreatedAtMs int64
UpdatedAtMs int64
DeletedAtMs int64
AppID int64
IconURL string
TableName string
TableDesc string
Status table.BotTableStatus
FieldList []*FieldItem
ActualTableName string
RwMode table.BotTableRWMode
PromptDisabled bool
IsVisible bool
DraftID *int64
OnlineID *int64
ExtraInfo map[string]string
IsAddedToAgent *bool
TableType *table.TableType
}
func (d *Database) GetDraftID() int64 {
if d.DraftID == nil {
return 0
}
return *d.DraftID
}
func (d *Database) GetOnlineID() int64 {
if d.OnlineID == nil {
return 0
}
return *d.OnlineID
}
type DatabaseBasic struct {
ID int64
TableType table.TableType
NeedSysFields bool
}
type DeleteDatabaseRequest struct {
ID int64
}
type AgentToDatabase struct {
AgentID int64
DatabaseID int64
TableType table.TableType
PromptDisabled bool
}
type AgentToDatabaseBasic struct {
AgentID int64
DatabaseID int64
}
type BindDatabaseToAgentRequest struct {
DraftDatabaseID int64
AgentID int64
}
type UnBindDatabaseToAgentRequest struct {
DraftDatabaseID int64
AgentID int64
}
type MGetDatabaseRequest struct {
Basics []*DatabaseBasic
}
type MGetDatabaseResponse struct {
Databases []*Database
}
type GetAllDatabaseByAppIDRequest struct {
AppID int64
}
type GetAllDatabaseByAppIDResponse struct {
Databases []*Database // online databases
}