feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
229
backend/domain/plugin/internal/dal/agent_tool_version.go
Normal file
229
backend/domain/plugin/internal/dal/agent_tool_version.go
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewAgentToolVersionDAO(db *gorm.DB, idGen idgen.IDGenerator) *AgentToolVersionDAO {
|
||||
return &AgentToolVersionDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type AgentToolVersionDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type agentToolVersionPO model.AgentToolVersion
|
||||
|
||||
func (a agentToolVersionPO) ToDO() *entity.ToolInfo {
|
||||
return &entity.ToolInfo{
|
||||
ID: a.ToolID,
|
||||
PluginID: a.PluginID,
|
||||
Version: &a.ToolVersion,
|
||||
Method: &a.Method,
|
||||
SubURL: &a.SubURL,
|
||||
Operation: a.Operation,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(@maronghong): 简化查询代码,封装查询条件
|
||||
func (at *AgentToolVersionDAO) GetWithToolName(ctx context.Context, agentID int64, toolName string, agentVersion *string) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := at.query.AgentToolVersion
|
||||
|
||||
conds := []gen.Condition{
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ToolName.Eq(toolName),
|
||||
}
|
||||
var tl *model.AgentToolVersion
|
||||
if agentVersion == nil || *agentVersion == "" {
|
||||
tl, err = table.WithContext(ctx).
|
||||
Where(conds...).
|
||||
Order(table.CreatedAt.Desc()).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
} else {
|
||||
conds = append(conds, table.AgentVersion.Eq(*agentVersion))
|
||||
tl, err = table.WithContext(ctx).
|
||||
Where(conds...).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
tool = agentToolVersionPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (at *AgentToolVersionDAO) Get(ctx context.Context, agentID int64, vAgentTool entity.VersionAgentTool) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := at.query.AgentToolVersion
|
||||
|
||||
conds := []gen.Condition{
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ToolID.Eq(vAgentTool.ToolID),
|
||||
}
|
||||
var tl *model.AgentToolVersion
|
||||
if vAgentTool.AgentVersion == nil || *vAgentTool.AgentVersion == "" {
|
||||
tl, err = table.WithContext(ctx).
|
||||
Where(conds...).
|
||||
Order(table.CreatedAt.Desc()).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
} else {
|
||||
conds = append(conds, table.AgentVersion.Eq(*vAgentTool.AgentVersion))
|
||||
tl, err = table.WithContext(ctx).
|
||||
Where(conds...).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
tool = agentToolVersionPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (at *AgentToolVersionDAO) MGet(ctx context.Context, agentID int64, vAgentTools []entity.VersionAgentTool) (tools []*entity.ToolInfo, err error) {
|
||||
tools = make([]*entity.ToolInfo, 0, len(vAgentTools))
|
||||
|
||||
table := at.query.AgentToolVersion
|
||||
chunks := slices.Chunks(vAgentTools, 20)
|
||||
noVersion := make([]entity.VersionAgentTool, 0, len(vAgentTools))
|
||||
|
||||
for _, chunk := range chunks {
|
||||
var q query.IAgentToolVersionDo
|
||||
for _, v := range chunk {
|
||||
if v.AgentVersion == nil || *v.AgentVersion == "" {
|
||||
noVersion = append(noVersion, v)
|
||||
continue
|
||||
}
|
||||
if q == nil {
|
||||
q = table.WithContext(ctx).
|
||||
Where(
|
||||
table.Where(
|
||||
table.ToolID.Eq(chunk[0].ToolID),
|
||||
table.AgentVersion.Eq(*chunk[0].AgentVersion),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
q = q.Or(
|
||||
table.ToolID.Eq(v.ToolID),
|
||||
table.AgentVersion.Eq(*v.AgentVersion),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if q == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
tls, err := q.Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, agentToolVersionPO(*tl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range noVersion {
|
||||
tool, exist, err := at.Get(ctx, agentID, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exist {
|
||||
continue
|
||||
}
|
||||
tools = append(tools, tool)
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (at *AgentToolVersionDAO) BatchCreate(ctx context.Context, agentID int64, agentVersion string,
|
||||
tools []*entity.ToolInfo) (err error) {
|
||||
|
||||
tls := make([]*model.AgentToolVersion, 0, len(tools))
|
||||
for _, tl := range tools {
|
||||
if tl.Version == nil || *tl.Version == "" {
|
||||
return fmt.Errorf("invalid tool version")
|
||||
}
|
||||
|
||||
id, err := at.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tls = append(tls, &model.AgentToolVersion{
|
||||
ID: id,
|
||||
AgentID: agentID,
|
||||
PluginID: tl.PluginID,
|
||||
ToolID: tl.ID,
|
||||
AgentVersion: agentVersion,
|
||||
ToolVersion: *tl.Version,
|
||||
SubURL: tl.GetSubURL(),
|
||||
Method: tl.GetMethod(),
|
||||
ToolName: tl.GetName(),
|
||||
Operation: tl.Operation,
|
||||
})
|
||||
}
|
||||
|
||||
err = at.query.Transaction(func(tx *query.Query) error {
|
||||
table := tx.AgentToolVersion
|
||||
return table.WithContext(ctx).CreateInBatches(tls, 10)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
276
backend/domain/plugin/internal/dal/agetn_tool_draft.go
Normal file
276
backend/domain/plugin/internal/dal/agetn_tool_draft.go
Normal file
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewAgentToolDraftDAO(db *gorm.DB, idGen idgen.IDGenerator) *AgentToolDraftDAO {
|
||||
return &AgentToolDraftDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type AgentToolDraftDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type agentToolDraftPO model.AgentToolDraft
|
||||
|
||||
func (a agentToolDraftPO) ToDO() *entity.ToolInfo {
|
||||
return &entity.ToolInfo{
|
||||
ID: a.ToolID,
|
||||
PluginID: a.PluginID,
|
||||
CreatedAt: a.CreatedAt,
|
||||
Version: &a.ToolVersion,
|
||||
Method: &a.Method,
|
||||
SubURL: &a.SubURL,
|
||||
Operation: a.Operation,
|
||||
}
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) Get(ctx context.Context, agentID, toolID int64) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := at.query.AgentToolDraft
|
||||
tl, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ToolID.Eq(toolID),
|
||||
).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
tool = agentToolDraftPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) GetWithToolName(ctx context.Context, agentID int64, toolName string) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := at.query.AgentToolDraft
|
||||
tl, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ToolName.Eq(toolName),
|
||||
).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
tool = agentToolDraftPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) MGet(ctx context.Context, agentID int64, toolIDs []int64) (tools []*entity.ToolInfo, err error) {
|
||||
tools = make([]*entity.ToolInfo, 0, len(toolIDs))
|
||||
|
||||
table := at.query.AgentToolDraft
|
||||
chunks := slices.Chunks(toolIDs, 20)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
tls, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ToolID.In(chunk...),
|
||||
).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, agentToolDraftPO(*tl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) GetAll(ctx context.Context, agentID int64) (tools []*entity.ToolInfo, err error) {
|
||||
const limit = 20
|
||||
table := at.query.AgentToolDraft
|
||||
cursor := int64(0)
|
||||
|
||||
for {
|
||||
tls, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ID.Gt(cursor),
|
||||
).
|
||||
Order(table.ID.Asc()).
|
||||
Limit(limit).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, agentToolDraftPO(*tl).ToDO())
|
||||
}
|
||||
|
||||
if len(tls) < limit {
|
||||
break
|
||||
}
|
||||
|
||||
cursor = tls[len(tls)-1].ID
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) UpdateWithToolName(ctx context.Context, agentID int64, toolName string, tool *entity.ToolInfo) (err error) {
|
||||
m := &model.AgentToolDraft{
|
||||
Operation: tool.Operation,
|
||||
}
|
||||
table := at.query.AgentToolDraft
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ToolName.Eq(toolName),
|
||||
).
|
||||
Updates(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) BatchCreateWithTX(ctx context.Context, tx *query.QueryTx, agentID int64, tools []*entity.ToolInfo) (err error) {
|
||||
tls := make([]*model.AgentToolDraft, 0, len(tools))
|
||||
for _, tl := range tools {
|
||||
id, err := at.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m := &model.AgentToolDraft{
|
||||
ID: id,
|
||||
ToolID: tl.ID,
|
||||
PluginID: tl.PluginID,
|
||||
AgentID: agentID,
|
||||
SubURL: tl.GetSubURL(),
|
||||
Method: tl.GetMethod(),
|
||||
ToolVersion: tl.GetVersion(),
|
||||
ToolName: tl.GetName(),
|
||||
Operation: tl.Operation,
|
||||
}
|
||||
tls = append(tls, m)
|
||||
}
|
||||
|
||||
table := tx.AgentToolDraft
|
||||
err = table.WithContext(ctx).CreateInBatches(tls, 20)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) DeleteAll(ctx context.Context, agentID int64) (err error) {
|
||||
const limit = 20
|
||||
table := at.query.AgentToolDraft
|
||||
|
||||
for {
|
||||
info, err := table.WithContext(ctx).
|
||||
Where(table.AgentID.Eq(agentID)).
|
||||
Limit(limit).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.RowsAffected == 0 || info.RowsAffected < limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) GetAllPluginIDs(ctx context.Context, agentID int64) (pluginIDs []int64, err error) {
|
||||
const size = 100
|
||||
table := at.query.AgentToolDraft
|
||||
cursor := int64(0)
|
||||
|
||||
for {
|
||||
tls, err := table.WithContext(ctx).
|
||||
Select(table.PluginID, table.ID).
|
||||
Where(
|
||||
table.AgentID.Eq(agentID),
|
||||
table.ID.Gt(cursor),
|
||||
).
|
||||
Order(table.ID.Asc()).
|
||||
Limit(size).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
pluginIDs = append(pluginIDs, tl.PluginID)
|
||||
}
|
||||
|
||||
if len(tls) < size {
|
||||
break
|
||||
}
|
||||
|
||||
cursor = tls[len(tls)-1].ID
|
||||
}
|
||||
|
||||
return slices.Unique(pluginIDs), nil
|
||||
}
|
||||
|
||||
func (at *AgentToolDraftDAO) DeleteAllWithTX(ctx context.Context, tx *query.QueryTx, agentID int64) (err error) {
|
||||
const limit = 20
|
||||
table := tx.AgentToolDraft
|
||||
|
||||
for {
|
||||
info, err := table.WithContext(ctx).
|
||||
Where(table.AgentID.Eq(agentID)).
|
||||
Limit(limit).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.RowsAffected == 0 || info.RowsAffected < limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
57
backend/domain/plugin/internal/dal/cache.go
Normal file
57
backend/domain/plugin/internal/dal/cache.go
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
redisV9 "github.com/redis/go-redis/v9"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
)
|
||||
|
||||
type OAuthCache struct {
|
||||
cacheCli *redisV9.Client
|
||||
}
|
||||
|
||||
func NewOAuthCache(cacheCli *redisV9.Client) *OAuthCache {
|
||||
return &OAuthCache{
|
||||
cacheCli: cacheCli,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OAuthCache) Get(ctx context.Context, key string) (value string, exist bool, err error) {
|
||||
cmd := o.cacheCli.Get(ctx, key)
|
||||
if cmd.Err() != nil {
|
||||
if errors.Is(cmd.Err(), redisV9.Nil) {
|
||||
return "", false, nil
|
||||
}
|
||||
return "", false, cmd.Err()
|
||||
}
|
||||
|
||||
return cmd.Val(), true, nil
|
||||
}
|
||||
|
||||
func (o *OAuthCache) Set(ctx context.Context, key string, value string, expiration *time.Duration) (err error) {
|
||||
_expiration := ptr.FromOrDefault(expiration, 0)
|
||||
|
||||
cmd := o.cacheCli.Set(ctx, key, value, _expiration)
|
||||
|
||||
return cmd.Err()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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/plugin"
|
||||
|
||||
const TableNameAgentToolDraft = "agent_tool_draft"
|
||||
|
||||
// AgentToolDraft Draft Agent Tool
|
||||
type AgentToolDraft struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID
|
||||
AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID
|
||||
PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID
|
||||
ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
|
||||
SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path
|
||||
Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method
|
||||
ToolName string `gorm:"column:tool_name;not null;comment:Tool Name" json:"tool_name"` // Tool Name
|
||||
ToolVersion string `gorm:"column:tool_version;not null;comment:Tool Version, e.g. v1.0.0" json:"tool_version"` // Tool Version, e.g. v1.0.0
|
||||
Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema
|
||||
}
|
||||
|
||||
// TableName AgentToolDraft's table name
|
||||
func (*AgentToolDraft) TableName() string {
|
||||
return TableNameAgentToolDraft
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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/plugin"
|
||||
|
||||
const TableNameAgentToolVersion = "agent_tool_version"
|
||||
|
||||
// AgentToolVersion Agent Tool Version
|
||||
type AgentToolVersion struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID
|
||||
AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID
|
||||
PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID
|
||||
ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID
|
||||
AgentVersion string `gorm:"column:agent_version;not null;comment:Agent Tool Version" json:"agent_version"` // Agent Tool Version
|
||||
ToolName string `gorm:"column:tool_name;not null;comment:Tool Name" json:"tool_name"` // Tool Name
|
||||
ToolVersion string `gorm:"column:tool_version;not null;comment:Tool Version, e.g. v1.0.0" json:"tool_version"` // Tool Version, e.g. v1.0.0
|
||||
SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path
|
||||
Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method
|
||||
Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
|
||||
}
|
||||
|
||||
// TableName AgentToolVersion's table name
|
||||
func (*AgentToolVersion) TableName() string {
|
||||
return TableNameAgentToolVersion
|
||||
}
|
||||
31
backend/domain/plugin/internal/dal/model/plugin.gen.go
Normal file
31
backend/domain/plugin/internal/dal/model/plugin.gen.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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/plugin"
|
||||
|
||||
const TableNamePlugin = "plugin"
|
||||
|
||||
// Plugin Latest Plugin
|
||||
type Plugin struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Plugin ID" json:"id"` // Plugin ID
|
||||
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
|
||||
DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID
|
||||
AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID
|
||||
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
|
||||
ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL
|
||||
PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local
|
||||
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
|
||||
Version string `gorm:"column:version;not null;comment:Plugin Version, e.g. v1.0.0" json:"version"` // Plugin Version, e.g. v1.0.0
|
||||
VersionDesc string `gorm:"column:version_desc;comment:Plugin Version Description" json:"version_desc"` // Plugin Version Description
|
||||
Manifest *plugin.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest
|
||||
OpenapiDoc *plugin.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root
|
||||
}
|
||||
|
||||
// TableName Plugin's table name
|
||||
func (*Plugin) TableName() string {
|
||||
return TableNamePlugin
|
||||
}
|
||||
33
backend/domain/plugin/internal/dal/model/plugin_draft.gen.go
Normal file
33
backend/domain/plugin/internal/dal/model/plugin_draft.gen.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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/plugin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNamePluginDraft = "plugin_draft"
|
||||
|
||||
// PluginDraft Draft Plugin
|
||||
type PluginDraft struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Plugin ID" json:"id"` // Plugin ID
|
||||
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
|
||||
DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID
|
||||
AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID
|
||||
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
|
||||
ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL
|
||||
PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local
|
||||
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
|
||||
Manifest *plugin.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest
|
||||
OpenapiDoc *plugin.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root
|
||||
}
|
||||
|
||||
// TableName PluginDraft's table name
|
||||
func (*PluginDraft) TableName() string {
|
||||
return TableNamePluginDraft
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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/plugin"
|
||||
|
||||
const TableNamePluginOauthAuth = "plugin_oauth_auth"
|
||||
|
||||
// PluginOauthAuth Plugin OAuth Authorization Code Info
|
||||
type PluginOauthAuth struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Primary Key" json:"id"` // Primary Key
|
||||
UserID string `gorm:"column:user_id;not null;comment:User ID" json:"user_id"` // User ID
|
||||
PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID
|
||||
IsDraft bool `gorm:"column:is_draft;not null;comment:Is Draft Plugin" json:"is_draft"` // Is Draft Plugin
|
||||
OauthConfig *plugin.OAuthAuthorizationCodeConfig `gorm:"column:oauth_config;comment:Authorization Code OAuth Config;serializer:json" json:"oauth_config"` // Authorization Code OAuth Config
|
||||
AccessToken string `gorm:"column:access_token;not null;comment:Access Token" json:"access_token"` // Access Token
|
||||
RefreshToken string `gorm:"column:refresh_token;not null;comment:Refresh Token" json:"refresh_token"` // Refresh Token
|
||||
TokenExpiredAt int64 `gorm:"column:token_expired_at;comment:Token Expired in Milliseconds" json:"token_expired_at"` // Token Expired in Milliseconds
|
||||
NextTokenRefreshAt int64 `gorm:"column:next_token_refresh_at;comment:Next Token Refresh Time in Milliseconds" json:"next_token_refresh_at"` // Next Token Refresh Time in Milliseconds
|
||||
LastActiveAt int64 `gorm:"column:last_active_at;comment:Last active time in Milliseconds" json:"last_active_at"` // Last active time in Milliseconds
|
||||
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
|
||||
}
|
||||
|
||||
// TableName PluginOauthAuth's table name
|
||||
func (*PluginOauthAuth) TableName() string {
|
||||
return TableNamePluginOauthAuth
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// 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/plugin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNamePluginVersion = "plugin_version"
|
||||
|
||||
// PluginVersion Plugin Version
|
||||
type PluginVersion struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID
|
||||
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
|
||||
DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID
|
||||
PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID
|
||||
AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID
|
||||
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
|
||||
ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL
|
||||
PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local
|
||||
Version string `gorm:"column:version;not null;comment:Plugin Version, e.g. v1.0.0" json:"version"` // Plugin Version, e.g. v1.0.0
|
||||
VersionDesc string `gorm:"column:version_desc;comment:Plugin Version Description" json:"version_desc"` // Plugin Version Description
|
||||
Manifest *plugin.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest
|
||||
OpenapiDoc *plugin.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time
|
||||
}
|
||||
|
||||
// TableName PluginVersion's table name
|
||||
func (*PluginVersion) TableName() string {
|
||||
return TableNamePluginVersion
|
||||
}
|
||||
27
backend/domain/plugin/internal/dal/model/tool.gen.go
Normal file
27
backend/domain/plugin/internal/dal/model/tool.gen.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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/plugin"
|
||||
|
||||
const TableNameTool = "tool"
|
||||
|
||||
// Tool Latest Tool
|
||||
type Tool struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Tool ID" json:"id"` // Tool ID
|
||||
PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
|
||||
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
|
||||
Version string `gorm:"column:version;not null;comment:Tool Version, e.g. v1.0.0" json:"version"` // Tool Version, e.g. v1.0.0
|
||||
SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path
|
||||
Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method
|
||||
Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema
|
||||
ActivatedStatus int32 `gorm:"column:activated_status;not null;comment:0:activated; 1:deactivated" json:"activated_status"` // 0:activated; 1:deactivated
|
||||
}
|
||||
|
||||
// TableName Tool's table name
|
||||
func (*Tool) TableName() string {
|
||||
return TableNameTool
|
||||
}
|
||||
27
backend/domain/plugin/internal/dal/model/tool_draft.gen.go
Normal file
27
backend/domain/plugin/internal/dal/model/tool_draft.gen.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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/plugin"
|
||||
|
||||
const TableNameToolDraft = "tool_draft"
|
||||
|
||||
// ToolDraft Draft Tool
|
||||
type ToolDraft struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Tool ID" json:"id"` // Tool ID
|
||||
PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
|
||||
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
|
||||
SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path
|
||||
Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method
|
||||
Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema
|
||||
DebugStatus int32 `gorm:"column:debug_status;not null;comment:0:not pass; 1:pass" json:"debug_status"` // 0:not pass; 1:pass
|
||||
ActivatedStatus int32 `gorm:"column:activated_status;not null;comment:0:activated; 1:deactivated" json:"activated_status"` // 0:activated; 1:deactivated
|
||||
}
|
||||
|
||||
// TableName ToolDraft's table name
|
||||
func (*ToolDraft) TableName() string {
|
||||
return TableNameToolDraft
|
||||
}
|
||||
30
backend/domain/plugin/internal/dal/model/tool_version.gen.go
Normal file
30
backend/domain/plugin/internal/dal/model/tool_version.gen.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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/plugin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameToolVersion = "tool_version"
|
||||
|
||||
// ToolVersion Tool Version
|
||||
type ToolVersion struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID
|
||||
ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID
|
||||
PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID
|
||||
Version string `gorm:"column:version;not null;comment:Tool Version, e.g. v1.0.0" json:"version"` // Tool Version, e.g. v1.0.0
|
||||
SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path
|
||||
Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method
|
||||
Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time
|
||||
}
|
||||
|
||||
// TableName ToolVersion's table name
|
||||
func (*ToolVersion) TableName() string {
|
||||
return TableNameToolVersion
|
||||
}
|
||||
33
backend/domain/plugin/internal/dal/option.go
Normal file
33
backend/domain/plugin/internal/dal/option.go
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
type PluginSelectedOption struct {
|
||||
PluginID bool
|
||||
OpenapiDoc bool
|
||||
Manifest bool
|
||||
IconURI bool
|
||||
Version bool
|
||||
}
|
||||
|
||||
type ToolSelectedOption struct {
|
||||
ToolID bool
|
||||
ToolMethod bool
|
||||
ToolSubURL bool
|
||||
DebugStatus bool
|
||||
ActivatedStatus bool
|
||||
}
|
||||
253
backend/domain/plugin/internal/dal/plugin.go
Normal file
253
backend/domain/plugin/internal/dal/plugin.go
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewPluginDAO(db *gorm.DB, idGen idgen.IDGenerator) *PluginDAO {
|
||||
return &PluginDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type PluginDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type pluginPO model.Plugin
|
||||
|
||||
func (p pluginPO) ToDO() *entity.PluginInfo {
|
||||
return entity.NewPluginInfo(&plugin.PluginInfo{
|
||||
ID: p.ID,
|
||||
SpaceID: p.SpaceID,
|
||||
DeveloperID: p.DeveloperID,
|
||||
IconURI: &p.IconURI,
|
||||
ServerURL: &p.ServerURL,
|
||||
PluginType: plugin_develop_common.PluginType(p.PluginType),
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
Version: &p.Version,
|
||||
VersionDesc: &p.VersionDesc,
|
||||
Manifest: p.Manifest,
|
||||
OpenapiDoc: p.OpenapiDoc,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *PluginDAO) getSelected(opt *PluginSelectedOption) (selected []field.Expr) {
|
||||
if opt == nil {
|
||||
return selected
|
||||
}
|
||||
|
||||
table := p.query.Plugin
|
||||
|
||||
if opt.PluginID {
|
||||
selected = append(selected, table.ID)
|
||||
}
|
||||
if opt.OpenapiDoc {
|
||||
selected = append(selected, table.OpenapiDoc)
|
||||
}
|
||||
if opt.Version {
|
||||
selected = append(selected, table.Version)
|
||||
}
|
||||
if opt.Manifest {
|
||||
selected = append(selected, table.Manifest)
|
||||
}
|
||||
if opt.IconURI {
|
||||
selected = append(selected, table.IconURI)
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
func (p *PluginDAO) Get(ctx context.Context, pluginID int64, opt *PluginSelectedOption) (plugin *entity.PluginInfo, exist bool, err error) {
|
||||
table := p.query.Plugin
|
||||
|
||||
pl, err := table.WithContext(ctx).
|
||||
Where(table.ID.Eq(pluginID)).
|
||||
Select(p.getSelected(opt)...).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
plugin = pluginPO(*pl).ToDO()
|
||||
|
||||
return plugin, true, nil
|
||||
}
|
||||
|
||||
func (p *PluginDAO) MGet(ctx context.Context, pluginIDs []int64, opt *PluginSelectedOption) (plugins []*entity.PluginInfo, err error) {
|
||||
plugins = make([]*entity.PluginInfo, 0, len(pluginIDs))
|
||||
|
||||
table := p.query.Plugin
|
||||
chunks := slices.Chunks(pluginIDs, 10)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
pls, err := table.WithContext(ctx).
|
||||
Select(p.getSelected(opt)...).
|
||||
Where(table.ID.In(chunk...)).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, pl := range pls {
|
||||
plugins = append(plugins, pluginPO(*pl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
func (p *PluginDAO) List(ctx context.Context, spaceID int64, pageInfo entity.PageInfo) (plugins []*entity.PluginInfo, total int64, err error) {
|
||||
if pageInfo.SortBy == nil || pageInfo.OrderByACS == nil {
|
||||
return nil, 0, fmt.Errorf("sortBy or orderByACS is empty")
|
||||
}
|
||||
|
||||
var orderExpr field.Expr
|
||||
table := p.query.Plugin
|
||||
|
||||
switch *pageInfo.SortBy {
|
||||
case entity.SortByCreatedAt:
|
||||
if *pageInfo.OrderByACS {
|
||||
orderExpr = table.CreatedAt.Asc()
|
||||
} else {
|
||||
orderExpr = table.CreatedAt.Desc()
|
||||
}
|
||||
case entity.SortByUpdatedAt:
|
||||
if *pageInfo.OrderByACS {
|
||||
orderExpr = table.UpdatedAt.Asc()
|
||||
} else {
|
||||
orderExpr = table.UpdatedAt.Desc()
|
||||
}
|
||||
default:
|
||||
return nil, 0, fmt.Errorf("invalid sortBy '%v'", *pageInfo.SortBy)
|
||||
}
|
||||
|
||||
offset := (pageInfo.Page - 1) * pageInfo.Size
|
||||
pls, total, err := table.WithContext(ctx).
|
||||
Where(table.SpaceID.Eq(spaceID)).
|
||||
Order(orderExpr).
|
||||
FindByPage(offset, pageInfo.Size)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
plugins = make([]*entity.PluginInfo, 0, len(pls))
|
||||
for _, pl := range pls {
|
||||
plugins = append(plugins, pluginPO(*pl).ToDO())
|
||||
}
|
||||
|
||||
return plugins, total, nil
|
||||
}
|
||||
|
||||
func (p *PluginDAO) UpsertWithTX(ctx context.Context, tx *query.QueryTx, plugin *entity.PluginInfo) (err error) {
|
||||
table := tx.Plugin
|
||||
_, err = table.WithContext(ctx).Select(table.ID).Where(table.ID.Eq(plugin.ID)).First()
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
m := &model.Plugin{
|
||||
ID: plugin.ID,
|
||||
SpaceID: plugin.SpaceID,
|
||||
DeveloperID: plugin.DeveloperID,
|
||||
AppID: plugin.GetAPPID(),
|
||||
Manifest: plugin.Manifest,
|
||||
OpenapiDoc: plugin.OpenapiDoc,
|
||||
PluginType: int32(plugin.PluginType),
|
||||
IconURI: plugin.GetIconURI(),
|
||||
ServerURL: plugin.GetServerURL(),
|
||||
Version: plugin.GetVersion(),
|
||||
VersionDesc: plugin.GetVersionDesc(),
|
||||
}
|
||||
|
||||
return table.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
updateMap := map[string]any{}
|
||||
if plugin.APPID != nil {
|
||||
updateMap[table.AppID.ColumnName().String()] = *plugin.APPID
|
||||
}
|
||||
if plugin.IconURI != nil {
|
||||
updateMap[table.IconURI.ColumnName().String()] = *plugin.IconURI
|
||||
}
|
||||
if plugin.Version != nil {
|
||||
updateMap[table.Version.ColumnName().String()] = *plugin.Version
|
||||
}
|
||||
if plugin.VersionDesc != nil {
|
||||
updateMap[table.VersionDesc.ColumnName().String()] = *plugin.VersionDesc
|
||||
}
|
||||
if plugin.ServerURL != nil {
|
||||
updateMap[table.ServerURL.ColumnName().String()] = *plugin.ServerURL
|
||||
}
|
||||
if plugin.Manifest != nil {
|
||||
b, err := json.Marshal(plugin.Manifest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateMap[table.Manifest.ColumnName().String()] = b
|
||||
}
|
||||
if plugin.OpenapiDoc != nil {
|
||||
b, err := json.Marshal(plugin.OpenapiDoc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateMap[table.OpenapiDoc.ColumnName().String()] = b
|
||||
}
|
||||
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(plugin.ID)).
|
||||
Updates(updateMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PluginDAO) DeleteWithTX(ctx context.Context, tx *query.QueryTx, pluginID int64) (err error) {
|
||||
table := tx.Plugin
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(pluginID)).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
348
backend/domain/plugin/internal/dal/plugin_draft.go
Normal file
348
backend/domain/plugin/internal/dal/plugin_draft.go
Normal file
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewPluginDraftDAO(db *gorm.DB, idGen idgen.IDGenerator) *PluginDraftDAO {
|
||||
return &PluginDraftDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type PluginDraftDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type pluginDraftPO model.PluginDraft
|
||||
|
||||
func (p pluginDraftPO) ToDO() *entity.PluginInfo {
|
||||
return entity.NewPluginInfo(&plugin.PluginInfo{
|
||||
ID: p.ID,
|
||||
SpaceID: p.SpaceID,
|
||||
DeveloperID: p.DeveloperID,
|
||||
APPID: &p.AppID,
|
||||
IconURI: &p.IconURI,
|
||||
ServerURL: &p.ServerURL,
|
||||
PluginType: plugin_develop_common.PluginType(p.PluginType),
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
Manifest: p.Manifest,
|
||||
OpenapiDoc: p.OpenapiDoc,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) getSelected(opt *PluginSelectedOption) (selected []field.Expr) {
|
||||
if opt == nil {
|
||||
return selected
|
||||
}
|
||||
|
||||
table := p.query.PluginDraft
|
||||
|
||||
if opt.PluginID {
|
||||
selected = append(selected, table.ID)
|
||||
}
|
||||
if opt.OpenapiDoc {
|
||||
selected = append(selected, table.OpenapiDoc)
|
||||
}
|
||||
if opt.Manifest {
|
||||
selected = append(selected, table.Manifest)
|
||||
}
|
||||
if opt.IconURI {
|
||||
selected = append(selected, table.IconURI)
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) Create(ctx context.Context, plugin *entity.PluginInfo) (pluginID int64, err error) {
|
||||
id, err := p.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
mf, err := plugin.Manifest.EncryptAuthPayload()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("EncryptAuthPayload failed, err=%w", err)
|
||||
}
|
||||
|
||||
table := p.query.PluginDraft
|
||||
err = table.WithContext(ctx).Create(&model.PluginDraft{
|
||||
ID: id,
|
||||
SpaceID: plugin.SpaceID,
|
||||
DeveloperID: plugin.DeveloperID,
|
||||
PluginType: int32(plugin.PluginType),
|
||||
IconURI: plugin.GetIconURI(),
|
||||
ServerURL: plugin.GetServerURL(),
|
||||
AppID: plugin.GetAPPID(),
|
||||
Manifest: mf,
|
||||
OpenapiDoc: plugin.OpenapiDoc,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) Get(ctx context.Context, pluginID int64, opt *PluginSelectedOption) (plugin *entity.PluginInfo, exist bool, err error) {
|
||||
table := p.query.PluginDraft
|
||||
pl, err := table.WithContext(ctx).
|
||||
Select(p.getSelected(opt)...).
|
||||
Where(table.ID.Eq(pluginID)).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
plugin = pluginDraftPO(*pl).ToDO()
|
||||
|
||||
return plugin, true, nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) GetAPPAllPlugins(ctx context.Context, appID int64, opt *PluginSelectedOption) (plugins []*entity.PluginInfo, err error) {
|
||||
table := p.query.PluginDraft
|
||||
|
||||
cursor := int64(0)
|
||||
limit := 20
|
||||
|
||||
for {
|
||||
pls, err := table.WithContext(ctx).
|
||||
Select(p.getSelected(opt)...).
|
||||
Where(
|
||||
table.AppID.Eq(appID),
|
||||
table.ID.Gt(cursor),
|
||||
).
|
||||
Order(table.ID.Asc()).
|
||||
Limit(limit).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, pl := range pls {
|
||||
plugins = append(plugins, pluginDraftPO(*pl).ToDO())
|
||||
}
|
||||
|
||||
if len(pls) < limit {
|
||||
break
|
||||
}
|
||||
|
||||
cursor = pls[len(pls)-1].ID
|
||||
}
|
||||
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) MGet(ctx context.Context, pluginIDs []int64, opt *PluginSelectedOption) (plugins []*entity.PluginInfo, err error) {
|
||||
plugins = make([]*entity.PluginInfo, 0, len(pluginIDs))
|
||||
|
||||
table := p.query.PluginDraft
|
||||
chunks := slices.Chunks(pluginIDs, 20)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
pls, err := table.WithContext(ctx).
|
||||
Select(p.getSelected(opt)...).
|
||||
Where(table.ID.In(chunk...)).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, pl := range pls {
|
||||
plugins = append(plugins, pluginDraftPO(*pl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) List(ctx context.Context, spaceID, appID int64, pageInfo entity.PageInfo) (plugins []*entity.PluginInfo, total int64, err error) {
|
||||
if pageInfo.SortBy == nil || pageInfo.OrderByACS == nil {
|
||||
return nil, 0, fmt.Errorf("sortBy or orderByACS is empty")
|
||||
}
|
||||
|
||||
var orderExpr field.Expr
|
||||
table := p.query.PluginDraft
|
||||
|
||||
switch *pageInfo.SortBy {
|
||||
case entity.SortByCreatedAt:
|
||||
if *pageInfo.OrderByACS {
|
||||
orderExpr = table.CreatedAt.Asc()
|
||||
} else {
|
||||
orderExpr = table.CreatedAt.Desc()
|
||||
}
|
||||
case entity.SortByUpdatedAt:
|
||||
if *pageInfo.OrderByACS {
|
||||
orderExpr = table.UpdatedAt.Asc()
|
||||
} else {
|
||||
orderExpr = table.UpdatedAt.Desc()
|
||||
}
|
||||
default:
|
||||
return nil, 0, fmt.Errorf("invalid sortBy '%v'", *pageInfo.SortBy)
|
||||
}
|
||||
|
||||
offset := (pageInfo.Page - 1) * pageInfo.Size
|
||||
pls, total, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.SpaceID.Eq(spaceID),
|
||||
table.AppID.Eq(appID),
|
||||
).
|
||||
Order(orderExpr).
|
||||
FindByPage(offset, pageInfo.Size)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
plugins = make([]*entity.PluginInfo, 0, len(pls))
|
||||
for _, pl := range pls {
|
||||
plugins = append(plugins, pluginDraftPO(*pl).ToDO())
|
||||
}
|
||||
|
||||
return plugins, total, nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) Update(ctx context.Context, plugin *entity.PluginInfo) (err error) {
|
||||
mf, err := plugin.Manifest.EncryptAuthPayload()
|
||||
if err != nil {
|
||||
return fmt.Errorf("EncryptAuthPayload failed, err=%w", err)
|
||||
}
|
||||
|
||||
m := &model.PluginDraft{
|
||||
Manifest: mf,
|
||||
OpenapiDoc: plugin.OpenapiDoc,
|
||||
}
|
||||
if plugin.IconURI != nil {
|
||||
m.IconURI = *plugin.IconURI
|
||||
}
|
||||
|
||||
table := p.query.PluginDraft
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(plugin.ID)).
|
||||
Updates(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) CreateWithTX(ctx context.Context, tx *query.QueryTx, plugin *entity.PluginInfo) (pluginID int64, err error) {
|
||||
id, err := p.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
mf, err := plugin.Manifest.EncryptAuthPayload()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("EncryptAuthPayload failed, err=%w", err)
|
||||
}
|
||||
|
||||
table := tx.PluginDraft
|
||||
err = table.WithContext(ctx).Create(&model.PluginDraft{
|
||||
ID: id,
|
||||
SpaceID: plugin.SpaceID,
|
||||
DeveloperID: plugin.DeveloperID,
|
||||
PluginType: int32(plugin.PluginType),
|
||||
IconURI: plugin.GetIconURI(),
|
||||
ServerURL: plugin.GetServerURL(),
|
||||
AppID: plugin.GetAPPID(),
|
||||
Manifest: mf,
|
||||
OpenapiDoc: plugin.OpenapiDoc,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) UpdateWithTX(ctx context.Context, tx *query.QueryTx, plugin *entity.PluginInfo) (err error) {
|
||||
table := tx.PluginDraft
|
||||
|
||||
updateMap := map[string]any{}
|
||||
if plugin.Manifest != nil {
|
||||
mf, err := plugin.Manifest.EncryptAuthPayload()
|
||||
if err != nil {
|
||||
return fmt.Errorf("EncryptAuthPayload failed, err=%w", err)
|
||||
}
|
||||
|
||||
mfBytes, err := json.Marshal(mf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
updateMap[table.Manifest.ColumnName().String()] = mfBytes
|
||||
}
|
||||
if plugin.OpenapiDoc != nil {
|
||||
doc, err := json.Marshal(plugin.OpenapiDoc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateMap[table.OpenapiDoc.ColumnName().String()] = doc
|
||||
}
|
||||
if plugin.IconURI != nil {
|
||||
updateMap[table.IconURI.ColumnName().String()] = *plugin.IconURI
|
||||
}
|
||||
if plugin.ServerURL != nil {
|
||||
updateMap[table.ServerURL.ColumnName().String()] = *plugin.ServerURL
|
||||
}
|
||||
if plugin.APPID != nil {
|
||||
updateMap[table.AppID.ColumnName().String()] = *plugin.APPID
|
||||
}
|
||||
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(plugin.ID)).
|
||||
UpdateColumns(updateMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PluginDraftDAO) DeleteWithTX(ctx context.Context, tx *query.QueryTx, pluginID int64) (err error) {
|
||||
table := tx.PluginDraft
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(pluginID)).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
320
backend/domain/plugin/internal/dal/plugin_oauth_auth.go
Normal file
320
backend/domain/plugin/internal/dal/plugin_oauth_auth.go
Normal file
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/utils"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewPluginOAuthAuthDAO(db *gorm.DB, idGen idgen.IDGenerator) *PluginOAuthAuthDAO {
|
||||
return &PluginOAuthAuthDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type pluginOAuthAuthPO model.PluginOauthAuth
|
||||
|
||||
func (p pluginOAuthAuthPO) ToDO() *entity.AuthorizationCodeInfo {
|
||||
if p.RefreshToken != "" {
|
||||
refreshToken, err := utils.DecryptByAES(p.RefreshToken, utils.OAuthTokenSecretKey)
|
||||
if err == nil {
|
||||
p.RefreshToken = string(refreshToken)
|
||||
}
|
||||
}
|
||||
if p.AccessToken != "" {
|
||||
accessToken, err := utils.DecryptByAES(p.AccessToken, utils.OAuthTokenSecretKey)
|
||||
if err == nil {
|
||||
p.AccessToken = string(accessToken)
|
||||
}
|
||||
}
|
||||
|
||||
return &entity.AuthorizationCodeInfo{
|
||||
RecordID: p.ID,
|
||||
Meta: &entity.AuthorizationCodeMeta{
|
||||
UserID: p.UserID,
|
||||
PluginID: p.PluginID,
|
||||
IsDraft: p.IsDraft,
|
||||
},
|
||||
Config: p.OauthConfig,
|
||||
AccessToken: p.AccessToken,
|
||||
RefreshToken: p.RefreshToken,
|
||||
TokenExpiredAtMS: p.TokenExpiredAt,
|
||||
NextTokenRefreshAtMS: &p.NextTokenRefreshAt,
|
||||
LastActiveAtMS: p.LastActiveAt,
|
||||
}
|
||||
}
|
||||
|
||||
type PluginOAuthAuthDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) Get(ctx context.Context, meta *entity.AuthorizationCodeMeta) (info *entity.AuthorizationCodeInfo, exist bool, err error) {
|
||||
table := p.query.PluginOauthAuth
|
||||
res, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.UserID.Eq(meta.UserID),
|
||||
table.PluginID.Eq(meta.PluginID),
|
||||
table.IsDraft.Is(meta.IsDraft),
|
||||
).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
info = pluginOAuthAuthPO(*res).ToDO()
|
||||
|
||||
return info, true, nil
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) Upsert(ctx context.Context, info *entity.AuthorizationCodeInfo) (err error) {
|
||||
if info.Meta == nil || info.Meta.UserID == "" || info.Meta.PluginID <= 0 {
|
||||
return fmt.Errorf("meta info is required")
|
||||
}
|
||||
|
||||
meta := info.Meta
|
||||
|
||||
var accessToken, refreshToken string
|
||||
if info.AccessToken != "" {
|
||||
accessToken, err = utils.EncryptByAES([]byte(info.AccessToken), utils.OAuthTokenSecretKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if info.RefreshToken != "" {
|
||||
refreshToken, err = utils.EncryptByAES([]byte(info.RefreshToken), utils.OAuthTokenSecretKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
table := p.query.PluginOauthAuth
|
||||
_, err = table.WithContext(ctx).
|
||||
Select(table.ID).
|
||||
Where(
|
||||
table.UserID.Eq(meta.UserID),
|
||||
table.PluginID.Eq(meta.PluginID),
|
||||
table.IsDraft.Is(meta.IsDraft),
|
||||
).First()
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
id, err := p.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
po := &model.PluginOauthAuth{
|
||||
ID: id,
|
||||
UserID: meta.UserID,
|
||||
PluginID: meta.PluginID,
|
||||
IsDraft: meta.IsDraft,
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: refreshToken,
|
||||
TokenExpiredAt: info.TokenExpiredAtMS,
|
||||
NextTokenRefreshAt: info.GetNextTokenRefreshAtMS(),
|
||||
OauthConfig: info.Config,
|
||||
LastActiveAt: info.LastActiveAtMS,
|
||||
}
|
||||
|
||||
return table.WithContext(ctx).Create(po)
|
||||
}
|
||||
|
||||
updateMap := map[string]any{}
|
||||
if accessToken != "" {
|
||||
updateMap[table.AccessToken.ColumnName().String()] = accessToken
|
||||
}
|
||||
if refreshToken != "" {
|
||||
updateMap[table.RefreshToken.ColumnName().String()] = refreshToken
|
||||
}
|
||||
if info.NextTokenRefreshAtMS != nil {
|
||||
updateMap[table.NextTokenRefreshAt.ColumnName().String()] = *info.NextTokenRefreshAtMS
|
||||
}
|
||||
if info.TokenExpiredAtMS > 0 {
|
||||
updateMap[table.TokenExpiredAt.ColumnName().String()] = info.TokenExpiredAtMS
|
||||
}
|
||||
if info.LastActiveAtMS > 0 {
|
||||
updateMap[table.LastActiveAt.ColumnName().String()] = info.LastActiveAtMS
|
||||
}
|
||||
if info.Config != nil {
|
||||
b, err := json.Marshal(info.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateMap[table.OauthConfig.ColumnName().String()] = b
|
||||
}
|
||||
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(
|
||||
table.UserID.Eq(meta.UserID),
|
||||
table.PluginID.Eq(meta.PluginID),
|
||||
table.IsDraft.Is(meta.IsDraft),
|
||||
).
|
||||
Updates(updateMap)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) UpdateLastActiveAt(ctx context.Context, meta *entity.AuthorizationCodeMeta, lastActiveAtMs int64) (err error) {
|
||||
po := &model.PluginOauthAuth{
|
||||
LastActiveAt: lastActiveAtMs,
|
||||
}
|
||||
|
||||
table := p.query.PluginOauthAuth
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(
|
||||
table.UserID.Eq(meta.UserID),
|
||||
table.PluginID.Eq(meta.PluginID),
|
||||
table.IsDraft.Is(meta.IsDraft),
|
||||
).
|
||||
Updates(po)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) GetRefreshTokenList(ctx context.Context, nextRefreshAt int64, limit int) (infos []*entity.AuthorizationCodeInfo, err error) {
|
||||
const size = 50
|
||||
table := p.query.PluginOauthAuth
|
||||
|
||||
infos = make([]*entity.AuthorizationCodeInfo, 0, limit)
|
||||
|
||||
for limit > 0 {
|
||||
res, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.NextTokenRefreshAt.Gt(0),
|
||||
table.NextTokenRefreshAt.Lt(nextRefreshAt),
|
||||
).
|
||||
Order(table.NextTokenRefreshAt.Asc()).
|
||||
Limit(size).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
infos = make([]*entity.AuthorizationCodeInfo, 0, len(res))
|
||||
for _, v := range res {
|
||||
infos = append(infos, pluginOAuthAuthPO(*v).ToDO())
|
||||
}
|
||||
|
||||
limit -= size
|
||||
|
||||
if len(res) < size {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) BatchDeleteByIDs(ctx context.Context, ids []int64) (err error) {
|
||||
table := p.query.PluginOauthAuth
|
||||
|
||||
chunks := slices.Chunks(ids, 20)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.In(chunk...)).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) Delete(ctx context.Context, meta *entity.AuthorizationCodeMeta) (err error) {
|
||||
table := p.query.PluginOauthAuth
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(
|
||||
table.UserID.Eq(meta.UserID),
|
||||
table.PluginID.Eq(meta.PluginID),
|
||||
table.IsDraft.Is(meta.IsDraft),
|
||||
).
|
||||
Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) DeleteExpiredTokens(ctx context.Context, expireAt int64, limit int) (err error) {
|
||||
const size = 50
|
||||
table := p.query.PluginOauthAuth
|
||||
|
||||
for limit > 0 {
|
||||
res, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.TokenExpiredAt.Gt(0),
|
||||
table.TokenExpiredAt.Lt(expireAt),
|
||||
).
|
||||
Limit(size).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
limit -= size
|
||||
|
||||
if res.RowsAffected < size {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PluginOAuthAuthDAO) DeleteInactiveTokens(ctx context.Context, lastActiveAt int64, limit int) (err error) {
|
||||
const size = 50
|
||||
table := p.query.PluginOauthAuth
|
||||
|
||||
for limit > 0 {
|
||||
res, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.LastActiveAt.Gt(0),
|
||||
table.LastActiveAt.Lt(lastActiveAt),
|
||||
).
|
||||
Limit(size).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
limit -= size
|
||||
|
||||
if res.RowsAffected < size {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
210
backend/domain/plugin/internal/dal/plugin_version.go
Normal file
210
backend/domain/plugin/internal/dal/plugin_version.go
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewPluginVersionDAO(db *gorm.DB, idGen idgen.IDGenerator) *PluginVersionDAO {
|
||||
return &PluginVersionDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type PluginVersionDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type pluginVersionPO model.PluginVersion
|
||||
|
||||
func (p pluginVersionPO) ToDO() *entity.PluginInfo {
|
||||
return entity.NewPluginInfo(&plugin.PluginInfo{
|
||||
ID: p.PluginID,
|
||||
SpaceID: p.SpaceID,
|
||||
APPID: &p.AppID,
|
||||
DeveloperID: p.DeveloperID,
|
||||
PluginType: plugin_develop_common.PluginType(p.PluginType),
|
||||
IconURI: &p.IconURI,
|
||||
ServerURL: &p.ServerURL,
|
||||
CreatedAt: p.CreatedAt,
|
||||
Version: &p.Version,
|
||||
VersionDesc: &p.VersionDesc,
|
||||
Manifest: p.Manifest,
|
||||
OpenapiDoc: p.OpenapiDoc,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *PluginVersionDAO) getSelected(opt *PluginSelectedOption) (selected []field.Expr) {
|
||||
if opt == nil {
|
||||
return selected
|
||||
}
|
||||
|
||||
table := p.query.PluginVersion
|
||||
|
||||
if opt.PluginID {
|
||||
selected = append(selected, table.PluginID)
|
||||
}
|
||||
if opt.OpenapiDoc {
|
||||
selected = append(selected, table.OpenapiDoc)
|
||||
}
|
||||
if opt.Version {
|
||||
selected = append(selected, table.Version)
|
||||
}
|
||||
if opt.Manifest {
|
||||
selected = append(selected, table.Manifest)
|
||||
}
|
||||
if opt.IconURI {
|
||||
selected = append(selected, table.IconURI)
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
func (p *PluginVersionDAO) Get(ctx context.Context, pluginID int64, version string) (plugin *entity.PluginInfo, exist bool, err error) {
|
||||
table := p.query.PluginVersion
|
||||
pl, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.PluginID.Eq(pluginID),
|
||||
table.Version.Eq(version),
|
||||
).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
plugin = pluginVersionPO(*pl).ToDO()
|
||||
|
||||
return plugin, true, nil
|
||||
}
|
||||
|
||||
func (p *PluginVersionDAO) MGet(ctx context.Context, vPlugins []entity.VersionPlugin, opt *PluginSelectedOption) (plugins []*entity.PluginInfo, err error) {
|
||||
plugins = make([]*entity.PluginInfo, 0, len(vPlugins))
|
||||
|
||||
table := p.query.PluginVersion
|
||||
chunks := slices.Chunks(vPlugins, 10)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
q := table.WithContext(ctx).
|
||||
Select(p.getSelected(opt)...).
|
||||
Where(
|
||||
table.Where(
|
||||
table.PluginID.Eq(chunk[0].PluginID),
|
||||
table.Version.Eq(chunk[0].Version),
|
||||
),
|
||||
)
|
||||
|
||||
for i, v := range chunk {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
q = q.Or(
|
||||
table.PluginID.Eq(v.PluginID),
|
||||
table.Version.Eq(v.Version),
|
||||
)
|
||||
}
|
||||
|
||||
pls, err := q.Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, pl := range pls {
|
||||
plugins = append(plugins, pluginVersionPO(*pl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
func (p *PluginVersionDAO) ListVersions(ctx context.Context, pluginID int64, pageInfo entity.PageInfo) (plugins []*entity.PluginInfo, total int64, err error) {
|
||||
table := p.query.PluginVersion
|
||||
|
||||
offset := (pageInfo.Page - 1) * pageInfo.Size
|
||||
pls, total, err := table.WithContext(ctx).
|
||||
Where(table.PluginID.Eq(pluginID)).
|
||||
Select(table.CreatedAt, table.Manifest, table.Version, table.VersionDesc).
|
||||
Order(table.CreatedAt.Desc()).
|
||||
FindByPage(offset, pageInfo.Size)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
plugins = make([]*entity.PluginInfo, 0, len(pls))
|
||||
for _, pl := range pls {
|
||||
plugins = append(plugins, pluginVersionPO(*pl).ToDO())
|
||||
}
|
||||
|
||||
return plugins, total, nil
|
||||
}
|
||||
|
||||
func (p *PluginVersionDAO) CreateWithTX(ctx context.Context, tx *query.QueryTx, plugin *entity.PluginInfo) (err error) {
|
||||
if plugin.GetVersion() == "" {
|
||||
return fmt.Errorf("invalid plugin version")
|
||||
}
|
||||
|
||||
id, err := p.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
table := tx.PluginVersion
|
||||
err = table.WithContext(ctx).Create(&model.PluginVersion{
|
||||
ID: id,
|
||||
SpaceID: plugin.SpaceID,
|
||||
PluginID: plugin.ID,
|
||||
DeveloperID: plugin.DeveloperID,
|
||||
AppID: plugin.GetAPPID(),
|
||||
PluginType: int32(plugin.PluginType),
|
||||
IconURI: plugin.GetIconURI(),
|
||||
ServerURL: plugin.GetServerURL(),
|
||||
Version: plugin.GetVersion(),
|
||||
VersionDesc: plugin.GetVersionDesc(),
|
||||
Manifest: plugin.Manifest,
|
||||
OpenapiDoc: plugin.OpenapiDoc,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PluginVersionDAO) DeleteWithTX(ctx context.Context, tx *query.QueryTx, pluginID int64) (err error) {
|
||||
table := tx.PluginVersion
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.PluginID.Eq(pluginID)).
|
||||
Delete()
|
||||
return err
|
||||
}
|
||||
417
backend/domain/plugin/internal/dal/query/agent_tool_draft.gen.go
Normal file
417
backend/domain/plugin/internal/dal/query/agent_tool_draft.gen.go
Normal file
@@ -0,0 +1,417 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newAgentToolDraft(db *gorm.DB, opts ...gen.DOOption) agentToolDraft {
|
||||
_agentToolDraft := agentToolDraft{}
|
||||
|
||||
_agentToolDraft.agentToolDraftDo.UseDB(db, opts...)
|
||||
_agentToolDraft.agentToolDraftDo.UseModel(&model.AgentToolDraft{})
|
||||
|
||||
tableName := _agentToolDraft.agentToolDraftDo.TableName()
|
||||
_agentToolDraft.ALL = field.NewAsterisk(tableName)
|
||||
_agentToolDraft.ID = field.NewInt64(tableName, "id")
|
||||
_agentToolDraft.AgentID = field.NewInt64(tableName, "agent_id")
|
||||
_agentToolDraft.PluginID = field.NewInt64(tableName, "plugin_id")
|
||||
_agentToolDraft.ToolID = field.NewInt64(tableName, "tool_id")
|
||||
_agentToolDraft.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_agentToolDraft.SubURL = field.NewString(tableName, "sub_url")
|
||||
_agentToolDraft.Method = field.NewString(tableName, "method")
|
||||
_agentToolDraft.ToolName = field.NewString(tableName, "tool_name")
|
||||
_agentToolDraft.ToolVersion = field.NewString(tableName, "tool_version")
|
||||
_agentToolDraft.Operation = field.NewField(tableName, "operation")
|
||||
|
||||
_agentToolDraft.fillFieldMap()
|
||||
|
||||
return _agentToolDraft
|
||||
}
|
||||
|
||||
// agentToolDraft Draft Agent Tool
|
||||
type agentToolDraft struct {
|
||||
agentToolDraftDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Primary Key ID
|
||||
AgentID field.Int64 // Agent ID
|
||||
PluginID field.Int64 // Plugin ID
|
||||
ToolID field.Int64 // Tool ID
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
SubURL field.String // Sub URL Path
|
||||
Method field.String // HTTP Request Method
|
||||
ToolName field.String // Tool Name
|
||||
ToolVersion field.String // Tool Version, e.g. v1.0.0
|
||||
Operation field.Field // Tool Openapi Operation Schema
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (a agentToolDraft) Table(newTableName string) *agentToolDraft {
|
||||
a.agentToolDraftDo.UseTable(newTableName)
|
||||
return a.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (a agentToolDraft) As(alias string) *agentToolDraft {
|
||||
a.agentToolDraftDo.DO = *(a.agentToolDraftDo.As(alias).(*gen.DO))
|
||||
return a.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (a *agentToolDraft) updateTableName(table string) *agentToolDraft {
|
||||
a.ALL = field.NewAsterisk(table)
|
||||
a.ID = field.NewInt64(table, "id")
|
||||
a.AgentID = field.NewInt64(table, "agent_id")
|
||||
a.PluginID = field.NewInt64(table, "plugin_id")
|
||||
a.ToolID = field.NewInt64(table, "tool_id")
|
||||
a.CreatedAt = field.NewInt64(table, "created_at")
|
||||
a.SubURL = field.NewString(table, "sub_url")
|
||||
a.Method = field.NewString(table, "method")
|
||||
a.ToolName = field.NewString(table, "tool_name")
|
||||
a.ToolVersion = field.NewString(table, "tool_version")
|
||||
a.Operation = field.NewField(table, "operation")
|
||||
|
||||
a.fillFieldMap()
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *agentToolDraft) 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 *agentToolDraft) fillFieldMap() {
|
||||
a.fieldMap = make(map[string]field.Expr, 10)
|
||||
a.fieldMap["id"] = a.ID
|
||||
a.fieldMap["agent_id"] = a.AgentID
|
||||
a.fieldMap["plugin_id"] = a.PluginID
|
||||
a.fieldMap["tool_id"] = a.ToolID
|
||||
a.fieldMap["created_at"] = a.CreatedAt
|
||||
a.fieldMap["sub_url"] = a.SubURL
|
||||
a.fieldMap["method"] = a.Method
|
||||
a.fieldMap["tool_name"] = a.ToolName
|
||||
a.fieldMap["tool_version"] = a.ToolVersion
|
||||
a.fieldMap["operation"] = a.Operation
|
||||
}
|
||||
|
||||
func (a agentToolDraft) clone(db *gorm.DB) agentToolDraft {
|
||||
a.agentToolDraftDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a agentToolDraft) replaceDB(db *gorm.DB) agentToolDraft {
|
||||
a.agentToolDraftDo.ReplaceDB(db)
|
||||
return a
|
||||
}
|
||||
|
||||
type agentToolDraftDo struct{ gen.DO }
|
||||
|
||||
type IAgentToolDraftDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IAgentToolDraftDo
|
||||
WithContext(ctx context.Context) IAgentToolDraftDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IAgentToolDraftDo
|
||||
WriteDB() IAgentToolDraftDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IAgentToolDraftDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IAgentToolDraftDo
|
||||
Not(conds ...gen.Condition) IAgentToolDraftDo
|
||||
Or(conds ...gen.Condition) IAgentToolDraftDo
|
||||
Select(conds ...field.Expr) IAgentToolDraftDo
|
||||
Where(conds ...gen.Condition) IAgentToolDraftDo
|
||||
Order(conds ...field.Expr) IAgentToolDraftDo
|
||||
Distinct(cols ...field.Expr) IAgentToolDraftDo
|
||||
Omit(cols ...field.Expr) IAgentToolDraftDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IAgentToolDraftDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IAgentToolDraftDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IAgentToolDraftDo
|
||||
Group(cols ...field.Expr) IAgentToolDraftDo
|
||||
Having(conds ...gen.Condition) IAgentToolDraftDo
|
||||
Limit(limit int) IAgentToolDraftDo
|
||||
Offset(offset int) IAgentToolDraftDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IAgentToolDraftDo
|
||||
Unscoped() IAgentToolDraftDo
|
||||
Create(values ...*model.AgentToolDraft) error
|
||||
CreateInBatches(values []*model.AgentToolDraft, batchSize int) error
|
||||
Save(values ...*model.AgentToolDraft) error
|
||||
First() (*model.AgentToolDraft, error)
|
||||
Take() (*model.AgentToolDraft, error)
|
||||
Last() (*model.AgentToolDraft, error)
|
||||
Find() ([]*model.AgentToolDraft, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AgentToolDraft, err error)
|
||||
FindInBatches(result *[]*model.AgentToolDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.AgentToolDraft) (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) IAgentToolDraftDo
|
||||
Assign(attrs ...field.AssignExpr) IAgentToolDraftDo
|
||||
Joins(fields ...field.RelationField) IAgentToolDraftDo
|
||||
Preload(fields ...field.RelationField) IAgentToolDraftDo
|
||||
FirstOrInit() (*model.AgentToolDraft, error)
|
||||
FirstOrCreate() (*model.AgentToolDraft, error)
|
||||
FindByPage(offset int, limit int) (result []*model.AgentToolDraft, 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) IAgentToolDraftDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Debug() IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Debug())
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) WithContext(ctx context.Context) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) ReadDB() IAgentToolDraftDo {
|
||||
return a.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) WriteDB() IAgentToolDraftDo {
|
||||
return a.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Session(config *gorm.Session) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Session(config))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Clauses(conds ...clause.Expression) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Returning(value interface{}, columns ...string) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Not(conds ...gen.Condition) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Or(conds ...gen.Condition) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Select(conds ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Where(conds ...gen.Condition) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Order(conds ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Distinct(cols ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Omit(cols ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Join(table schema.Tabler, on ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) RightJoin(table schema.Tabler, on ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Group(cols ...field.Expr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Having(conds ...gen.Condition) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Limit(limit int) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Offset(offset int) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Unscoped() IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Create(values ...*model.AgentToolDraft) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Create(values)
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) CreateInBatches(values []*model.AgentToolDraft, 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 agentToolDraftDo) Save(values ...*model.AgentToolDraft) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Save(values)
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) First() (*model.AgentToolDraft, error) {
|
||||
if result, err := a.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Take() (*model.AgentToolDraft, error) {
|
||||
if result, err := a.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Last() (*model.AgentToolDraft, error) {
|
||||
if result, err := a.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Find() ([]*model.AgentToolDraft, error) {
|
||||
result, err := a.DO.Find()
|
||||
return result.([]*model.AgentToolDraft), err
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AgentToolDraft, err error) {
|
||||
buf := make([]*model.AgentToolDraft, 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 agentToolDraftDo) FindInBatches(result *[]*model.AgentToolDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return a.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Attrs(attrs ...field.AssignExpr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Assign(attrs ...field.AssignExpr) IAgentToolDraftDo {
|
||||
return a.withDO(a.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Joins(fields ...field.RelationField) IAgentToolDraftDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Joins(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Preload(fields ...field.RelationField) IAgentToolDraftDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Preload(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) FirstOrInit() (*model.AgentToolDraft, error) {
|
||||
if result, err := a.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) FirstOrCreate() (*model.AgentToolDraft, error) {
|
||||
if result, err := a.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) FindByPage(offset int, limit int) (result []*model.AgentToolDraft, 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 agentToolDraftDo) 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 agentToolDraftDo) Scan(result interface{}) (err error) {
|
||||
return a.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (a agentToolDraftDo) Delete(models ...*model.AgentToolDraft) (result gen.ResultInfo, err error) {
|
||||
return a.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (a *agentToolDraftDo) withDO(do gen.Dao) *agentToolDraftDo {
|
||||
a.DO = *do.(*gen.DO)
|
||||
return a
|
||||
}
|
||||
@@ -0,0 +1,421 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newAgentToolVersion(db *gorm.DB, opts ...gen.DOOption) agentToolVersion {
|
||||
_agentToolVersion := agentToolVersion{}
|
||||
|
||||
_agentToolVersion.agentToolVersionDo.UseDB(db, opts...)
|
||||
_agentToolVersion.agentToolVersionDo.UseModel(&model.AgentToolVersion{})
|
||||
|
||||
tableName := _agentToolVersion.agentToolVersionDo.TableName()
|
||||
_agentToolVersion.ALL = field.NewAsterisk(tableName)
|
||||
_agentToolVersion.ID = field.NewInt64(tableName, "id")
|
||||
_agentToolVersion.AgentID = field.NewInt64(tableName, "agent_id")
|
||||
_agentToolVersion.PluginID = field.NewInt64(tableName, "plugin_id")
|
||||
_agentToolVersion.ToolID = field.NewInt64(tableName, "tool_id")
|
||||
_agentToolVersion.AgentVersion = field.NewString(tableName, "agent_version")
|
||||
_agentToolVersion.ToolName = field.NewString(tableName, "tool_name")
|
||||
_agentToolVersion.ToolVersion = field.NewString(tableName, "tool_version")
|
||||
_agentToolVersion.SubURL = field.NewString(tableName, "sub_url")
|
||||
_agentToolVersion.Method = field.NewString(tableName, "method")
|
||||
_agentToolVersion.Operation = field.NewField(tableName, "operation")
|
||||
_agentToolVersion.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
|
||||
_agentToolVersion.fillFieldMap()
|
||||
|
||||
return _agentToolVersion
|
||||
}
|
||||
|
||||
// agentToolVersion Agent Tool Version
|
||||
type agentToolVersion struct {
|
||||
agentToolVersionDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Primary Key ID
|
||||
AgentID field.Int64 // Agent ID
|
||||
PluginID field.Int64 // Plugin ID
|
||||
ToolID field.Int64 // Tool ID
|
||||
AgentVersion field.String // Agent Tool Version
|
||||
ToolName field.String // Tool Name
|
||||
ToolVersion field.String // Tool Version, e.g. v1.0.0
|
||||
SubURL field.String // Sub URL Path
|
||||
Method field.String // HTTP Request Method
|
||||
Operation field.Field // Tool Openapi Operation Schema
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (a agentToolVersion) Table(newTableName string) *agentToolVersion {
|
||||
a.agentToolVersionDo.UseTable(newTableName)
|
||||
return a.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (a agentToolVersion) As(alias string) *agentToolVersion {
|
||||
a.agentToolVersionDo.DO = *(a.agentToolVersionDo.As(alias).(*gen.DO))
|
||||
return a.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (a *agentToolVersion) updateTableName(table string) *agentToolVersion {
|
||||
a.ALL = field.NewAsterisk(table)
|
||||
a.ID = field.NewInt64(table, "id")
|
||||
a.AgentID = field.NewInt64(table, "agent_id")
|
||||
a.PluginID = field.NewInt64(table, "plugin_id")
|
||||
a.ToolID = field.NewInt64(table, "tool_id")
|
||||
a.AgentVersion = field.NewString(table, "agent_version")
|
||||
a.ToolName = field.NewString(table, "tool_name")
|
||||
a.ToolVersion = field.NewString(table, "tool_version")
|
||||
a.SubURL = field.NewString(table, "sub_url")
|
||||
a.Method = field.NewString(table, "method")
|
||||
a.Operation = field.NewField(table, "operation")
|
||||
a.CreatedAt = field.NewInt64(table, "created_at")
|
||||
|
||||
a.fillFieldMap()
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *agentToolVersion) 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 *agentToolVersion) fillFieldMap() {
|
||||
a.fieldMap = make(map[string]field.Expr, 11)
|
||||
a.fieldMap["id"] = a.ID
|
||||
a.fieldMap["agent_id"] = a.AgentID
|
||||
a.fieldMap["plugin_id"] = a.PluginID
|
||||
a.fieldMap["tool_id"] = a.ToolID
|
||||
a.fieldMap["agent_version"] = a.AgentVersion
|
||||
a.fieldMap["tool_name"] = a.ToolName
|
||||
a.fieldMap["tool_version"] = a.ToolVersion
|
||||
a.fieldMap["sub_url"] = a.SubURL
|
||||
a.fieldMap["method"] = a.Method
|
||||
a.fieldMap["operation"] = a.Operation
|
||||
a.fieldMap["created_at"] = a.CreatedAt
|
||||
}
|
||||
|
||||
func (a agentToolVersion) clone(db *gorm.DB) agentToolVersion {
|
||||
a.agentToolVersionDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a agentToolVersion) replaceDB(db *gorm.DB) agentToolVersion {
|
||||
a.agentToolVersionDo.ReplaceDB(db)
|
||||
return a
|
||||
}
|
||||
|
||||
type agentToolVersionDo struct{ gen.DO }
|
||||
|
||||
type IAgentToolVersionDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IAgentToolVersionDo
|
||||
WithContext(ctx context.Context) IAgentToolVersionDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IAgentToolVersionDo
|
||||
WriteDB() IAgentToolVersionDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IAgentToolVersionDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IAgentToolVersionDo
|
||||
Not(conds ...gen.Condition) IAgentToolVersionDo
|
||||
Or(conds ...gen.Condition) IAgentToolVersionDo
|
||||
Select(conds ...field.Expr) IAgentToolVersionDo
|
||||
Where(conds ...gen.Condition) IAgentToolVersionDo
|
||||
Order(conds ...field.Expr) IAgentToolVersionDo
|
||||
Distinct(cols ...field.Expr) IAgentToolVersionDo
|
||||
Omit(cols ...field.Expr) IAgentToolVersionDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IAgentToolVersionDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IAgentToolVersionDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IAgentToolVersionDo
|
||||
Group(cols ...field.Expr) IAgentToolVersionDo
|
||||
Having(conds ...gen.Condition) IAgentToolVersionDo
|
||||
Limit(limit int) IAgentToolVersionDo
|
||||
Offset(offset int) IAgentToolVersionDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IAgentToolVersionDo
|
||||
Unscoped() IAgentToolVersionDo
|
||||
Create(values ...*model.AgentToolVersion) error
|
||||
CreateInBatches(values []*model.AgentToolVersion, batchSize int) error
|
||||
Save(values ...*model.AgentToolVersion) error
|
||||
First() (*model.AgentToolVersion, error)
|
||||
Take() (*model.AgentToolVersion, error)
|
||||
Last() (*model.AgentToolVersion, error)
|
||||
Find() ([]*model.AgentToolVersion, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AgentToolVersion, err error)
|
||||
FindInBatches(result *[]*model.AgentToolVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.AgentToolVersion) (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) IAgentToolVersionDo
|
||||
Assign(attrs ...field.AssignExpr) IAgentToolVersionDo
|
||||
Joins(fields ...field.RelationField) IAgentToolVersionDo
|
||||
Preload(fields ...field.RelationField) IAgentToolVersionDo
|
||||
FirstOrInit() (*model.AgentToolVersion, error)
|
||||
FirstOrCreate() (*model.AgentToolVersion, error)
|
||||
FindByPage(offset int, limit int) (result []*model.AgentToolVersion, 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) IAgentToolVersionDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Debug() IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Debug())
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) WithContext(ctx context.Context) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) ReadDB() IAgentToolVersionDo {
|
||||
return a.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) WriteDB() IAgentToolVersionDo {
|
||||
return a.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Session(config *gorm.Session) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Session(config))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Clauses(conds ...clause.Expression) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Returning(value interface{}, columns ...string) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Not(conds ...gen.Condition) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Or(conds ...gen.Condition) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Select(conds ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Where(conds ...gen.Condition) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Order(conds ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Distinct(cols ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Omit(cols ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Join(table schema.Tabler, on ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) RightJoin(table schema.Tabler, on ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Group(cols ...field.Expr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Having(conds ...gen.Condition) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Limit(limit int) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Offset(offset int) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Unscoped() IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Create(values ...*model.AgentToolVersion) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Create(values)
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) CreateInBatches(values []*model.AgentToolVersion, 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 agentToolVersionDo) Save(values ...*model.AgentToolVersion) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Save(values)
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) First() (*model.AgentToolVersion, error) {
|
||||
if result, err := a.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Take() (*model.AgentToolVersion, error) {
|
||||
if result, err := a.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Last() (*model.AgentToolVersion, error) {
|
||||
if result, err := a.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Find() ([]*model.AgentToolVersion, error) {
|
||||
result, err := a.DO.Find()
|
||||
return result.([]*model.AgentToolVersion), err
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AgentToolVersion, err error) {
|
||||
buf := make([]*model.AgentToolVersion, 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 agentToolVersionDo) FindInBatches(result *[]*model.AgentToolVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return a.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Attrs(attrs ...field.AssignExpr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Assign(attrs ...field.AssignExpr) IAgentToolVersionDo {
|
||||
return a.withDO(a.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Joins(fields ...field.RelationField) IAgentToolVersionDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Joins(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Preload(fields ...field.RelationField) IAgentToolVersionDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Preload(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) FirstOrInit() (*model.AgentToolVersion, error) {
|
||||
if result, err := a.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) FirstOrCreate() (*model.AgentToolVersion, error) {
|
||||
if result, err := a.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.AgentToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) FindByPage(offset int, limit int) (result []*model.AgentToolVersion, 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 agentToolVersionDo) 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 agentToolVersionDo) Scan(result interface{}) (err error) {
|
||||
return a.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (a agentToolVersionDo) Delete(models ...*model.AgentToolVersion) (result gen.ResultInfo, err error) {
|
||||
return a.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (a *agentToolVersionDo) withDO(do gen.Dao) *agentToolVersionDo {
|
||||
a.DO = *do.(*gen.DO)
|
||||
return a
|
||||
}
|
||||
167
backend/domain/plugin/internal/dal/query/gen.go
Normal file
167
backend/domain/plugin/internal/dal/query/gen.go
Normal file
@@ -0,0 +1,167 @@
|
||||
// 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)
|
||||
AgentToolDraft *agentToolDraft
|
||||
AgentToolVersion *agentToolVersion
|
||||
Plugin *plugin
|
||||
PluginDraft *pluginDraft
|
||||
PluginOauthAuth *pluginOauthAuth
|
||||
PluginVersion *pluginVersion
|
||||
Tool *tool
|
||||
ToolDraft *toolDraft
|
||||
ToolVersion *toolVersion
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
AgentToolDraft = &Q.AgentToolDraft
|
||||
AgentToolVersion = &Q.AgentToolVersion
|
||||
Plugin = &Q.Plugin
|
||||
PluginDraft = &Q.PluginDraft
|
||||
PluginOauthAuth = &Q.PluginOauthAuth
|
||||
PluginVersion = &Q.PluginVersion
|
||||
Tool = &Q.Tool
|
||||
ToolDraft = &Q.ToolDraft
|
||||
ToolVersion = &Q.ToolVersion
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
AgentToolDraft: newAgentToolDraft(db, opts...),
|
||||
AgentToolVersion: newAgentToolVersion(db, opts...),
|
||||
Plugin: newPlugin(db, opts...),
|
||||
PluginDraft: newPluginDraft(db, opts...),
|
||||
PluginOauthAuth: newPluginOauthAuth(db, opts...),
|
||||
PluginVersion: newPluginVersion(db, opts...),
|
||||
Tool: newTool(db, opts...),
|
||||
ToolDraft: newToolDraft(db, opts...),
|
||||
ToolVersion: newToolVersion(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
AgentToolDraft agentToolDraft
|
||||
AgentToolVersion agentToolVersion
|
||||
Plugin plugin
|
||||
PluginDraft pluginDraft
|
||||
PluginOauthAuth pluginOauthAuth
|
||||
PluginVersion pluginVersion
|
||||
Tool tool
|
||||
ToolDraft toolDraft
|
||||
ToolVersion toolVersion
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
AgentToolDraft: q.AgentToolDraft.clone(db),
|
||||
AgentToolVersion: q.AgentToolVersion.clone(db),
|
||||
Plugin: q.Plugin.clone(db),
|
||||
PluginDraft: q.PluginDraft.clone(db),
|
||||
PluginOauthAuth: q.PluginOauthAuth.clone(db),
|
||||
PluginVersion: q.PluginVersion.clone(db),
|
||||
Tool: q.Tool.clone(db),
|
||||
ToolDraft: q.ToolDraft.clone(db),
|
||||
ToolVersion: q.ToolVersion.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,
|
||||
AgentToolDraft: q.AgentToolDraft.replaceDB(db),
|
||||
AgentToolVersion: q.AgentToolVersion.replaceDB(db),
|
||||
Plugin: q.Plugin.replaceDB(db),
|
||||
PluginDraft: q.PluginDraft.replaceDB(db),
|
||||
PluginOauthAuth: q.PluginOauthAuth.replaceDB(db),
|
||||
PluginVersion: q.PluginVersion.replaceDB(db),
|
||||
Tool: q.Tool.replaceDB(db),
|
||||
ToolDraft: q.ToolDraft.replaceDB(db),
|
||||
ToolVersion: q.ToolVersion.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
AgentToolDraft IAgentToolDraftDo
|
||||
AgentToolVersion IAgentToolVersionDo
|
||||
Plugin IPluginDo
|
||||
PluginDraft IPluginDraftDo
|
||||
PluginOauthAuth IPluginOauthAuthDo
|
||||
PluginVersion IPluginVersionDo
|
||||
Tool IToolDo
|
||||
ToolDraft IToolDraftDo
|
||||
ToolVersion IToolVersionDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
AgentToolDraft: q.AgentToolDraft.WithContext(ctx),
|
||||
AgentToolVersion: q.AgentToolVersion.WithContext(ctx),
|
||||
Plugin: q.Plugin.WithContext(ctx),
|
||||
PluginDraft: q.PluginDraft.WithContext(ctx),
|
||||
PluginOauthAuth: q.PluginOauthAuth.WithContext(ctx),
|
||||
PluginVersion: q.PluginVersion.WithContext(ctx),
|
||||
Tool: q.Tool.WithContext(ctx),
|
||||
ToolDraft: q.ToolDraft.WithContext(ctx),
|
||||
ToolVersion: q.ToolVersion.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
|
||||
}
|
||||
429
backend/domain/plugin/internal/dal/query/plugin.gen.go
Normal file
429
backend/domain/plugin/internal/dal/query/plugin.gen.go
Normal file
@@ -0,0 +1,429 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newPlugin(db *gorm.DB, opts ...gen.DOOption) plugin {
|
||||
_plugin := plugin{}
|
||||
|
||||
_plugin.pluginDo.UseDB(db, opts...)
|
||||
_plugin.pluginDo.UseModel(&model.Plugin{})
|
||||
|
||||
tableName := _plugin.pluginDo.TableName()
|
||||
_plugin.ALL = field.NewAsterisk(tableName)
|
||||
_plugin.ID = field.NewInt64(tableName, "id")
|
||||
_plugin.SpaceID = field.NewInt64(tableName, "space_id")
|
||||
_plugin.DeveloperID = field.NewInt64(tableName, "developer_id")
|
||||
_plugin.AppID = field.NewInt64(tableName, "app_id")
|
||||
_plugin.IconURI = field.NewString(tableName, "icon_uri")
|
||||
_plugin.ServerURL = field.NewString(tableName, "server_url")
|
||||
_plugin.PluginType = field.NewInt32(tableName, "plugin_type")
|
||||
_plugin.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_plugin.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_plugin.Version = field.NewString(tableName, "version")
|
||||
_plugin.VersionDesc = field.NewString(tableName, "version_desc")
|
||||
_plugin.Manifest = field.NewField(tableName, "manifest")
|
||||
_plugin.OpenapiDoc = field.NewField(tableName, "openapi_doc")
|
||||
|
||||
_plugin.fillFieldMap()
|
||||
|
||||
return _plugin
|
||||
}
|
||||
|
||||
// plugin Latest Plugin
|
||||
type plugin struct {
|
||||
pluginDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Plugin ID
|
||||
SpaceID field.Int64 // Space ID
|
||||
DeveloperID field.Int64 // Developer ID
|
||||
AppID field.Int64 // Application ID
|
||||
IconURI field.String // Icon URI
|
||||
ServerURL field.String // Server URL
|
||||
PluginType field.Int32 // Plugin Type, 1:http, 6:local
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
Version field.String // Plugin Version, e.g. v1.0.0
|
||||
VersionDesc field.String // Plugin Version Description
|
||||
Manifest field.Field // Plugin Manifest
|
||||
OpenapiDoc field.Field // OpenAPI Document, only stores the root
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p plugin) Table(newTableName string) *plugin {
|
||||
p.pluginDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p plugin) As(alias string) *plugin {
|
||||
p.pluginDo.DO = *(p.pluginDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *plugin) updateTableName(table string) *plugin {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewInt64(table, "id")
|
||||
p.SpaceID = field.NewInt64(table, "space_id")
|
||||
p.DeveloperID = field.NewInt64(table, "developer_id")
|
||||
p.AppID = field.NewInt64(table, "app_id")
|
||||
p.IconURI = field.NewString(table, "icon_uri")
|
||||
p.ServerURL = field.NewString(table, "server_url")
|
||||
p.PluginType = field.NewInt32(table, "plugin_type")
|
||||
p.CreatedAt = field.NewInt64(table, "created_at")
|
||||
p.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
p.Version = field.NewString(table, "version")
|
||||
p.VersionDesc = field.NewString(table, "version_desc")
|
||||
p.Manifest = field.NewField(table, "manifest")
|
||||
p.OpenapiDoc = field.NewField(table, "openapi_doc")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *plugin) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *plugin) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 13)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["space_id"] = p.SpaceID
|
||||
p.fieldMap["developer_id"] = p.DeveloperID
|
||||
p.fieldMap["app_id"] = p.AppID
|
||||
p.fieldMap["icon_uri"] = p.IconURI
|
||||
p.fieldMap["server_url"] = p.ServerURL
|
||||
p.fieldMap["plugin_type"] = p.PluginType
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["version"] = p.Version
|
||||
p.fieldMap["version_desc"] = p.VersionDesc
|
||||
p.fieldMap["manifest"] = p.Manifest
|
||||
p.fieldMap["openapi_doc"] = p.OpenapiDoc
|
||||
}
|
||||
|
||||
func (p plugin) clone(db *gorm.DB) plugin {
|
||||
p.pluginDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p plugin) replaceDB(db *gorm.DB) plugin {
|
||||
p.pluginDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type pluginDo struct{ gen.DO }
|
||||
|
||||
type IPluginDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPluginDo
|
||||
WithContext(ctx context.Context) IPluginDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPluginDo
|
||||
WriteDB() IPluginDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPluginDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPluginDo
|
||||
Not(conds ...gen.Condition) IPluginDo
|
||||
Or(conds ...gen.Condition) IPluginDo
|
||||
Select(conds ...field.Expr) IPluginDo
|
||||
Where(conds ...gen.Condition) IPluginDo
|
||||
Order(conds ...field.Expr) IPluginDo
|
||||
Distinct(cols ...field.Expr) IPluginDo
|
||||
Omit(cols ...field.Expr) IPluginDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPluginDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPluginDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPluginDo
|
||||
Group(cols ...field.Expr) IPluginDo
|
||||
Having(conds ...gen.Condition) IPluginDo
|
||||
Limit(limit int) IPluginDo
|
||||
Offset(offset int) IPluginDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginDo
|
||||
Unscoped() IPluginDo
|
||||
Create(values ...*model.Plugin) error
|
||||
CreateInBatches(values []*model.Plugin, batchSize int) error
|
||||
Save(values ...*model.Plugin) error
|
||||
First() (*model.Plugin, error)
|
||||
Take() (*model.Plugin, error)
|
||||
Last() (*model.Plugin, error)
|
||||
Find() ([]*model.Plugin, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Plugin, err error)
|
||||
FindInBatches(result *[]*model.Plugin, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.Plugin) (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) IPluginDo
|
||||
Assign(attrs ...field.AssignExpr) IPluginDo
|
||||
Joins(fields ...field.RelationField) IPluginDo
|
||||
Preload(fields ...field.RelationField) IPluginDo
|
||||
FirstOrInit() (*model.Plugin, error)
|
||||
FirstOrCreate() (*model.Plugin, error)
|
||||
FindByPage(offset int, limit int) (result []*model.Plugin, 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) IPluginDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p pluginDo) Debug() IPluginDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p pluginDo) WithContext(ctx context.Context) IPluginDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p pluginDo) ReadDB() IPluginDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p pluginDo) WriteDB() IPluginDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p pluginDo) Session(config *gorm.Session) IPluginDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p pluginDo) Clauses(conds ...clause.Expression) IPluginDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Returning(value interface{}, columns ...string) IPluginDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Not(conds ...gen.Condition) IPluginDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Or(conds ...gen.Condition) IPluginDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Select(conds ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Where(conds ...gen.Condition) IPluginDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Order(conds ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Distinct(cols ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Omit(cols ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Join(table schema.Tabler, on ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginDo) RightJoin(table schema.Tabler, on ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Group(cols ...field.Expr) IPluginDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Having(conds ...gen.Condition) IPluginDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Limit(limit int) IPluginDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p pluginDo) Offset(offset int) IPluginDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p pluginDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Unscoped() IPluginDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p pluginDo) Create(values ...*model.Plugin) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p pluginDo) CreateInBatches(values []*model.Plugin, batchSize int) error {
|
||||
return p.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 (p pluginDo) Save(values ...*model.Plugin) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p pluginDo) First() (*model.Plugin, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plugin), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDo) Take() (*model.Plugin, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plugin), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDo) Last() (*model.Plugin, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plugin), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDo) Find() ([]*model.Plugin, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.Plugin), err
|
||||
}
|
||||
|
||||
func (p pluginDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Plugin, err error) {
|
||||
buf := make([]*model.Plugin, 0, batchSize)
|
||||
err = p.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 (p pluginDo) FindInBatches(result *[]*model.Plugin, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p pluginDo) Attrs(attrs ...field.AssignExpr) IPluginDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Assign(attrs ...field.AssignExpr) IPluginDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginDo) Joins(fields ...field.RelationField) IPluginDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginDo) Preload(fields ...field.RelationField) IPluginDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginDo) FirstOrInit() (*model.Plugin, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plugin), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDo) FirstOrCreate() (*model.Plugin, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plugin), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDo) FindByPage(offset int, limit int) (result []*model.Plugin, count int64, err error) {
|
||||
result, err = p.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 = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p pluginDo) Delete(models ...*model.Plugin) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *pluginDo) withDO(do gen.Dao) *pluginDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
425
backend/domain/plugin/internal/dal/query/plugin_draft.gen.go
Normal file
425
backend/domain/plugin/internal/dal/query/plugin_draft.gen.go
Normal file
@@ -0,0 +1,425 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newPluginDraft(db *gorm.DB, opts ...gen.DOOption) pluginDraft {
|
||||
_pluginDraft := pluginDraft{}
|
||||
|
||||
_pluginDraft.pluginDraftDo.UseDB(db, opts...)
|
||||
_pluginDraft.pluginDraftDo.UseModel(&model.PluginDraft{})
|
||||
|
||||
tableName := _pluginDraft.pluginDraftDo.TableName()
|
||||
_pluginDraft.ALL = field.NewAsterisk(tableName)
|
||||
_pluginDraft.ID = field.NewInt64(tableName, "id")
|
||||
_pluginDraft.SpaceID = field.NewInt64(tableName, "space_id")
|
||||
_pluginDraft.DeveloperID = field.NewInt64(tableName, "developer_id")
|
||||
_pluginDraft.AppID = field.NewInt64(tableName, "app_id")
|
||||
_pluginDraft.IconURI = field.NewString(tableName, "icon_uri")
|
||||
_pluginDraft.ServerURL = field.NewString(tableName, "server_url")
|
||||
_pluginDraft.PluginType = field.NewInt32(tableName, "plugin_type")
|
||||
_pluginDraft.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_pluginDraft.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_pluginDraft.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_pluginDraft.Manifest = field.NewField(tableName, "manifest")
|
||||
_pluginDraft.OpenapiDoc = field.NewField(tableName, "openapi_doc")
|
||||
|
||||
_pluginDraft.fillFieldMap()
|
||||
|
||||
return _pluginDraft
|
||||
}
|
||||
|
||||
// pluginDraft Draft Plugin
|
||||
type pluginDraft struct {
|
||||
pluginDraftDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Plugin ID
|
||||
SpaceID field.Int64 // Space ID
|
||||
DeveloperID field.Int64 // Developer ID
|
||||
AppID field.Int64 // Application ID
|
||||
IconURI field.String // Icon URI
|
||||
ServerURL field.String // Server URL
|
||||
PluginType field.Int32 // Plugin Type, 1:http, 6:local
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
DeletedAt field.Field // Delete Time
|
||||
Manifest field.Field // Plugin Manifest
|
||||
OpenapiDoc field.Field // OpenAPI Document, only stores the root
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p pluginDraft) Table(newTableName string) *pluginDraft {
|
||||
p.pluginDraftDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p pluginDraft) As(alias string) *pluginDraft {
|
||||
p.pluginDraftDo.DO = *(p.pluginDraftDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *pluginDraft) updateTableName(table string) *pluginDraft {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewInt64(table, "id")
|
||||
p.SpaceID = field.NewInt64(table, "space_id")
|
||||
p.DeveloperID = field.NewInt64(table, "developer_id")
|
||||
p.AppID = field.NewInt64(table, "app_id")
|
||||
p.IconURI = field.NewString(table, "icon_uri")
|
||||
p.ServerURL = field.NewString(table, "server_url")
|
||||
p.PluginType = field.NewInt32(table, "plugin_type")
|
||||
p.CreatedAt = field.NewInt64(table, "created_at")
|
||||
p.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
p.DeletedAt = field.NewField(table, "deleted_at")
|
||||
p.Manifest = field.NewField(table, "manifest")
|
||||
p.OpenapiDoc = field.NewField(table, "openapi_doc")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *pluginDraft) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *pluginDraft) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 12)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["space_id"] = p.SpaceID
|
||||
p.fieldMap["developer_id"] = p.DeveloperID
|
||||
p.fieldMap["app_id"] = p.AppID
|
||||
p.fieldMap["icon_uri"] = p.IconURI
|
||||
p.fieldMap["server_url"] = p.ServerURL
|
||||
p.fieldMap["plugin_type"] = p.PluginType
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["deleted_at"] = p.DeletedAt
|
||||
p.fieldMap["manifest"] = p.Manifest
|
||||
p.fieldMap["openapi_doc"] = p.OpenapiDoc
|
||||
}
|
||||
|
||||
func (p pluginDraft) clone(db *gorm.DB) pluginDraft {
|
||||
p.pluginDraftDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p pluginDraft) replaceDB(db *gorm.DB) pluginDraft {
|
||||
p.pluginDraftDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type pluginDraftDo struct{ gen.DO }
|
||||
|
||||
type IPluginDraftDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPluginDraftDo
|
||||
WithContext(ctx context.Context) IPluginDraftDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPluginDraftDo
|
||||
WriteDB() IPluginDraftDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPluginDraftDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPluginDraftDo
|
||||
Not(conds ...gen.Condition) IPluginDraftDo
|
||||
Or(conds ...gen.Condition) IPluginDraftDo
|
||||
Select(conds ...field.Expr) IPluginDraftDo
|
||||
Where(conds ...gen.Condition) IPluginDraftDo
|
||||
Order(conds ...field.Expr) IPluginDraftDo
|
||||
Distinct(cols ...field.Expr) IPluginDraftDo
|
||||
Omit(cols ...field.Expr) IPluginDraftDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPluginDraftDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPluginDraftDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPluginDraftDo
|
||||
Group(cols ...field.Expr) IPluginDraftDo
|
||||
Having(conds ...gen.Condition) IPluginDraftDo
|
||||
Limit(limit int) IPluginDraftDo
|
||||
Offset(offset int) IPluginDraftDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginDraftDo
|
||||
Unscoped() IPluginDraftDo
|
||||
Create(values ...*model.PluginDraft) error
|
||||
CreateInBatches(values []*model.PluginDraft, batchSize int) error
|
||||
Save(values ...*model.PluginDraft) error
|
||||
First() (*model.PluginDraft, error)
|
||||
Take() (*model.PluginDraft, error)
|
||||
Last() (*model.PluginDraft, error)
|
||||
Find() ([]*model.PluginDraft, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PluginDraft, err error)
|
||||
FindInBatches(result *[]*model.PluginDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.PluginDraft) (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) IPluginDraftDo
|
||||
Assign(attrs ...field.AssignExpr) IPluginDraftDo
|
||||
Joins(fields ...field.RelationField) IPluginDraftDo
|
||||
Preload(fields ...field.RelationField) IPluginDraftDo
|
||||
FirstOrInit() (*model.PluginDraft, error)
|
||||
FirstOrCreate() (*model.PluginDraft, error)
|
||||
FindByPage(offset int, limit int) (result []*model.PluginDraft, 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) IPluginDraftDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Debug() IPluginDraftDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) WithContext(ctx context.Context) IPluginDraftDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) ReadDB() IPluginDraftDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) WriteDB() IPluginDraftDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Session(config *gorm.Session) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Clauses(conds ...clause.Expression) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Returning(value interface{}, columns ...string) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Not(conds ...gen.Condition) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Or(conds ...gen.Condition) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Select(conds ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Where(conds ...gen.Condition) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Order(conds ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Distinct(cols ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Omit(cols ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Join(table schema.Tabler, on ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) RightJoin(table schema.Tabler, on ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Group(cols ...field.Expr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Having(conds ...gen.Condition) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Limit(limit int) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Offset(offset int) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Unscoped() IPluginDraftDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Create(values ...*model.PluginDraft) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) CreateInBatches(values []*model.PluginDraft, batchSize int) error {
|
||||
return p.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 (p pluginDraftDo) Save(values ...*model.PluginDraft) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) First() (*model.PluginDraft, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Take() (*model.PluginDraft, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Last() (*model.PluginDraft, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Find() ([]*model.PluginDraft, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.PluginDraft), err
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PluginDraft, err error) {
|
||||
buf := make([]*model.PluginDraft, 0, batchSize)
|
||||
err = p.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 (p pluginDraftDo) FindInBatches(result *[]*model.PluginDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Attrs(attrs ...field.AssignExpr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Assign(attrs ...field.AssignExpr) IPluginDraftDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Joins(fields ...field.RelationField) IPluginDraftDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Preload(fields ...field.RelationField) IPluginDraftDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) FirstOrInit() (*model.PluginDraft, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) FirstOrCreate() (*model.PluginDraft, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) FindByPage(offset int, limit int) (result []*model.PluginDraft, count int64, err error) {
|
||||
result, err = p.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 = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p pluginDraftDo) Delete(models ...*model.PluginDraft) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *pluginDraftDo) withDO(do gen.Dao) *pluginDraftDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newPluginOauthAuth(db *gorm.DB, opts ...gen.DOOption) pluginOauthAuth {
|
||||
_pluginOauthAuth := pluginOauthAuth{}
|
||||
|
||||
_pluginOauthAuth.pluginOauthAuthDo.UseDB(db, opts...)
|
||||
_pluginOauthAuth.pluginOauthAuthDo.UseModel(&model.PluginOauthAuth{})
|
||||
|
||||
tableName := _pluginOauthAuth.pluginOauthAuthDo.TableName()
|
||||
_pluginOauthAuth.ALL = field.NewAsterisk(tableName)
|
||||
_pluginOauthAuth.ID = field.NewInt64(tableName, "id")
|
||||
_pluginOauthAuth.UserID = field.NewString(tableName, "user_id")
|
||||
_pluginOauthAuth.PluginID = field.NewInt64(tableName, "plugin_id")
|
||||
_pluginOauthAuth.IsDraft = field.NewBool(tableName, "is_draft")
|
||||
_pluginOauthAuth.OauthConfig = field.NewField(tableName, "oauth_config")
|
||||
_pluginOauthAuth.AccessToken = field.NewString(tableName, "access_token")
|
||||
_pluginOauthAuth.RefreshToken = field.NewString(tableName, "refresh_token")
|
||||
_pluginOauthAuth.TokenExpiredAt = field.NewInt64(tableName, "token_expired_at")
|
||||
_pluginOauthAuth.NextTokenRefreshAt = field.NewInt64(tableName, "next_token_refresh_at")
|
||||
_pluginOauthAuth.LastActiveAt = field.NewInt64(tableName, "last_active_at")
|
||||
_pluginOauthAuth.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_pluginOauthAuth.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
|
||||
_pluginOauthAuth.fillFieldMap()
|
||||
|
||||
return _pluginOauthAuth
|
||||
}
|
||||
|
||||
// pluginOauthAuth Plugin OAuth Authorization Code Info
|
||||
type pluginOauthAuth struct {
|
||||
pluginOauthAuthDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Primary Key
|
||||
UserID field.String // User ID
|
||||
PluginID field.Int64 // Plugin ID
|
||||
IsDraft field.Bool // Is Draft Plugin
|
||||
OauthConfig field.Field // Authorization Code OAuth Config
|
||||
AccessToken field.String // Access Token
|
||||
RefreshToken field.String // Refresh Token
|
||||
TokenExpiredAt field.Int64 // Token Expired in Milliseconds
|
||||
NextTokenRefreshAt field.Int64 // Next Token Refresh Time in Milliseconds
|
||||
LastActiveAt field.Int64 // Last active time in Milliseconds
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p pluginOauthAuth) Table(newTableName string) *pluginOauthAuth {
|
||||
p.pluginOauthAuthDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p pluginOauthAuth) As(alias string) *pluginOauthAuth {
|
||||
p.pluginOauthAuthDo.DO = *(p.pluginOauthAuthDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *pluginOauthAuth) updateTableName(table string) *pluginOauthAuth {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewInt64(table, "id")
|
||||
p.UserID = field.NewString(table, "user_id")
|
||||
p.PluginID = field.NewInt64(table, "plugin_id")
|
||||
p.IsDraft = field.NewBool(table, "is_draft")
|
||||
p.OauthConfig = field.NewField(table, "oauth_config")
|
||||
p.AccessToken = field.NewString(table, "access_token")
|
||||
p.RefreshToken = field.NewString(table, "refresh_token")
|
||||
p.TokenExpiredAt = field.NewInt64(table, "token_expired_at")
|
||||
p.NextTokenRefreshAt = field.NewInt64(table, "next_token_refresh_at")
|
||||
p.LastActiveAt = field.NewInt64(table, "last_active_at")
|
||||
p.CreatedAt = field.NewInt64(table, "created_at")
|
||||
p.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *pluginOauthAuth) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *pluginOauthAuth) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 12)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["user_id"] = p.UserID
|
||||
p.fieldMap["plugin_id"] = p.PluginID
|
||||
p.fieldMap["is_draft"] = p.IsDraft
|
||||
p.fieldMap["oauth_config"] = p.OauthConfig
|
||||
p.fieldMap["access_token"] = p.AccessToken
|
||||
p.fieldMap["refresh_token"] = p.RefreshToken
|
||||
p.fieldMap["token_expired_at"] = p.TokenExpiredAt
|
||||
p.fieldMap["next_token_refresh_at"] = p.NextTokenRefreshAt
|
||||
p.fieldMap["last_active_at"] = p.LastActiveAt
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
}
|
||||
|
||||
func (p pluginOauthAuth) clone(db *gorm.DB) pluginOauthAuth {
|
||||
p.pluginOauthAuthDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p pluginOauthAuth) replaceDB(db *gorm.DB) pluginOauthAuth {
|
||||
p.pluginOauthAuthDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type pluginOauthAuthDo struct{ gen.DO }
|
||||
|
||||
type IPluginOauthAuthDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPluginOauthAuthDo
|
||||
WithContext(ctx context.Context) IPluginOauthAuthDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPluginOauthAuthDo
|
||||
WriteDB() IPluginOauthAuthDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPluginOauthAuthDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPluginOauthAuthDo
|
||||
Not(conds ...gen.Condition) IPluginOauthAuthDo
|
||||
Or(conds ...gen.Condition) IPluginOauthAuthDo
|
||||
Select(conds ...field.Expr) IPluginOauthAuthDo
|
||||
Where(conds ...gen.Condition) IPluginOauthAuthDo
|
||||
Order(conds ...field.Expr) IPluginOauthAuthDo
|
||||
Distinct(cols ...field.Expr) IPluginOauthAuthDo
|
||||
Omit(cols ...field.Expr) IPluginOauthAuthDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPluginOauthAuthDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPluginOauthAuthDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPluginOauthAuthDo
|
||||
Group(cols ...field.Expr) IPluginOauthAuthDo
|
||||
Having(conds ...gen.Condition) IPluginOauthAuthDo
|
||||
Limit(limit int) IPluginOauthAuthDo
|
||||
Offset(offset int) IPluginOauthAuthDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginOauthAuthDo
|
||||
Unscoped() IPluginOauthAuthDo
|
||||
Create(values ...*model.PluginOauthAuth) error
|
||||
CreateInBatches(values []*model.PluginOauthAuth, batchSize int) error
|
||||
Save(values ...*model.PluginOauthAuth) error
|
||||
First() (*model.PluginOauthAuth, error)
|
||||
Take() (*model.PluginOauthAuth, error)
|
||||
Last() (*model.PluginOauthAuth, error)
|
||||
Find() ([]*model.PluginOauthAuth, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PluginOauthAuth, err error)
|
||||
FindInBatches(result *[]*model.PluginOauthAuth, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.PluginOauthAuth) (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) IPluginOauthAuthDo
|
||||
Assign(attrs ...field.AssignExpr) IPluginOauthAuthDo
|
||||
Joins(fields ...field.RelationField) IPluginOauthAuthDo
|
||||
Preload(fields ...field.RelationField) IPluginOauthAuthDo
|
||||
FirstOrInit() (*model.PluginOauthAuth, error)
|
||||
FirstOrCreate() (*model.PluginOauthAuth, error)
|
||||
FindByPage(offset int, limit int) (result []*model.PluginOauthAuth, 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) IPluginOauthAuthDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Debug() IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) WithContext(ctx context.Context) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) ReadDB() IPluginOauthAuthDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) WriteDB() IPluginOauthAuthDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Session(config *gorm.Session) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Clauses(conds ...clause.Expression) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Returning(value interface{}, columns ...string) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Not(conds ...gen.Condition) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Or(conds ...gen.Condition) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Select(conds ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Where(conds ...gen.Condition) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Order(conds ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Distinct(cols ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Omit(cols ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Join(table schema.Tabler, on ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) RightJoin(table schema.Tabler, on ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Group(cols ...field.Expr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Having(conds ...gen.Condition) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Limit(limit int) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Offset(offset int) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Unscoped() IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Create(values ...*model.PluginOauthAuth) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) CreateInBatches(values []*model.PluginOauthAuth, batchSize int) error {
|
||||
return p.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 (p pluginOauthAuthDo) Save(values ...*model.PluginOauthAuth) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) First() (*model.PluginOauthAuth, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginOauthAuth), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Take() (*model.PluginOauthAuth, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginOauthAuth), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Last() (*model.PluginOauthAuth, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginOauthAuth), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Find() ([]*model.PluginOauthAuth, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.PluginOauthAuth), err
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PluginOauthAuth, err error) {
|
||||
buf := make([]*model.PluginOauthAuth, 0, batchSize)
|
||||
err = p.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 (p pluginOauthAuthDo) FindInBatches(result *[]*model.PluginOauthAuth, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Attrs(attrs ...field.AssignExpr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Assign(attrs ...field.AssignExpr) IPluginOauthAuthDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Joins(fields ...field.RelationField) IPluginOauthAuthDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Preload(fields ...field.RelationField) IPluginOauthAuthDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) FirstOrInit() (*model.PluginOauthAuth, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginOauthAuth), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) FirstOrCreate() (*model.PluginOauthAuth, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginOauthAuth), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) FindByPage(offset int, limit int) (result []*model.PluginOauthAuth, count int64, err error) {
|
||||
result, err = p.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 = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p pluginOauthAuthDo) Delete(models ...*model.PluginOauthAuth) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *pluginOauthAuthDo) withDO(do gen.Dao) *pluginOauthAuthDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
433
backend/domain/plugin/internal/dal/query/plugin_version.gen.go
Normal file
433
backend/domain/plugin/internal/dal/query/plugin_version.gen.go
Normal file
@@ -0,0 +1,433 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newPluginVersion(db *gorm.DB, opts ...gen.DOOption) pluginVersion {
|
||||
_pluginVersion := pluginVersion{}
|
||||
|
||||
_pluginVersion.pluginVersionDo.UseDB(db, opts...)
|
||||
_pluginVersion.pluginVersionDo.UseModel(&model.PluginVersion{})
|
||||
|
||||
tableName := _pluginVersion.pluginVersionDo.TableName()
|
||||
_pluginVersion.ALL = field.NewAsterisk(tableName)
|
||||
_pluginVersion.ID = field.NewInt64(tableName, "id")
|
||||
_pluginVersion.SpaceID = field.NewInt64(tableName, "space_id")
|
||||
_pluginVersion.DeveloperID = field.NewInt64(tableName, "developer_id")
|
||||
_pluginVersion.PluginID = field.NewInt64(tableName, "plugin_id")
|
||||
_pluginVersion.AppID = field.NewInt64(tableName, "app_id")
|
||||
_pluginVersion.IconURI = field.NewString(tableName, "icon_uri")
|
||||
_pluginVersion.ServerURL = field.NewString(tableName, "server_url")
|
||||
_pluginVersion.PluginType = field.NewInt32(tableName, "plugin_type")
|
||||
_pluginVersion.Version = field.NewString(tableName, "version")
|
||||
_pluginVersion.VersionDesc = field.NewString(tableName, "version_desc")
|
||||
_pluginVersion.Manifest = field.NewField(tableName, "manifest")
|
||||
_pluginVersion.OpenapiDoc = field.NewField(tableName, "openapi_doc")
|
||||
_pluginVersion.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_pluginVersion.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_pluginVersion.fillFieldMap()
|
||||
|
||||
return _pluginVersion
|
||||
}
|
||||
|
||||
// pluginVersion Plugin Version
|
||||
type pluginVersion struct {
|
||||
pluginVersionDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Primary Key ID
|
||||
SpaceID field.Int64 // Space ID
|
||||
DeveloperID field.Int64 // Developer ID
|
||||
PluginID field.Int64 // Plugin ID
|
||||
AppID field.Int64 // Application ID
|
||||
IconURI field.String // Icon URI
|
||||
ServerURL field.String // Server URL
|
||||
PluginType field.Int32 // Plugin Type, 1:http, 6:local
|
||||
Version field.String // Plugin Version, e.g. v1.0.0
|
||||
VersionDesc field.String // Plugin Version Description
|
||||
Manifest field.Field // Plugin Manifest
|
||||
OpenapiDoc field.Field // OpenAPI Document, only stores the root
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
DeletedAt field.Field // Delete Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p pluginVersion) Table(newTableName string) *pluginVersion {
|
||||
p.pluginVersionDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p pluginVersion) As(alias string) *pluginVersion {
|
||||
p.pluginVersionDo.DO = *(p.pluginVersionDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *pluginVersion) updateTableName(table string) *pluginVersion {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewInt64(table, "id")
|
||||
p.SpaceID = field.NewInt64(table, "space_id")
|
||||
p.DeveloperID = field.NewInt64(table, "developer_id")
|
||||
p.PluginID = field.NewInt64(table, "plugin_id")
|
||||
p.AppID = field.NewInt64(table, "app_id")
|
||||
p.IconURI = field.NewString(table, "icon_uri")
|
||||
p.ServerURL = field.NewString(table, "server_url")
|
||||
p.PluginType = field.NewInt32(table, "plugin_type")
|
||||
p.Version = field.NewString(table, "version")
|
||||
p.VersionDesc = field.NewString(table, "version_desc")
|
||||
p.Manifest = field.NewField(table, "manifest")
|
||||
p.OpenapiDoc = field.NewField(table, "openapi_doc")
|
||||
p.CreatedAt = field.NewInt64(table, "created_at")
|
||||
p.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *pluginVersion) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *pluginVersion) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 14)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["space_id"] = p.SpaceID
|
||||
p.fieldMap["developer_id"] = p.DeveloperID
|
||||
p.fieldMap["plugin_id"] = p.PluginID
|
||||
p.fieldMap["app_id"] = p.AppID
|
||||
p.fieldMap["icon_uri"] = p.IconURI
|
||||
p.fieldMap["server_url"] = p.ServerURL
|
||||
p.fieldMap["plugin_type"] = p.PluginType
|
||||
p.fieldMap["version"] = p.Version
|
||||
p.fieldMap["version_desc"] = p.VersionDesc
|
||||
p.fieldMap["manifest"] = p.Manifest
|
||||
p.fieldMap["openapi_doc"] = p.OpenapiDoc
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["deleted_at"] = p.DeletedAt
|
||||
}
|
||||
|
||||
func (p pluginVersion) clone(db *gorm.DB) pluginVersion {
|
||||
p.pluginVersionDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p pluginVersion) replaceDB(db *gorm.DB) pluginVersion {
|
||||
p.pluginVersionDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type pluginVersionDo struct{ gen.DO }
|
||||
|
||||
type IPluginVersionDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPluginVersionDo
|
||||
WithContext(ctx context.Context) IPluginVersionDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPluginVersionDo
|
||||
WriteDB() IPluginVersionDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPluginVersionDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPluginVersionDo
|
||||
Not(conds ...gen.Condition) IPluginVersionDo
|
||||
Or(conds ...gen.Condition) IPluginVersionDo
|
||||
Select(conds ...field.Expr) IPluginVersionDo
|
||||
Where(conds ...gen.Condition) IPluginVersionDo
|
||||
Order(conds ...field.Expr) IPluginVersionDo
|
||||
Distinct(cols ...field.Expr) IPluginVersionDo
|
||||
Omit(cols ...field.Expr) IPluginVersionDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPluginVersionDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPluginVersionDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPluginVersionDo
|
||||
Group(cols ...field.Expr) IPluginVersionDo
|
||||
Having(conds ...gen.Condition) IPluginVersionDo
|
||||
Limit(limit int) IPluginVersionDo
|
||||
Offset(offset int) IPluginVersionDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginVersionDo
|
||||
Unscoped() IPluginVersionDo
|
||||
Create(values ...*model.PluginVersion) error
|
||||
CreateInBatches(values []*model.PluginVersion, batchSize int) error
|
||||
Save(values ...*model.PluginVersion) error
|
||||
First() (*model.PluginVersion, error)
|
||||
Take() (*model.PluginVersion, error)
|
||||
Last() (*model.PluginVersion, error)
|
||||
Find() ([]*model.PluginVersion, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PluginVersion, err error)
|
||||
FindInBatches(result *[]*model.PluginVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.PluginVersion) (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) IPluginVersionDo
|
||||
Assign(attrs ...field.AssignExpr) IPluginVersionDo
|
||||
Joins(fields ...field.RelationField) IPluginVersionDo
|
||||
Preload(fields ...field.RelationField) IPluginVersionDo
|
||||
FirstOrInit() (*model.PluginVersion, error)
|
||||
FirstOrCreate() (*model.PluginVersion, error)
|
||||
FindByPage(offset int, limit int) (result []*model.PluginVersion, 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) IPluginVersionDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Debug() IPluginVersionDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) WithContext(ctx context.Context) IPluginVersionDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) ReadDB() IPluginVersionDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) WriteDB() IPluginVersionDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Session(config *gorm.Session) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Clauses(conds ...clause.Expression) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Returning(value interface{}, columns ...string) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Not(conds ...gen.Condition) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Or(conds ...gen.Condition) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Select(conds ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Where(conds ...gen.Condition) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Order(conds ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Distinct(cols ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Omit(cols ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Join(table schema.Tabler, on ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) RightJoin(table schema.Tabler, on ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Group(cols ...field.Expr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Having(conds ...gen.Condition) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Limit(limit int) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Offset(offset int) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Unscoped() IPluginVersionDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Create(values ...*model.PluginVersion) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) CreateInBatches(values []*model.PluginVersion, batchSize int) error {
|
||||
return p.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 (p pluginVersionDo) Save(values ...*model.PluginVersion) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) First() (*model.PluginVersion, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Take() (*model.PluginVersion, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Last() (*model.PluginVersion, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Find() ([]*model.PluginVersion, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.PluginVersion), err
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PluginVersion, err error) {
|
||||
buf := make([]*model.PluginVersion, 0, batchSize)
|
||||
err = p.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 (p pluginVersionDo) FindInBatches(result *[]*model.PluginVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Attrs(attrs ...field.AssignExpr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Assign(attrs ...field.AssignExpr) IPluginVersionDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Joins(fields ...field.RelationField) IPluginVersionDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Preload(fields ...field.RelationField) IPluginVersionDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) FirstOrInit() (*model.PluginVersion, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) FirstOrCreate() (*model.PluginVersion, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PluginVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) FindByPage(offset int, limit int) (result []*model.PluginVersion, count int64, err error) {
|
||||
result, err = p.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 = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p pluginVersionDo) Delete(models ...*model.PluginVersion) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *pluginVersionDo) withDO(do gen.Dao) *pluginVersionDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
413
backend/domain/plugin/internal/dal/query/tool.gen.go
Normal file
413
backend/domain/plugin/internal/dal/query/tool.gen.go
Normal file
@@ -0,0 +1,413 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newTool(db *gorm.DB, opts ...gen.DOOption) tool {
|
||||
_tool := tool{}
|
||||
|
||||
_tool.toolDo.UseDB(db, opts...)
|
||||
_tool.toolDo.UseModel(&model.Tool{})
|
||||
|
||||
tableName := _tool.toolDo.TableName()
|
||||
_tool.ALL = field.NewAsterisk(tableName)
|
||||
_tool.ID = field.NewInt64(tableName, "id")
|
||||
_tool.PluginID = field.NewInt64(tableName, "plugin_id")
|
||||
_tool.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_tool.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_tool.Version = field.NewString(tableName, "version")
|
||||
_tool.SubURL = field.NewString(tableName, "sub_url")
|
||||
_tool.Method = field.NewString(tableName, "method")
|
||||
_tool.Operation = field.NewField(tableName, "operation")
|
||||
_tool.ActivatedStatus = field.NewInt32(tableName, "activated_status")
|
||||
|
||||
_tool.fillFieldMap()
|
||||
|
||||
return _tool
|
||||
}
|
||||
|
||||
// tool Latest Tool
|
||||
type tool struct {
|
||||
toolDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Tool ID
|
||||
PluginID field.Int64 // Plugin ID
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
Version field.String // Tool Version, e.g. v1.0.0
|
||||
SubURL field.String // Sub URL Path
|
||||
Method field.String // HTTP Request Method
|
||||
Operation field.Field // Tool Openapi Operation Schema
|
||||
ActivatedStatus field.Int32 // 0:activated; 1:deactivated
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t tool) Table(newTableName string) *tool {
|
||||
t.toolDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t tool) As(alias string) *tool {
|
||||
t.toolDo.DO = *(t.toolDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *tool) updateTableName(table string) *tool {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.ID = field.NewInt64(table, "id")
|
||||
t.PluginID = field.NewInt64(table, "plugin_id")
|
||||
t.CreatedAt = field.NewInt64(table, "created_at")
|
||||
t.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
t.Version = field.NewString(table, "version")
|
||||
t.SubURL = field.NewString(table, "sub_url")
|
||||
t.Method = field.NewString(table, "method")
|
||||
t.Operation = field.NewField(table, "operation")
|
||||
t.ActivatedStatus = field.NewInt32(table, "activated_status")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tool) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *tool) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 9)
|
||||
t.fieldMap["id"] = t.ID
|
||||
t.fieldMap["plugin_id"] = t.PluginID
|
||||
t.fieldMap["created_at"] = t.CreatedAt
|
||||
t.fieldMap["updated_at"] = t.UpdatedAt
|
||||
t.fieldMap["version"] = t.Version
|
||||
t.fieldMap["sub_url"] = t.SubURL
|
||||
t.fieldMap["method"] = t.Method
|
||||
t.fieldMap["operation"] = t.Operation
|
||||
t.fieldMap["activated_status"] = t.ActivatedStatus
|
||||
}
|
||||
|
||||
func (t tool) clone(db *gorm.DB) tool {
|
||||
t.toolDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t tool) replaceDB(db *gorm.DB) tool {
|
||||
t.toolDo.ReplaceDB(db)
|
||||
return t
|
||||
}
|
||||
|
||||
type toolDo struct{ gen.DO }
|
||||
|
||||
type IToolDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IToolDo
|
||||
WithContext(ctx context.Context) IToolDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IToolDo
|
||||
WriteDB() IToolDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IToolDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IToolDo
|
||||
Not(conds ...gen.Condition) IToolDo
|
||||
Or(conds ...gen.Condition) IToolDo
|
||||
Select(conds ...field.Expr) IToolDo
|
||||
Where(conds ...gen.Condition) IToolDo
|
||||
Order(conds ...field.Expr) IToolDo
|
||||
Distinct(cols ...field.Expr) IToolDo
|
||||
Omit(cols ...field.Expr) IToolDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IToolDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IToolDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IToolDo
|
||||
Group(cols ...field.Expr) IToolDo
|
||||
Having(conds ...gen.Condition) IToolDo
|
||||
Limit(limit int) IToolDo
|
||||
Offset(offset int) IToolDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IToolDo
|
||||
Unscoped() IToolDo
|
||||
Create(values ...*model.Tool) error
|
||||
CreateInBatches(values []*model.Tool, batchSize int) error
|
||||
Save(values ...*model.Tool) error
|
||||
First() (*model.Tool, error)
|
||||
Take() (*model.Tool, error)
|
||||
Last() (*model.Tool, error)
|
||||
Find() ([]*model.Tool, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Tool, err error)
|
||||
FindInBatches(result *[]*model.Tool, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.Tool) (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) IToolDo
|
||||
Assign(attrs ...field.AssignExpr) IToolDo
|
||||
Joins(fields ...field.RelationField) IToolDo
|
||||
Preload(fields ...field.RelationField) IToolDo
|
||||
FirstOrInit() (*model.Tool, error)
|
||||
FirstOrCreate() (*model.Tool, error)
|
||||
FindByPage(offset int, limit int) (result []*model.Tool, 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) IToolDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (t toolDo) Debug() IToolDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t toolDo) WithContext(ctx context.Context) IToolDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t toolDo) ReadDB() IToolDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t toolDo) WriteDB() IToolDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t toolDo) Session(config *gorm.Session) IToolDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t toolDo) Clauses(conds ...clause.Expression) IToolDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t toolDo) Returning(value interface{}, columns ...string) IToolDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t toolDo) Not(conds ...gen.Condition) IToolDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t toolDo) Or(conds ...gen.Condition) IToolDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t toolDo) Select(conds ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t toolDo) Where(conds ...gen.Condition) IToolDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t toolDo) Order(conds ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t toolDo) Distinct(cols ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t toolDo) Omit(cols ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t toolDo) Join(table schema.Tabler, on ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t toolDo) LeftJoin(table schema.Tabler, on ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t toolDo) RightJoin(table schema.Tabler, on ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t toolDo) Group(cols ...field.Expr) IToolDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t toolDo) Having(conds ...gen.Condition) IToolDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t toolDo) Limit(limit int) IToolDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t toolDo) Offset(offset int) IToolDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t toolDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IToolDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t toolDo) Unscoped() IToolDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t toolDo) Create(values ...*model.Tool) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t toolDo) CreateInBatches(values []*model.Tool, batchSize int) error {
|
||||
return t.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 (t toolDo) Save(values ...*model.Tool) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t toolDo) First() (*model.Tool, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Tool), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDo) Take() (*model.Tool, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Tool), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDo) Last() (*model.Tool, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Tool), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDo) Find() ([]*model.Tool, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*model.Tool), err
|
||||
}
|
||||
|
||||
func (t toolDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Tool, err error) {
|
||||
buf := make([]*model.Tool, 0, batchSize)
|
||||
err = t.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 (t toolDo) FindInBatches(result *[]*model.Tool, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t toolDo) Attrs(attrs ...field.AssignExpr) IToolDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t toolDo) Assign(attrs ...field.AssignExpr) IToolDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t toolDo) Joins(fields ...field.RelationField) IToolDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t toolDo) Preload(fields ...field.RelationField) IToolDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t toolDo) FirstOrInit() (*model.Tool, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Tool), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDo) FirstOrCreate() (*model.Tool, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Tool), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDo) FindByPage(offset int, limit int) (result []*model.Tool, count int64, err error) {
|
||||
result, err = t.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 = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t toolDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t toolDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t toolDo) Delete(models ...*model.Tool) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (t *toolDo) withDO(do gen.Dao) *toolDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
||||
413
backend/domain/plugin/internal/dal/query/tool_draft.gen.go
Normal file
413
backend/domain/plugin/internal/dal/query/tool_draft.gen.go
Normal file
@@ -0,0 +1,413 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newToolDraft(db *gorm.DB, opts ...gen.DOOption) toolDraft {
|
||||
_toolDraft := toolDraft{}
|
||||
|
||||
_toolDraft.toolDraftDo.UseDB(db, opts...)
|
||||
_toolDraft.toolDraftDo.UseModel(&model.ToolDraft{})
|
||||
|
||||
tableName := _toolDraft.toolDraftDo.TableName()
|
||||
_toolDraft.ALL = field.NewAsterisk(tableName)
|
||||
_toolDraft.ID = field.NewInt64(tableName, "id")
|
||||
_toolDraft.PluginID = field.NewInt64(tableName, "plugin_id")
|
||||
_toolDraft.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_toolDraft.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
_toolDraft.SubURL = field.NewString(tableName, "sub_url")
|
||||
_toolDraft.Method = field.NewString(tableName, "method")
|
||||
_toolDraft.Operation = field.NewField(tableName, "operation")
|
||||
_toolDraft.DebugStatus = field.NewInt32(tableName, "debug_status")
|
||||
_toolDraft.ActivatedStatus = field.NewInt32(tableName, "activated_status")
|
||||
|
||||
_toolDraft.fillFieldMap()
|
||||
|
||||
return _toolDraft
|
||||
}
|
||||
|
||||
// toolDraft Draft Tool
|
||||
type toolDraft struct {
|
||||
toolDraftDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Tool ID
|
||||
PluginID field.Int64 // Plugin ID
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
UpdatedAt field.Int64 // Update Time in Milliseconds
|
||||
SubURL field.String // Sub URL Path
|
||||
Method field.String // HTTP Request Method
|
||||
Operation field.Field // Tool Openapi Operation Schema
|
||||
DebugStatus field.Int32 // 0:not pass; 1:pass
|
||||
ActivatedStatus field.Int32 // 0:activated; 1:deactivated
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t toolDraft) Table(newTableName string) *toolDraft {
|
||||
t.toolDraftDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t toolDraft) As(alias string) *toolDraft {
|
||||
t.toolDraftDo.DO = *(t.toolDraftDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *toolDraft) updateTableName(table string) *toolDraft {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.ID = field.NewInt64(table, "id")
|
||||
t.PluginID = field.NewInt64(table, "plugin_id")
|
||||
t.CreatedAt = field.NewInt64(table, "created_at")
|
||||
t.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
t.SubURL = field.NewString(table, "sub_url")
|
||||
t.Method = field.NewString(table, "method")
|
||||
t.Operation = field.NewField(table, "operation")
|
||||
t.DebugStatus = field.NewInt32(table, "debug_status")
|
||||
t.ActivatedStatus = field.NewInt32(table, "activated_status")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *toolDraft) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *toolDraft) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 9)
|
||||
t.fieldMap["id"] = t.ID
|
||||
t.fieldMap["plugin_id"] = t.PluginID
|
||||
t.fieldMap["created_at"] = t.CreatedAt
|
||||
t.fieldMap["updated_at"] = t.UpdatedAt
|
||||
t.fieldMap["sub_url"] = t.SubURL
|
||||
t.fieldMap["method"] = t.Method
|
||||
t.fieldMap["operation"] = t.Operation
|
||||
t.fieldMap["debug_status"] = t.DebugStatus
|
||||
t.fieldMap["activated_status"] = t.ActivatedStatus
|
||||
}
|
||||
|
||||
func (t toolDraft) clone(db *gorm.DB) toolDraft {
|
||||
t.toolDraftDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t toolDraft) replaceDB(db *gorm.DB) toolDraft {
|
||||
t.toolDraftDo.ReplaceDB(db)
|
||||
return t
|
||||
}
|
||||
|
||||
type toolDraftDo struct{ gen.DO }
|
||||
|
||||
type IToolDraftDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IToolDraftDo
|
||||
WithContext(ctx context.Context) IToolDraftDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IToolDraftDo
|
||||
WriteDB() IToolDraftDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IToolDraftDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IToolDraftDo
|
||||
Not(conds ...gen.Condition) IToolDraftDo
|
||||
Or(conds ...gen.Condition) IToolDraftDo
|
||||
Select(conds ...field.Expr) IToolDraftDo
|
||||
Where(conds ...gen.Condition) IToolDraftDo
|
||||
Order(conds ...field.Expr) IToolDraftDo
|
||||
Distinct(cols ...field.Expr) IToolDraftDo
|
||||
Omit(cols ...field.Expr) IToolDraftDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IToolDraftDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IToolDraftDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IToolDraftDo
|
||||
Group(cols ...field.Expr) IToolDraftDo
|
||||
Having(conds ...gen.Condition) IToolDraftDo
|
||||
Limit(limit int) IToolDraftDo
|
||||
Offset(offset int) IToolDraftDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IToolDraftDo
|
||||
Unscoped() IToolDraftDo
|
||||
Create(values ...*model.ToolDraft) error
|
||||
CreateInBatches(values []*model.ToolDraft, batchSize int) error
|
||||
Save(values ...*model.ToolDraft) error
|
||||
First() (*model.ToolDraft, error)
|
||||
Take() (*model.ToolDraft, error)
|
||||
Last() (*model.ToolDraft, error)
|
||||
Find() ([]*model.ToolDraft, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ToolDraft, err error)
|
||||
FindInBatches(result *[]*model.ToolDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ToolDraft) (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) IToolDraftDo
|
||||
Assign(attrs ...field.AssignExpr) IToolDraftDo
|
||||
Joins(fields ...field.RelationField) IToolDraftDo
|
||||
Preload(fields ...field.RelationField) IToolDraftDo
|
||||
FirstOrInit() (*model.ToolDraft, error)
|
||||
FirstOrCreate() (*model.ToolDraft, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ToolDraft, 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) IToolDraftDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Debug() IToolDraftDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t toolDraftDo) WithContext(ctx context.Context) IToolDraftDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) ReadDB() IToolDraftDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t toolDraftDo) WriteDB() IToolDraftDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Session(config *gorm.Session) IToolDraftDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Clauses(conds ...clause.Expression) IToolDraftDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Returning(value interface{}, columns ...string) IToolDraftDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Not(conds ...gen.Condition) IToolDraftDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Or(conds ...gen.Condition) IToolDraftDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Select(conds ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Where(conds ...gen.Condition) IToolDraftDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Order(conds ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Distinct(cols ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Omit(cols ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Join(table schema.Tabler, on ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) LeftJoin(table schema.Tabler, on ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) RightJoin(table schema.Tabler, on ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Group(cols ...field.Expr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Having(conds ...gen.Condition) IToolDraftDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Limit(limit int) IToolDraftDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Offset(offset int) IToolDraftDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IToolDraftDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Unscoped() IToolDraftDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Create(values ...*model.ToolDraft) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t toolDraftDo) CreateInBatches(values []*model.ToolDraft, batchSize int) error {
|
||||
return t.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 (t toolDraftDo) Save(values ...*model.ToolDraft) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t toolDraftDo) First() (*model.ToolDraft, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Take() (*model.ToolDraft, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Last() (*model.ToolDraft, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Find() ([]*model.ToolDraft, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*model.ToolDraft), err
|
||||
}
|
||||
|
||||
func (t toolDraftDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ToolDraft, err error) {
|
||||
buf := make([]*model.ToolDraft, 0, batchSize)
|
||||
err = t.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 (t toolDraftDo) FindInBatches(result *[]*model.ToolDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Attrs(attrs ...field.AssignExpr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Assign(attrs ...field.AssignExpr) IToolDraftDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Joins(fields ...field.RelationField) IToolDraftDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Preload(fields ...field.RelationField) IToolDraftDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t toolDraftDo) FirstOrInit() (*model.ToolDraft, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDraftDo) FirstOrCreate() (*model.ToolDraft, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolDraft), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolDraftDo) FindByPage(offset int, limit int) (result []*model.ToolDraft, count int64, err error) {
|
||||
result, err = t.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 = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t toolDraftDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t toolDraftDo) Delete(models ...*model.ToolDraft) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (t *toolDraftDo) withDO(do gen.Dao) *toolDraftDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
||||
413
backend/domain/plugin/internal/dal/query/tool_version.gen.go
Normal file
413
backend/domain/plugin/internal/dal/query/tool_version.gen.go
Normal file
@@ -0,0 +1,413 @@
|
||||
// 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/plugin/internal/dal/model"
|
||||
)
|
||||
|
||||
func newToolVersion(db *gorm.DB, opts ...gen.DOOption) toolVersion {
|
||||
_toolVersion := toolVersion{}
|
||||
|
||||
_toolVersion.toolVersionDo.UseDB(db, opts...)
|
||||
_toolVersion.toolVersionDo.UseModel(&model.ToolVersion{})
|
||||
|
||||
tableName := _toolVersion.toolVersionDo.TableName()
|
||||
_toolVersion.ALL = field.NewAsterisk(tableName)
|
||||
_toolVersion.ID = field.NewInt64(tableName, "id")
|
||||
_toolVersion.ToolID = field.NewInt64(tableName, "tool_id")
|
||||
_toolVersion.PluginID = field.NewInt64(tableName, "plugin_id")
|
||||
_toolVersion.Version = field.NewString(tableName, "version")
|
||||
_toolVersion.SubURL = field.NewString(tableName, "sub_url")
|
||||
_toolVersion.Method = field.NewString(tableName, "method")
|
||||
_toolVersion.Operation = field.NewField(tableName, "operation")
|
||||
_toolVersion.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_toolVersion.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_toolVersion.fillFieldMap()
|
||||
|
||||
return _toolVersion
|
||||
}
|
||||
|
||||
// toolVersion Tool Version
|
||||
type toolVersion struct {
|
||||
toolVersionDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // Primary Key ID
|
||||
ToolID field.Int64 // Tool ID
|
||||
PluginID field.Int64 // Plugin ID
|
||||
Version field.String // Tool Version, e.g. v1.0.0
|
||||
SubURL field.String // Sub URL Path
|
||||
Method field.String // HTTP Request Method
|
||||
Operation field.Field // Tool Openapi Operation Schema
|
||||
CreatedAt field.Int64 // Create Time in Milliseconds
|
||||
DeletedAt field.Field // Delete Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t toolVersion) Table(newTableName string) *toolVersion {
|
||||
t.toolVersionDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t toolVersion) As(alias string) *toolVersion {
|
||||
t.toolVersionDo.DO = *(t.toolVersionDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *toolVersion) updateTableName(table string) *toolVersion {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.ID = field.NewInt64(table, "id")
|
||||
t.ToolID = field.NewInt64(table, "tool_id")
|
||||
t.PluginID = field.NewInt64(table, "plugin_id")
|
||||
t.Version = field.NewString(table, "version")
|
||||
t.SubURL = field.NewString(table, "sub_url")
|
||||
t.Method = field.NewString(table, "method")
|
||||
t.Operation = field.NewField(table, "operation")
|
||||
t.CreatedAt = field.NewInt64(table, "created_at")
|
||||
t.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *toolVersion) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *toolVersion) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 9)
|
||||
t.fieldMap["id"] = t.ID
|
||||
t.fieldMap["tool_id"] = t.ToolID
|
||||
t.fieldMap["plugin_id"] = t.PluginID
|
||||
t.fieldMap["version"] = t.Version
|
||||
t.fieldMap["sub_url"] = t.SubURL
|
||||
t.fieldMap["method"] = t.Method
|
||||
t.fieldMap["operation"] = t.Operation
|
||||
t.fieldMap["created_at"] = t.CreatedAt
|
||||
t.fieldMap["deleted_at"] = t.DeletedAt
|
||||
}
|
||||
|
||||
func (t toolVersion) clone(db *gorm.DB) toolVersion {
|
||||
t.toolVersionDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t toolVersion) replaceDB(db *gorm.DB) toolVersion {
|
||||
t.toolVersionDo.ReplaceDB(db)
|
||||
return t
|
||||
}
|
||||
|
||||
type toolVersionDo struct{ gen.DO }
|
||||
|
||||
type IToolVersionDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IToolVersionDo
|
||||
WithContext(ctx context.Context) IToolVersionDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IToolVersionDo
|
||||
WriteDB() IToolVersionDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IToolVersionDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IToolVersionDo
|
||||
Not(conds ...gen.Condition) IToolVersionDo
|
||||
Or(conds ...gen.Condition) IToolVersionDo
|
||||
Select(conds ...field.Expr) IToolVersionDo
|
||||
Where(conds ...gen.Condition) IToolVersionDo
|
||||
Order(conds ...field.Expr) IToolVersionDo
|
||||
Distinct(cols ...field.Expr) IToolVersionDo
|
||||
Omit(cols ...field.Expr) IToolVersionDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IToolVersionDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IToolVersionDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IToolVersionDo
|
||||
Group(cols ...field.Expr) IToolVersionDo
|
||||
Having(conds ...gen.Condition) IToolVersionDo
|
||||
Limit(limit int) IToolVersionDo
|
||||
Offset(offset int) IToolVersionDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IToolVersionDo
|
||||
Unscoped() IToolVersionDo
|
||||
Create(values ...*model.ToolVersion) error
|
||||
CreateInBatches(values []*model.ToolVersion, batchSize int) error
|
||||
Save(values ...*model.ToolVersion) error
|
||||
First() (*model.ToolVersion, error)
|
||||
Take() (*model.ToolVersion, error)
|
||||
Last() (*model.ToolVersion, error)
|
||||
Find() ([]*model.ToolVersion, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ToolVersion, err error)
|
||||
FindInBatches(result *[]*model.ToolVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ToolVersion) (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) IToolVersionDo
|
||||
Assign(attrs ...field.AssignExpr) IToolVersionDo
|
||||
Joins(fields ...field.RelationField) IToolVersionDo
|
||||
Preload(fields ...field.RelationField) IToolVersionDo
|
||||
FirstOrInit() (*model.ToolVersion, error)
|
||||
FirstOrCreate() (*model.ToolVersion, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ToolVersion, 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) IToolVersionDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Debug() IToolVersionDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t toolVersionDo) WithContext(ctx context.Context) IToolVersionDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) ReadDB() IToolVersionDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t toolVersionDo) WriteDB() IToolVersionDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Session(config *gorm.Session) IToolVersionDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Clauses(conds ...clause.Expression) IToolVersionDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Returning(value interface{}, columns ...string) IToolVersionDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Not(conds ...gen.Condition) IToolVersionDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Or(conds ...gen.Condition) IToolVersionDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Select(conds ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Where(conds ...gen.Condition) IToolVersionDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Order(conds ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Distinct(cols ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Omit(cols ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Join(table schema.Tabler, on ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) LeftJoin(table schema.Tabler, on ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) RightJoin(table schema.Tabler, on ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Group(cols ...field.Expr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Having(conds ...gen.Condition) IToolVersionDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Limit(limit int) IToolVersionDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Offset(offset int) IToolVersionDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IToolVersionDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Unscoped() IToolVersionDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Create(values ...*model.ToolVersion) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t toolVersionDo) CreateInBatches(values []*model.ToolVersion, batchSize int) error {
|
||||
return t.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 (t toolVersionDo) Save(values ...*model.ToolVersion) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t toolVersionDo) First() (*model.ToolVersion, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Take() (*model.ToolVersion, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Last() (*model.ToolVersion, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Find() ([]*model.ToolVersion, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*model.ToolVersion), err
|
||||
}
|
||||
|
||||
func (t toolVersionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ToolVersion, err error) {
|
||||
buf := make([]*model.ToolVersion, 0, batchSize)
|
||||
err = t.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 (t toolVersionDo) FindInBatches(result *[]*model.ToolVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Attrs(attrs ...field.AssignExpr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Assign(attrs ...field.AssignExpr) IToolVersionDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Joins(fields ...field.RelationField) IToolVersionDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Preload(fields ...field.RelationField) IToolVersionDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t toolVersionDo) FirstOrInit() (*model.ToolVersion, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolVersionDo) FirstOrCreate() (*model.ToolVersion, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ToolVersion), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t toolVersionDo) FindByPage(offset int, limit int) (result []*model.ToolVersion, count int64, err error) {
|
||||
result, err = t.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 = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t toolVersionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t toolVersionDo) Delete(models ...*model.ToolVersion) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (t *toolVersionDo) withDO(do gen.Dao) *toolVersionDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
||||
202
backend/domain/plugin/internal/dal/tool.go
Normal file
202
backend/domain/plugin/internal/dal/tool.go
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewToolDAO(db *gorm.DB, idGen idgen.IDGenerator) *ToolDAO {
|
||||
return &ToolDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type ToolDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type toolPO model.Tool
|
||||
|
||||
func (t toolPO) ToDO() *entity.ToolInfo {
|
||||
return &entity.ToolInfo{
|
||||
ID: t.ID,
|
||||
PluginID: t.PluginID,
|
||||
CreatedAt: t.CreatedAt,
|
||||
UpdatedAt: t.UpdatedAt,
|
||||
Version: &t.Version,
|
||||
SubURL: &t.SubURL,
|
||||
Method: ptr.Of(t.Method),
|
||||
Operation: t.Operation,
|
||||
ActivatedStatus: ptr.Of(plugin.ActivatedStatus(t.ActivatedStatus)),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *ToolDAO) getSelected(opt *ToolSelectedOption) (selected []field.Expr) {
|
||||
if opt == nil {
|
||||
return selected
|
||||
}
|
||||
|
||||
table := t.query.Tool
|
||||
|
||||
if opt.ToolID {
|
||||
selected = append(selected, table.ID)
|
||||
}
|
||||
if opt.ActivatedStatus {
|
||||
selected = append(selected, table.ActivatedStatus)
|
||||
}
|
||||
if opt.ToolMethod {
|
||||
selected = append(selected, table.Method)
|
||||
}
|
||||
if opt.ToolSubURL {
|
||||
selected = append(selected, table.SubURL)
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
func (t *ToolDAO) Get(ctx context.Context, toolID int64) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := t.query.Tool
|
||||
tl, err := table.WithContext(ctx).
|
||||
Where(table.ID.Eq(toolID)).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
tool = toolPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (t *ToolDAO) MGet(ctx context.Context, toolIDs []int64, opt *ToolSelectedOption) (tools []*entity.ToolInfo, err error) {
|
||||
tools = make([]*entity.ToolInfo, 0, len(toolIDs))
|
||||
|
||||
table := t.query.Tool
|
||||
chunks := slices.Chunks(toolIDs, 20)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
tls, err := table.WithContext(ctx).
|
||||
Select(t.getSelected(opt)...).
|
||||
Where(table.ID.In(chunk...)).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, toolPO(*tl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *ToolDAO) GetAll(ctx context.Context, pluginID int64) (tools []*entity.ToolInfo, err error) {
|
||||
const limit = 20
|
||||
table := t.query.Tool
|
||||
cursor := int64(0)
|
||||
|
||||
for {
|
||||
tls, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.PluginID.Eq(pluginID),
|
||||
table.ID.Gt(cursor),
|
||||
).
|
||||
Order(table.ID.Asc()).
|
||||
Limit(limit).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, toolPO(*tl).ToDO())
|
||||
}
|
||||
|
||||
if len(tls) < limit {
|
||||
break
|
||||
}
|
||||
|
||||
cursor = tls[len(tls)-1].ID
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *ToolDAO) BatchCreateWithTX(ctx context.Context, tx *query.QueryTx, tools []*entity.ToolInfo) (err error) {
|
||||
tls := make([]*model.Tool, 0, len(tools))
|
||||
|
||||
for _, tool := range tools {
|
||||
if tool.GetVersion() == "" {
|
||||
return fmt.Errorf("invalid tool version")
|
||||
}
|
||||
tls = append(tls, &model.Tool{
|
||||
ID: tool.ID,
|
||||
PluginID: tool.PluginID,
|
||||
Version: tool.GetVersion(),
|
||||
SubURL: tool.GetSubURL(),
|
||||
Method: tool.GetMethod(),
|
||||
ActivatedStatus: int32(tool.GetActivatedStatus()),
|
||||
Operation: tool.Operation,
|
||||
})
|
||||
}
|
||||
|
||||
err = tx.Tool.WithContext(ctx).CreateInBatches(tls, 10)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolDAO) DeleteAllWithTX(ctx context.Context, tx *query.QueryTx, pluginID int64) (err error) {
|
||||
const limit = 20
|
||||
table := tx.Tool
|
||||
for {
|
||||
info, err := table.WithContext(ctx).
|
||||
Where(table.PluginID.Eq(pluginID)).
|
||||
Limit(limit).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.RowsAffected < limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
466
backend/domain/plugin/internal/dal/tool_draft.go
Normal file
466
backend/domain/plugin/internal/dal/tool_draft.go
Normal file
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewToolDraftDAO(db *gorm.DB, idGen idgen.IDGenerator) *ToolDraftDAO {
|
||||
return &ToolDraftDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type ToolDraftDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type toolDraftPO model.ToolDraft
|
||||
|
||||
func (t toolDraftPO) ToDO() *entity.ToolInfo {
|
||||
return &entity.ToolInfo{
|
||||
ID: t.ID,
|
||||
PluginID: t.PluginID,
|
||||
CreatedAt: t.CreatedAt,
|
||||
UpdatedAt: t.UpdatedAt,
|
||||
SubURL: &t.SubURL,
|
||||
Method: ptr.Of(t.Method),
|
||||
Operation: t.Operation,
|
||||
DebugStatus: ptr.Of(common.APIDebugStatus(t.DebugStatus)),
|
||||
ActivatedStatus: ptr.Of(plugin.ActivatedStatus(t.ActivatedStatus)),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) getSelected(opt *ToolSelectedOption) (selected []field.Expr) {
|
||||
if opt == nil {
|
||||
return selected
|
||||
}
|
||||
|
||||
table := t.query.ToolDraft
|
||||
|
||||
if opt.ToolID {
|
||||
selected = append(selected, table.ID)
|
||||
}
|
||||
if opt.ActivatedStatus {
|
||||
selected = append(selected, table.ActivatedStatus)
|
||||
}
|
||||
if opt.DebugStatus {
|
||||
selected = append(selected, table.DebugStatus)
|
||||
}
|
||||
if opt.ToolMethod {
|
||||
selected = append(selected, table.Method)
|
||||
}
|
||||
if opt.ToolSubURL {
|
||||
selected = append(selected, table.SubURL)
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) Create(ctx context.Context, tool *entity.ToolInfo) (toolID int64, err error) {
|
||||
id, err := t.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
err = t.query.ToolDraft.WithContext(ctx).Create(&model.ToolDraft{
|
||||
ID: id,
|
||||
PluginID: tool.PluginID,
|
||||
SubURL: tool.GetSubURL(),
|
||||
Method: tool.GetMethod(),
|
||||
ActivatedStatus: int32(tool.GetActivatedStatus()),
|
||||
DebugStatus: int32(tool.GetDebugStatus()),
|
||||
Operation: tool.Operation,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) Get(ctx context.Context, toolID int64) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := t.query.ToolDraft
|
||||
tl, err := table.WithContext(ctx).
|
||||
Where(table.ID.Eq(toolID)).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
tool = toolDraftPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) MGet(ctx context.Context, toolIDs []int64, opt *ToolSelectedOption) (tools []*entity.ToolInfo, err error) {
|
||||
tools = make([]*entity.ToolInfo, 0, len(toolIDs))
|
||||
|
||||
table := t.query.ToolDraft
|
||||
chunks := slices.Chunks(toolIDs, 10)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
tls, err := table.WithContext(ctx).
|
||||
Select(t.getSelected(opt)...).
|
||||
Where(table.ID.In(chunk...)).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, toolDraftPO(*tl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) GetWithAPI(ctx context.Context, pluginID int64, api entity.UniqueToolAPI) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := t.query.ToolDraft
|
||||
tl, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.PluginID.Eq(pluginID),
|
||||
table.SubURL.Eq(api.SubURL),
|
||||
table.Method.Eq(api.Method),
|
||||
).
|
||||
First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
tool = toolDraftPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) MGetWithAPIs(ctx context.Context, pluginID int64, apis []entity.UniqueToolAPI, opt *ToolSelectedOption) (tools map[entity.UniqueToolAPI]*entity.ToolInfo, err error) {
|
||||
tools = make(map[entity.UniqueToolAPI]*entity.ToolInfo, len(apis))
|
||||
|
||||
table := t.query.ToolDraft
|
||||
chunks := slices.Chunks(apis, 10)
|
||||
for _, chunk := range chunks {
|
||||
sq := table.Where(
|
||||
table.Where(
|
||||
table.SubURL.Eq(chunk[0].SubURL),
|
||||
table.Method.Eq(chunk[0].Method),
|
||||
),
|
||||
)
|
||||
for i, api := range chunk {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
sq = sq.Or(
|
||||
table.SubURL.Eq(api.SubURL),
|
||||
table.Method.Eq(api.Method),
|
||||
)
|
||||
}
|
||||
|
||||
tls, err := table.WithContext(ctx).
|
||||
Select(t.getSelected(opt)...).
|
||||
Where(table.PluginID.Eq(pluginID)).
|
||||
Where(sq).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, tl := range tls {
|
||||
api := entity.UniqueToolAPI{
|
||||
SubURL: tl.SubURL,
|
||||
Method: tl.Method,
|
||||
}
|
||||
tools[api] = toolDraftPO(*tl).ToDO()
|
||||
}
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) GetAll(ctx context.Context, pluginID int64, opt *ToolSelectedOption) (tools []*entity.ToolInfo, err error) {
|
||||
const limit = 20
|
||||
table := t.query.ToolDraft
|
||||
cursor := int64(0)
|
||||
|
||||
for {
|
||||
tls, err := table.WithContext(ctx).
|
||||
Select(t.getSelected(opt)...).
|
||||
Where(
|
||||
table.PluginID.Eq(pluginID),
|
||||
table.ID.Gt(cursor),
|
||||
).
|
||||
Order(table.ID.Asc()).
|
||||
Limit(limit).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, toolDraftPO(*tl).ToDO())
|
||||
}
|
||||
|
||||
if len(tls) < limit {
|
||||
break
|
||||
}
|
||||
|
||||
cursor = tls[len(tls)-1].ID
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) Delete(ctx context.Context, toolID int64) (err error) {
|
||||
table := t.query.ToolDraft
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(toolID)).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) Update(ctx context.Context, tool *entity.ToolInfo) (err error) {
|
||||
m, err := t.getToolDraftUpdateMap(tool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
table := t.query.ToolDraft
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(tool.ID)).
|
||||
Updates(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) List(ctx context.Context, pluginID int64, pageInfo entity.PageInfo) (tools []*entity.ToolInfo, total int64, err error) {
|
||||
if pageInfo.SortBy == nil || pageInfo.OrderByACS == nil {
|
||||
return nil, 0, fmt.Errorf("sortBy or orderByACS is empty")
|
||||
}
|
||||
|
||||
if *pageInfo.SortBy != entity.SortByCreatedAt {
|
||||
return nil, 0, fmt.Errorf("invalid sortBy '%v'", *pageInfo.SortBy)
|
||||
}
|
||||
|
||||
table := t.query.ToolDraft
|
||||
var orderExpr field.Expr
|
||||
if *pageInfo.OrderByACS {
|
||||
orderExpr = table.CreatedAt.Asc()
|
||||
} else {
|
||||
orderExpr = table.CreatedAt.Desc()
|
||||
}
|
||||
|
||||
offset := (pageInfo.Page - 1) * pageInfo.Size
|
||||
tls, total, err := table.WithContext(ctx).
|
||||
Where(table.PluginID.Eq(pluginID)).
|
||||
Order(orderExpr).
|
||||
FindByPage(offset, pageInfo.Size)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
tools = make([]*entity.ToolInfo, 0, len(tls))
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, toolDraftPO(*tl).ToDO())
|
||||
}
|
||||
|
||||
return tools, total, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) DeleteAllWithTX(ctx context.Context, tx *query.QueryTx, pluginID int64) (err error) {
|
||||
const limit = 20
|
||||
table := tx.ToolDraft
|
||||
|
||||
for {
|
||||
info, err := table.WithContext(ctx).
|
||||
Where(table.PluginID.Eq(pluginID)).
|
||||
Limit(limit).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.RowsAffected < limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) BatchCreateWithTX(ctx context.Context, tx *query.QueryTx, tools []*entity.ToolInfo) (toolIDs []int64, err error) {
|
||||
toolIDs = make([]int64, 0, len(tools))
|
||||
tls := make([]*model.ToolDraft, 0, len(tools))
|
||||
|
||||
for _, tool := range tools {
|
||||
id, err := t.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
toolIDs = append(toolIDs, id)
|
||||
|
||||
tls = append(tls, &model.ToolDraft{
|
||||
ID: id,
|
||||
PluginID: tool.PluginID,
|
||||
SubURL: tool.GetSubURL(),
|
||||
Method: tool.GetMethod(),
|
||||
ActivatedStatus: int32(tool.GetActivatedStatus()),
|
||||
DebugStatus: int32(tool.GetDebugStatus()),
|
||||
Operation: tool.Operation,
|
||||
})
|
||||
}
|
||||
|
||||
table := tx.ToolDraft
|
||||
err = table.CreateInBatches(tls, 10)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return toolIDs, nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) BatchUpdateWithTX(ctx context.Context, tx *query.QueryTx, tools []*entity.ToolInfo) (err error) {
|
||||
for _, tool := range tools {
|
||||
m, err := t.getToolDraftUpdateMap(tool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
table := tx.ToolDraft
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.Eq(tool.ID)).
|
||||
Updates(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) UpdateWithTX(ctx context.Context, tx *query.QueryTx, tool *entity.ToolInfo) (err error) {
|
||||
m, err := t.getToolDraftUpdateMap(tool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
table := tx.ToolDraft
|
||||
_, err = table.Debug().WithContext(ctx).
|
||||
Where(table.ID.Eq(tool.ID)).
|
||||
Updates(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) ResetAllDebugStatusWithTX(ctx context.Context, tx *query.QueryTx, pluginID int64) (err error) {
|
||||
const limit = 50
|
||||
table := tx.ToolDraft
|
||||
lastID := int64(0)
|
||||
|
||||
for {
|
||||
var toolIDs []int64
|
||||
err = table.WithContext(ctx).
|
||||
Where(table.PluginID.Eq(pluginID)).
|
||||
Where(table.ID.Gt(lastID)).
|
||||
Order(table.ID.Asc()).
|
||||
Limit(limit).
|
||||
Pluck(table.ID, &toolIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(toolIDs) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ID.In(toolIDs...)).
|
||||
Updates(map[string]any{
|
||||
table.DebugStatus.ColumnName().String(): int32(common.APIDebugStatus_DebugWaiting),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lastID = toolIDs[len(toolIDs)-1]
|
||||
|
||||
if len(toolIDs) < limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolDraftDAO) getToolDraftUpdateMap(tool *entity.ToolInfo) (map[string]any, error) {
|
||||
table := t.query.ToolDraft
|
||||
|
||||
updateMap := map[string]any{}
|
||||
if tool.Operation != nil {
|
||||
b, err := json.Marshal(tool.Operation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updateMap[table.Operation.ColumnName().String()] = b
|
||||
}
|
||||
if tool.SubURL != nil {
|
||||
updateMap[table.SubURL.ColumnName().String()] = *tool.SubURL
|
||||
}
|
||||
if tool.Method != nil {
|
||||
updateMap[table.Method.ColumnName().String()] = *tool.Method
|
||||
}
|
||||
if tool.ActivatedStatus != nil {
|
||||
updateMap[table.ActivatedStatus.ColumnName().String()] = int32(*tool.ActivatedStatus)
|
||||
}
|
||||
if tool.DebugStatus != nil {
|
||||
updateMap[table.DebugStatus.ColumnName().String()] = int32(*tool.DebugStatus)
|
||||
}
|
||||
|
||||
return updateMap, nil
|
||||
}
|
||||
157
backend/domain/plugin/internal/dal/tool_version.go
Normal file
157
backend/domain/plugin/internal/dal/tool_version.go
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
)
|
||||
|
||||
func NewToolVersionDAO(db *gorm.DB, idGen idgen.IDGenerator) *ToolVersionDAO {
|
||||
return &ToolVersionDAO{
|
||||
idGen: idGen,
|
||||
query: query.Use(db),
|
||||
}
|
||||
}
|
||||
|
||||
type ToolVersionDAO struct {
|
||||
idGen idgen.IDGenerator
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
type toolVersionPO model.ToolVersion
|
||||
|
||||
func (t toolVersionPO) ToDO() *entity.ToolInfo {
|
||||
return &entity.ToolInfo{
|
||||
ID: t.ToolID,
|
||||
PluginID: t.PluginID,
|
||||
CreatedAt: t.CreatedAt,
|
||||
Version: &t.Version,
|
||||
SubURL: &t.SubURL,
|
||||
Method: ptr.Of(t.Method),
|
||||
Operation: t.Operation,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *ToolVersionDAO) Get(ctx context.Context, vTool entity.VersionTool) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
table := t.query.ToolVersion
|
||||
|
||||
if vTool.Version == "" {
|
||||
return nil, false, fmt.Errorf("invalid tool version")
|
||||
}
|
||||
|
||||
tl, err := table.WithContext(ctx).
|
||||
Where(
|
||||
table.ToolID.Eq(vTool.ToolID),
|
||||
table.Version.Eq(vTool.Version),
|
||||
).
|
||||
First()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
tool = toolVersionPO(*tl).ToDO()
|
||||
|
||||
return tool, true, nil
|
||||
}
|
||||
|
||||
func (t *ToolVersionDAO) MGet(ctx context.Context, vTools []entity.VersionTool) (tools []*entity.ToolInfo, err error) {
|
||||
tools = make([]*entity.ToolInfo, 0, len(vTools))
|
||||
|
||||
table := t.query.ToolVersion
|
||||
chunks := slices.Chunks(vTools, 10)
|
||||
|
||||
for _, chunk := range chunks {
|
||||
q := table.WithContext(ctx).
|
||||
Where(
|
||||
table.Where(
|
||||
table.ToolID.Eq(chunk[0].ToolID),
|
||||
table.Version.Eq(chunk[0].Version),
|
||||
),
|
||||
)
|
||||
|
||||
for i, v := range chunk {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
q = q.Or(
|
||||
table.ToolID.Eq(v.ToolID),
|
||||
table.Version.Eq(v.Version),
|
||||
)
|
||||
}
|
||||
|
||||
tls, err := q.Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tl := range tls {
|
||||
tools = append(tools, toolVersionPO(*tl).ToDO())
|
||||
}
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *ToolVersionDAO) BatchCreateWithTX(ctx context.Context, tx *query.QueryTx, tools []*entity.ToolInfo) (err error) {
|
||||
tls := make([]*model.ToolVersion, 0, len(tools))
|
||||
|
||||
for _, tool := range tools {
|
||||
if tool.GetVersion() == "" {
|
||||
return fmt.Errorf("invalid tool version")
|
||||
}
|
||||
|
||||
id, err := t.idGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tls = append(tls, &model.ToolVersion{
|
||||
ID: id,
|
||||
ToolID: tool.ID,
|
||||
PluginID: tool.PluginID,
|
||||
Version: tool.GetVersion(),
|
||||
SubURL: tool.GetSubURL(),
|
||||
Method: tool.GetMethod(),
|
||||
Operation: tool.Operation,
|
||||
})
|
||||
}
|
||||
|
||||
err = tx.ToolVersion.WithContext(ctx).CreateInBatches(tls, 10)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ToolVersionDAO) DeleteWithTX(ctx context.Context, tx *query.QueryTx, toolID int64) (err error) {
|
||||
table := tx.ToolVersion
|
||||
_, err = table.WithContext(ctx).
|
||||
Where(table.ToolID.Eq(toolID)).
|
||||
Delete()
|
||||
return err
|
||||
}
|
||||
379
backend/domain/plugin/internal/encoder/req_encode.go
Normal file
379
backend/domain/plugin/internal/encoder/req_encode.go
Normal file
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
* 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 encoder
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
"github.com/shopspring/decimal"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
)
|
||||
|
||||
func EncodeBodyWithContentType(contentType string, body map[string]any) ([]byte, error) {
|
||||
switch contentType {
|
||||
case plugin.MediaTypeJson, plugin.MediaTypeProblemJson:
|
||||
return jsonBodyEncoder(body)
|
||||
case plugin.MediaTypeFormURLEncoded:
|
||||
return urlencodedBodyEncoder(body)
|
||||
case plugin.MediaTypeYaml, plugin.MediaTypeXYaml:
|
||||
return yamlBodyEncoder(body)
|
||||
default:
|
||||
return nil, fmt.Errorf("[EncodeBodyWithContentType] unsupported contentType=%s", contentType)
|
||||
}
|
||||
}
|
||||
|
||||
func jsonBodyEncoder(body map[string]any) ([]byte, error) {
|
||||
b, err := sonic.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[jsonBodyEncoder] failed to marshal body, err=%v", err)
|
||||
}
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func yamlBodyEncoder(body map[string]any) ([]byte, error) {
|
||||
b, err := yaml.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[yamlBodyEncoder] failed to marshal body, err=%v", err)
|
||||
}
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func urlencodedBodyEncoder(body map[string]any) ([]byte, error) {
|
||||
objectStr := ""
|
||||
res := url.Values{}
|
||||
sm := &openapi3.SerializationMethod{
|
||||
Style: openapi3.SerializationForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
for k, value := range body {
|
||||
switch val := value.(type) {
|
||||
case map[string]any:
|
||||
vStr, err := encodeObjectParam(sm, k, val)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(objectStr) > 0 {
|
||||
vStr = "&" + vStr
|
||||
}
|
||||
|
||||
objectStr += vStr
|
||||
case []any:
|
||||
vStr, err := encodeArrayParam(sm, k, val)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(objectStr) > 0 {
|
||||
vStr = "&" + vStr
|
||||
}
|
||||
|
||||
objectStr += vStr
|
||||
case string:
|
||||
res.Add(k, val)
|
||||
default:
|
||||
res.Add(k, MustString(val))
|
||||
}
|
||||
}
|
||||
|
||||
if len(objectStr) > 0 {
|
||||
return []byte(res.Encode() + "&" + url.QueryEscape(objectStr)), nil
|
||||
}
|
||||
|
||||
return []byte(res.Encode()), nil
|
||||
}
|
||||
|
||||
func EncodeParameter(param *openapi3.Parameter, value any) (string, error) {
|
||||
sm, err := param.SerializationMethod()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch v := value.(type) {
|
||||
case map[string]any:
|
||||
return encodeObjectParam(sm, param.Name, v)
|
||||
case []any:
|
||||
return encodeArrayParam(sm, param.Name, v)
|
||||
default:
|
||||
return encodePrimitiveParam(sm, param.Name, v)
|
||||
}
|
||||
}
|
||||
|
||||
func encodePrimitiveParam(sm *openapi3.SerializationMethod, paramName string, val any) (string, error) {
|
||||
var prefix string
|
||||
switch sm.Style {
|
||||
case openapi3.SerializationSimple:
|
||||
// A prefix is empty for style "simple".
|
||||
case openapi3.SerializationLabel:
|
||||
prefix = "."
|
||||
case openapi3.SerializationMatrix:
|
||||
prefix = ";" + url.QueryEscape(paramName) + "="
|
||||
case openapi3.SerializationForm:
|
||||
result := url.QueryEscape(paramName) + "=" + url.QueryEscape(MustString(val))
|
||||
return result, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid serialization method: style=%q, explode=%v", sm.Style, sm.Explode)
|
||||
}
|
||||
|
||||
raw := MustString(val)
|
||||
|
||||
return prefix + raw, nil
|
||||
}
|
||||
|
||||
func encodeArrayParam(sm *openapi3.SerializationMethod, paramName string, arrVal []any) (string, error) {
|
||||
var prefix, delim string
|
||||
switch {
|
||||
case sm.Style == openapi3.SerializationMatrix && !sm.Explode:
|
||||
prefix = ";" + paramName + "="
|
||||
delim = ","
|
||||
case sm.Style == openapi3.SerializationMatrix && sm.Explode:
|
||||
prefix = ";" + paramName + "="
|
||||
delim = ";" + paramName + "="
|
||||
case sm.Style == openapi3.SerializationLabel && !sm.Explode:
|
||||
prefix = "."
|
||||
delim = ","
|
||||
case sm.Style == openapi3.SerializationLabel && sm.Explode:
|
||||
prefix = "."
|
||||
delim = "."
|
||||
case sm.Style == openapi3.SerializationForm && sm.Explode:
|
||||
prefix = paramName + "="
|
||||
delim = "&" + paramName + "="
|
||||
case sm.Style == openapi3.SerializationForm && !sm.Explode:
|
||||
prefix = paramName + "="
|
||||
delim = ","
|
||||
case sm.Style == openapi3.SerializationSimple:
|
||||
delim = ","
|
||||
case sm.Style == openapi3.SerializationSpaceDelimited && !sm.Explode:
|
||||
delim = ","
|
||||
case sm.Style == openapi3.SerializationPipeDelimited && !sm.Explode:
|
||||
delim = "|"
|
||||
default:
|
||||
return "", fmt.Errorf("invalid serialization method: style=%q, explode=%v", sm.Style, sm.Explode)
|
||||
}
|
||||
|
||||
res := prefix
|
||||
|
||||
for i, val := range arrVal {
|
||||
vStr := MustString(val)
|
||||
res += vStr
|
||||
|
||||
if i != len(arrVal)-1 {
|
||||
res += delim
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func encodeObjectParam(sm *openapi3.SerializationMethod, paramName string, mapVal map[string]any) (string, error) {
|
||||
var prefix, propsDelim, valueDelim string
|
||||
|
||||
switch {
|
||||
case sm.Style == openapi3.SerializationSimple && !sm.Explode:
|
||||
propsDelim = ","
|
||||
valueDelim = ","
|
||||
case sm.Style == openapi3.SerializationSimple && sm.Explode:
|
||||
propsDelim = ","
|
||||
valueDelim = "="
|
||||
case sm.Style == openapi3.SerializationLabel && !sm.Explode:
|
||||
prefix = "."
|
||||
propsDelim = "."
|
||||
valueDelim = "."
|
||||
case sm.Style == openapi3.SerializationLabel && sm.Explode:
|
||||
prefix = "."
|
||||
propsDelim = "."
|
||||
valueDelim = "="
|
||||
case sm.Style == openapi3.SerializationMatrix && !sm.Explode:
|
||||
prefix = ";" + paramName + "="
|
||||
propsDelim = ","
|
||||
valueDelim = ","
|
||||
case sm.Style == openapi3.SerializationMatrix && sm.Explode:
|
||||
prefix = ";"
|
||||
propsDelim = ";"
|
||||
valueDelim = "="
|
||||
case sm.Style == openapi3.SerializationForm && !sm.Explode:
|
||||
prefix = paramName + "="
|
||||
propsDelim = ","
|
||||
valueDelim = ","
|
||||
case sm.Style == openapi3.SerializationForm && sm.Explode:
|
||||
propsDelim = "&"
|
||||
valueDelim = "="
|
||||
case sm.Style == openapi3.SerializationSpaceDelimited && !sm.Explode:
|
||||
propsDelim = " "
|
||||
valueDelim = " "
|
||||
case sm.Style == openapi3.SerializationPipeDelimited && !sm.Explode:
|
||||
propsDelim = "|"
|
||||
valueDelim = "|"
|
||||
case sm.Style == openapi3.SerializationDeepObject && sm.Explode:
|
||||
prefix = paramName + "["
|
||||
propsDelim = "&color["
|
||||
valueDelim = "]="
|
||||
default:
|
||||
return "", fmt.Errorf("invalid serialization method: style=%s, explode=%t", sm.Style, sm.Explode)
|
||||
}
|
||||
|
||||
res := prefix
|
||||
for k, val := range mapVal {
|
||||
vStr := MustString(val)
|
||||
res += k + valueDelim + vStr + propsDelim
|
||||
}
|
||||
|
||||
if len(mapVal) > 0 && len(res) > 0 {
|
||||
res = res[:len(res)-1]
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func MustString(value any) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
return val
|
||||
default:
|
||||
b, _ := json.Marshal(val)
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func TryFixValueType(paramName string, schemaRef *openapi3.SchemaRef, value any) (any, error) {
|
||||
if value == nil {
|
||||
return "", fmt.Errorf("value of '%s' is nil", paramName)
|
||||
}
|
||||
|
||||
switch schemaRef.Value.Type {
|
||||
case openapi3.TypeString:
|
||||
return tryString(value)
|
||||
case openapi3.TypeNumber:
|
||||
return tryFloat64(value)
|
||||
case openapi3.TypeInteger:
|
||||
return tryInt64(value)
|
||||
case openapi3.TypeBoolean:
|
||||
return tryBool(value)
|
||||
case openapi3.TypeArray:
|
||||
arrVal, ok := value.([]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("[TryFixValueType] value '%s' is not array", paramName)
|
||||
}
|
||||
|
||||
for i, v := range arrVal {
|
||||
_v, err := TryFixValueType(paramName, schemaRef.Value.Items, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
arrVal[i] = _v
|
||||
}
|
||||
|
||||
return arrVal, nil
|
||||
case openapi3.TypeObject:
|
||||
mapVal, ok := value.(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("[TryFixValueType] value '%s' is not object", paramName)
|
||||
}
|
||||
|
||||
for k, v := range mapVal {
|
||||
p, ok := schemaRef.Value.Properties[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
_v, err := TryFixValueType(k, p, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mapVal[k] = _v
|
||||
}
|
||||
|
||||
return mapVal, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("[TryFixValueType] unsupported schema type '%s'", schemaRef.Value.Type)
|
||||
}
|
||||
}
|
||||
|
||||
func tryString(value any) (string, error) {
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
return val, nil
|
||||
case int64:
|
||||
return strconv.FormatInt(val, 10), nil
|
||||
case float64:
|
||||
d := decimal.NewFromFloat(val)
|
||||
return d.String(), nil
|
||||
case json.Number:
|
||||
return val.String(), nil
|
||||
default:
|
||||
return "", fmt.Errorf("cannot convert type from '%T' to string", val)
|
||||
}
|
||||
}
|
||||
|
||||
func tryInt64(value any) (int64, error) {
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
vi64, _ := strconv.ParseInt(val, 10, 64)
|
||||
return vi64, nil
|
||||
case int64:
|
||||
return val, nil
|
||||
case float64:
|
||||
return int64(val), nil
|
||||
case json.Number:
|
||||
vi64, _ := strconv.ParseInt(val.String(), 10, 64)
|
||||
return vi64, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("cannot convert type from '%T' to int64", val)
|
||||
}
|
||||
}
|
||||
|
||||
func tryBool(value any) (bool, error) {
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
return strconv.ParseBool(val)
|
||||
case bool:
|
||||
return val, nil
|
||||
default:
|
||||
return false, fmt.Errorf("cannot convert type from '%T' to bool", val)
|
||||
}
|
||||
}
|
||||
|
||||
func tryFloat64(value any) (float64, error) {
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
return strconv.ParseFloat(val, 64)
|
||||
case float64:
|
||||
return val, nil
|
||||
case int64:
|
||||
return float64(val), nil
|
||||
case json.Number:
|
||||
return strconv.ParseFloat(val.String(), 64)
|
||||
default:
|
||||
return 0, fmt.Errorf("cannot convert type from '%T' to float64", val)
|
||||
}
|
||||
}
|
||||
1000
backend/domain/plugin/internal/openapi/convert_protocol.go
Normal file
1000
backend/domain/plugin/internal/openapi/convert_protocol.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user