feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
/*
* 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"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
)
func NewAPPConnectorReleaseRefDAO(db *gorm.DB, idGen idgen.IDGenerator) *APPConnectorReleaseRefDAO {
return &APPConnectorReleaseRefDAO{
idGen: idGen,
query: query.Use(db),
}
}
type APPConnectorReleaseRefDAO struct {
idGen idgen.IDGenerator
query *query.Query
}
type appConnectorReleaseRefPO model.AppConnectorReleaseRef
func (a appConnectorReleaseRefPO) ToDO() *entity.ConnectorPublishRecord {
return &entity.ConnectorPublishRecord{
ConnectorID: a.ConnectorID,
PublishStatus: entity.ConnectorPublishStatus(a.PublishStatus),
PublishConfig: a.PublishConfig,
}
}
func (c *APPConnectorReleaseRefDAO) MGetConnectorPublishRecords(ctx context.Context, recordID int64, connectorIDs []int64) ([]*entity.ConnectorPublishRecord, error) {
table := c.query.AppConnectorReleaseRef
res, err := table.WithContext(ctx).
Where(
table.RecordID.Eq(recordID),
table.ConnectorID.In(connectorIDs...),
).
Find()
if err != nil {
return nil, err
}
publishInfo := make([]*entity.ConnectorPublishRecord, 0, len(res))
for _, r := range res {
publishInfo = append(publishInfo, appConnectorReleaseRefPO(*r).ToDO())
}
return publishInfo, nil
}
func (c *APPConnectorReleaseRefDAO) GetAllConnectorPublishRecords(ctx context.Context, recordID int64) ([]*entity.ConnectorPublishRecord, error) {
table := c.query.AppConnectorReleaseRef
res, err := table.WithContext(ctx).
Where(table.RecordID.Eq(recordID)).
Find()
if err != nil {
return nil, err
}
records := make([]*entity.ConnectorPublishRecord, 0, len(res))
for _, r := range res {
records = append(records, appConnectorReleaseRefPO(*r).ToDO())
}
return records, nil
}
func (c *APPConnectorReleaseRefDAO) GetAllConnectorRecords(ctx context.Context, recordID int64) ([]*entity.ConnectorPublishRecord, error) {
table := c.query.AppConnectorReleaseRef
res, err := table.WithContext(ctx).
Where(table.RecordID.Eq(recordID)).
Find()
if err != nil {
return nil, err
}
publishInfo := make([]*entity.ConnectorPublishRecord, 0, len(res))
for _, r := range res {
publishInfo = append(publishInfo, appConnectorReleaseRefPO(*r).ToDO())
}
return publishInfo, nil
}
func (c *APPConnectorReleaseRefDAO) UpdatePublishStatus(ctx context.Context, recordID int64, status entity.ConnectorPublishStatus) error {
table := c.query.AppConnectorReleaseRef
_, err := table.WithContext(ctx).
Where(table.RecordID.Eq(recordID)).
Update(table.PublishStatus, int32(status))
if err != nil {
return err
}
return nil
}
func (c *APPConnectorReleaseRefDAO) BatchCreateWithTX(ctx context.Context, tx *query.QueryTx, recordID int64, publishRecords []*entity.ConnectorPublishRecord) error {
records := make([]*model.AppConnectorReleaseRef, 0, len(publishRecords))
for _, r := range publishRecords {
id, err := c.idGen.GenID(ctx)
if err != nil {
return err
}
records = append(records, &model.AppConnectorReleaseRef{
ID: id,
RecordID: recordID,
ConnectorID: r.ConnectorID,
PublishConfig: r.PublishConfig,
PublishStatus: int32(r.PublishStatus),
})
}
return tx.AppConnectorReleaseRef.WithContext(ctx).Create(records...)
}

View File

@@ -0,0 +1,144 @@
/*
* 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/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
)
func NewAPPDraftDAO(db *gorm.DB, idGen idgen.IDGenerator) *APPDraftDAO {
return &APPDraftDAO{
idGen: idGen,
query: query.Use(db),
}
}
type APPDraftDAO struct {
idGen idgen.IDGenerator
query *query.Query
}
type appDraftPO model.AppDraft
func (a appDraftPO) ToDO() *entity.APP {
return &entity.APP{
ID: a.ID,
SpaceID: a.SpaceID,
IconURI: &a.IconURI,
Name: &a.Name,
Desc: &a.Description,
OwnerID: a.OwnerID,
CreatedAtMS: a.CreatedAt,
UpdatedAtMS: a.UpdatedAt,
}
}
func (a *APPDraftDAO) Create(ctx context.Context, app *entity.APP) (appID int64, err error) {
appID, err = a.idGen.GenID(ctx)
if err != nil {
return 0, err
}
m := &model.AppDraft{
ID: appID,
SpaceID: app.SpaceID,
OwnerID: app.OwnerID,
IconURI: app.GetIconURI(),
Name: app.GetName(),
Description: app.GetDesc(),
}
err = a.query.AppDraft.WithContext(ctx).Create(m)
if err != nil {
return 0, err
}
return appID, nil
}
func (a *APPDraftDAO) Get(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error) {
table := a.query.AppDraft
res, err := table.WithContext(ctx).
Where(table.ID.Eq(appID)).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = appDraftPO(*res).ToDO()
return app, true, nil
}
func (a *APPDraftDAO) CheckExist(ctx context.Context, appID int64) (exist bool, err error) {
table := a.query.AppDraft
_, err = table.WithContext(ctx).
Where(table.ID.Eq(appID)).
Select(table.ID).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return false, nil
}
return false, err
}
return true, nil
}
func (a *APPDraftDAO) Delete(ctx context.Context, appID int64) (err error) {
table := a.query.AppDraft
_, err = table.WithContext(ctx).
Where(table.ID.Eq(appID)).
Delete()
if err != nil {
return err
}
return nil
}
func (a *APPDraftDAO) Update(ctx context.Context, app *entity.APP) (err error) {
table := a.query.AppDraft
m := &model.AppDraft{}
if app.Name != nil {
m.Name = *app.Name
}
if app.Desc != nil {
m.Description = *app.Desc
}
if app.IconURI != nil {
m.IconURI = *app.IconURI
}
_, err = table.WithContext(ctx).
Where(table.ID.Eq(app.ID)).
Updates(m)
if err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,256 @@
/*
* 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"
"math"
"gorm.io/gen/field"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
)
func NewAPPReleaseRecordDAO(db *gorm.DB, idGen idgen.IDGenerator) *APPReleaseRecordDAO {
return &APPReleaseRecordDAO{
idGen: idGen,
query: query.Use(db),
}
}
type APPReleaseRecordDAO struct {
idGen idgen.IDGenerator
query *query.Query
}
type releaseRecordPO model.AppReleaseRecord
func (a releaseRecordPO) ToDO() *entity.APP {
return &entity.APP{
ID: a.AppID,
SpaceID: a.SpaceID,
IconURI: &a.IconURI,
Name: &a.Name,
Desc: &a.Description,
OwnerID: a.OwnerID,
CreatedAtMS: a.CreatedAt,
UpdatedAtMS: a.UpdatedAt,
PublishedAtMS: &a.PublishAt,
ConnectorIDs: a.ConnectorIds,
PublishRecordID: &a.ID,
Version: &a.Version,
VersionDesc: &a.VersionDesc,
PublishStatus: ptr.Of(entity.PublishStatus(a.PublishStatus)),
PublishExtraInfo: a.ExtraInfo,
}
}
func (r *APPReleaseRecordDAO) getSelected(opt *APPSelectedOption) (selected []field.Expr) {
if opt == nil {
return selected
}
table := r.query.AppReleaseRecord
if opt.PublishRecordID {
selected = append(selected, table.ID)
}
if opt.APPID {
selected = append(selected, table.AppID)
}
if opt.PublishAtMS {
selected = append(selected, table.PublishAt)
}
if opt.PublishVersion {
selected = append(selected, table.Version)
}
if opt.PublishRecordExtraInfo {
selected = append(selected, table.ExtraInfo)
}
return selected
}
func (r *APPReleaseRecordDAO) GetLatestReleaseRecord(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(table.AppID.Eq(appID)).
Order(table.PublishAt.Desc()).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetOldestReleaseSuccessRecord(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(
table.AppID.Eq(appID),
table.PublishStatus.Eq(int32(entity.PublishStatusOfPublishDone)),
).
Order(table.PublishAt.Asc()).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetReleaseRecordWithID(ctx context.Context, recordID int64) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(table.ID.Eq(recordID)).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetReleaseRecordWithVersion(ctx context.Context, appID int64, version string) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(
table.AppID.Eq(appID),
table.Version.Eq(version),
).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetAPPAllPublishRecords(ctx context.Context, appID int64, opt *APPSelectedOption) (apps []*entity.APP, err error) {
table := r.query.AppReleaseRecord
cursor := int64(math.MaxInt64)
limit := 20
for {
res, err := table.WithContext(ctx).
Select(r.getSelected(opt)...).
Where(
table.AppID.Eq(appID),
table.ID.Lt(cursor),
).
Order(table.ID.Desc()).
Limit(limit).
Find()
if err != nil {
return nil, err
}
for _, v := range res {
apps = append(apps, releaseRecordPO(*v).ToDO())
}
if len(res) < limit {
break
}
cursor = res[len(res)-1].ID
}
return apps, nil
}
func (r *APPReleaseRecordDAO) UpdatePublishStatus(ctx context.Context, recordID int64, status entity.PublishStatus, extraInfo *entity.PublishRecordExtraInfo) (err error) {
table := r.query.AppReleaseRecord
updateMap := map[string]any{
table.PublishStatus.ColumnName().String(): int32(status),
}
if extraInfo != nil {
b, err := json.Marshal(extraInfo)
if err != nil {
return err
}
updateMap[table.ExtraInfo.ColumnName().String()] = b
}
_, err = table.WithContext(ctx).
Where(table.ID.Eq(recordID)).
Updates(updateMap)
if err != nil {
return err
}
return nil
}
func (r *APPReleaseRecordDAO) CreateWithTX(ctx context.Context, tx *query.QueryTx, app *entity.APP) (recordID int64, err error) {
id, err := r.idGen.GenID(ctx)
if err != nil {
return 0, err
}
m := &model.AppReleaseRecord{
ID: id,
AppID: app.ID,
SpaceID: app.SpaceID,
OwnerID: app.OwnerID,
IconURI: app.GetIconURI(),
Name: app.GetName(),
Description: app.GetDesc(),
ConnectorIds: app.ConnectorIDs,
Version: app.GetVersion(),
VersionDesc: app.GetVersionDesc(),
PublishStatus: int32(app.GetPublishStatus()),
PublishAt: app.GetPublishedAtMS(),
}
err = tx.AppReleaseRecord.WithContext(ctx).Create(m)
if err != nil {
return 0, err
}
return id, err
}

View 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 AppCache struct {
cacheCli *redisV9.Client
}
func NewAppCache(cacheCli *redisV9.Client) *AppCache {
return &AppCache{
cacheCli: cacheCli,
}
}
func (a *AppCache) Get(ctx context.Context, key string) (value string, exist bool, err error) {
cmd := a.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 (a *AppCache) Set(ctx context.Context, key string, value string, expiration *time.Duration) (err error) {
_expiration := ptr.FromOrDefault(expiration, 0)
cmd := a.cacheCli.Set(ctx, key, value, _expiration)
return cmd.Err()
}

View File

@@ -0,0 +1,25 @@
// 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/domain/app/entity"
const TableNameAppConnectorReleaseRef = "app_connector_release_ref"
// AppConnectorReleaseRef Connector Release Record Reference
type AppConnectorReleaseRef struct {
ID int64 `gorm:"column:id;primaryKey;comment:Primary Key" json:"id"` // Primary Key
RecordID int64 `gorm:"column:record_id;not null;comment:Publish Record ID" json:"record_id"` // Publish Record ID
ConnectorID int64 `gorm:"column:connector_id;comment:Publish Connector ID" json:"connector_id"` // Publish Connector ID
PublishConfig entity.PublishConfig `gorm:"column:publish_config;comment:Publish Configuration;serializer:json" json:"publish_config"` // Publish Configuration
PublishStatus int32 `gorm:"column:publish_status;not null;comment:Publish Status" json:"publish_status"` // Publish Status
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 AppConnectorReleaseRef's table name
func (*AppConnectorReleaseRef) TableName() string {
return TableNameAppConnectorReleaseRef
}

View File

@@ -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 (
"gorm.io/gorm"
)
const TableNameAppDraft = "app_draft"
// AppDraft Draft Application
type AppDraft struct {
ID int64 `gorm:"column:id;primaryKey;comment:APP ID" json:"id"` // APP ID
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
OwnerID int64 `gorm:"column:owner_id;not null;comment:Owner ID" json:"owner_id"` // Owner ID
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
Name string `gorm:"column:name;not null;comment:Application Name" json:"name"` // Application Name
Description string `gorm:"column:description;comment:Application Description" json:"description"` // Application Description
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time
}
// TableName AppDraft's table name
func (*AppDraft) TableName() string {
return TableNameAppDraft
}

View 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/domain/app/entity"
const TableNameAppReleaseRecord = "app_release_record"
// AppReleaseRecord Application Release Record
type AppReleaseRecord struct {
ID int64 `gorm:"column:id;primaryKey;comment:Publish Record ID" json:"id"` // Publish Record ID
AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
OwnerID int64 `gorm:"column:owner_id;not null;comment:Owner ID" json:"owner_id"` // Owner ID
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
Name string `gorm:"column:name;not null;comment:Application Name" json:"name"` // Application Name
Description string `gorm:"column:description;comment:Application Description" json:"description"` // Application Description
ConnectorIds []int64 `gorm:"column:connector_ids;comment:Publish Connector IDs;serializer:json" json:"connector_ids"` // Publish Connector IDs
ExtraInfo *entity.PublishRecordExtraInfo `gorm:"column:extra_info;comment:Publish Extra Info;serializer:json" json:"extra_info"` // Publish Extra Info
Version string `gorm:"column:version;not null;comment:Release Version" json:"version"` // Release Version
VersionDesc string `gorm:"column:version_desc;comment:Version Description" json:"version_desc"` // Version Description
PublishStatus int32 `gorm:"column:publish_status;not null;comment:Publish Status" json:"publish_status"` // Publish Status
PublishAt int64 `gorm:"column:publish_at;not null;comment:Publish Time in Milliseconds" json:"publish_at"` // Publish 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 AppReleaseRecord's table name
func (*AppReleaseRecord) TableName() string {
return TableNameAppReleaseRecord
}

View File

@@ -0,0 +1,26 @@
/*
* 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 APPSelectedOption struct {
APPID bool
PublishRecordID bool
PublishAtMS bool
PublishVersion bool
PublishStatus bool
PublishRecordExtraInfo bool
}

View File

@@ -0,0 +1,405 @@
// 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/app/internal/dal/model"
)
func newAppConnectorReleaseRef(db *gorm.DB, opts ...gen.DOOption) appConnectorReleaseRef {
_appConnectorReleaseRef := appConnectorReleaseRef{}
_appConnectorReleaseRef.appConnectorReleaseRefDo.UseDB(db, opts...)
_appConnectorReleaseRef.appConnectorReleaseRefDo.UseModel(&model.AppConnectorReleaseRef{})
tableName := _appConnectorReleaseRef.appConnectorReleaseRefDo.TableName()
_appConnectorReleaseRef.ALL = field.NewAsterisk(tableName)
_appConnectorReleaseRef.ID = field.NewInt64(tableName, "id")
_appConnectorReleaseRef.RecordID = field.NewInt64(tableName, "record_id")
_appConnectorReleaseRef.ConnectorID = field.NewInt64(tableName, "connector_id")
_appConnectorReleaseRef.PublishConfig = field.NewField(tableName, "publish_config")
_appConnectorReleaseRef.PublishStatus = field.NewInt32(tableName, "publish_status")
_appConnectorReleaseRef.CreatedAt = field.NewInt64(tableName, "created_at")
_appConnectorReleaseRef.UpdatedAt = field.NewInt64(tableName, "updated_at")
_appConnectorReleaseRef.fillFieldMap()
return _appConnectorReleaseRef
}
// appConnectorReleaseRef Connector Release Record Reference
type appConnectorReleaseRef struct {
appConnectorReleaseRefDo
ALL field.Asterisk
ID field.Int64 // Primary Key
RecordID field.Int64 // Publish Record ID
ConnectorID field.Int64 // Publish Connector ID
PublishConfig field.Field // Publish Configuration
PublishStatus field.Int32 // Publish Status
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
fieldMap map[string]field.Expr
}
func (a appConnectorReleaseRef) Table(newTableName string) *appConnectorReleaseRef {
a.appConnectorReleaseRefDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a appConnectorReleaseRef) As(alias string) *appConnectorReleaseRef {
a.appConnectorReleaseRefDo.DO = *(a.appConnectorReleaseRefDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *appConnectorReleaseRef) updateTableName(table string) *appConnectorReleaseRef {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt64(table, "id")
a.RecordID = field.NewInt64(table, "record_id")
a.ConnectorID = field.NewInt64(table, "connector_id")
a.PublishConfig = field.NewField(table, "publish_config")
a.PublishStatus = field.NewInt32(table, "publish_status")
a.CreatedAt = field.NewInt64(table, "created_at")
a.UpdatedAt = field.NewInt64(table, "updated_at")
a.fillFieldMap()
return a
}
func (a *appConnectorReleaseRef) 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 *appConnectorReleaseRef) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 7)
a.fieldMap["id"] = a.ID
a.fieldMap["record_id"] = a.RecordID
a.fieldMap["connector_id"] = a.ConnectorID
a.fieldMap["publish_config"] = a.PublishConfig
a.fieldMap["publish_status"] = a.PublishStatus
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
}
func (a appConnectorReleaseRef) clone(db *gorm.DB) appConnectorReleaseRef {
a.appConnectorReleaseRefDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a appConnectorReleaseRef) replaceDB(db *gorm.DB) appConnectorReleaseRef {
a.appConnectorReleaseRefDo.ReplaceDB(db)
return a
}
type appConnectorReleaseRefDo struct{ gen.DO }
type IAppConnectorReleaseRefDo interface {
gen.SubQuery
Debug() IAppConnectorReleaseRefDo
WithContext(ctx context.Context) IAppConnectorReleaseRefDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppConnectorReleaseRefDo
WriteDB() IAppConnectorReleaseRefDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppConnectorReleaseRefDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppConnectorReleaseRefDo
Not(conds ...gen.Condition) IAppConnectorReleaseRefDo
Or(conds ...gen.Condition) IAppConnectorReleaseRefDo
Select(conds ...field.Expr) IAppConnectorReleaseRefDo
Where(conds ...gen.Condition) IAppConnectorReleaseRefDo
Order(conds ...field.Expr) IAppConnectorReleaseRefDo
Distinct(cols ...field.Expr) IAppConnectorReleaseRefDo
Omit(cols ...field.Expr) IAppConnectorReleaseRefDo
Join(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo
Group(cols ...field.Expr) IAppConnectorReleaseRefDo
Having(conds ...gen.Condition) IAppConnectorReleaseRefDo
Limit(limit int) IAppConnectorReleaseRefDo
Offset(offset int) IAppConnectorReleaseRefDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppConnectorReleaseRefDo
Unscoped() IAppConnectorReleaseRefDo
Create(values ...*model.AppConnectorReleaseRef) error
CreateInBatches(values []*model.AppConnectorReleaseRef, batchSize int) error
Save(values ...*model.AppConnectorReleaseRef) error
First() (*model.AppConnectorReleaseRef, error)
Take() (*model.AppConnectorReleaseRef, error)
Last() (*model.AppConnectorReleaseRef, error)
Find() ([]*model.AppConnectorReleaseRef, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppConnectorReleaseRef, err error)
FindInBatches(result *[]*model.AppConnectorReleaseRef, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppConnectorReleaseRef) (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) IAppConnectorReleaseRefDo
Assign(attrs ...field.AssignExpr) IAppConnectorReleaseRefDo
Joins(fields ...field.RelationField) IAppConnectorReleaseRefDo
Preload(fields ...field.RelationField) IAppConnectorReleaseRefDo
FirstOrInit() (*model.AppConnectorReleaseRef, error)
FirstOrCreate() (*model.AppConnectorReleaseRef, error)
FindByPage(offset int, limit int) (result []*model.AppConnectorReleaseRef, 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) IAppConnectorReleaseRefDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a appConnectorReleaseRefDo) Debug() IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Debug())
}
func (a appConnectorReleaseRefDo) WithContext(ctx context.Context) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appConnectorReleaseRefDo) ReadDB() IAppConnectorReleaseRefDo {
return a.Clauses(dbresolver.Read)
}
func (a appConnectorReleaseRefDo) WriteDB() IAppConnectorReleaseRefDo {
return a.Clauses(dbresolver.Write)
}
func (a appConnectorReleaseRefDo) Session(config *gorm.Session) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Session(config))
}
func (a appConnectorReleaseRefDo) Clauses(conds ...clause.Expression) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appConnectorReleaseRefDo) Returning(value interface{}, columns ...string) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appConnectorReleaseRefDo) Not(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appConnectorReleaseRefDo) Or(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appConnectorReleaseRefDo) Select(conds ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appConnectorReleaseRefDo) Where(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appConnectorReleaseRefDo) Order(conds ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appConnectorReleaseRefDo) Distinct(cols ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appConnectorReleaseRefDo) Omit(cols ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appConnectorReleaseRefDo) Join(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appConnectorReleaseRefDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appConnectorReleaseRefDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appConnectorReleaseRefDo) Group(cols ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appConnectorReleaseRefDo) Having(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appConnectorReleaseRefDo) Limit(limit int) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appConnectorReleaseRefDo) Offset(offset int) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appConnectorReleaseRefDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appConnectorReleaseRefDo) Unscoped() IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Unscoped())
}
func (a appConnectorReleaseRefDo) Create(values ...*model.AppConnectorReleaseRef) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a appConnectorReleaseRefDo) CreateInBatches(values []*model.AppConnectorReleaseRef, 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 appConnectorReleaseRefDo) Save(values ...*model.AppConnectorReleaseRef) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a appConnectorReleaseRefDo) First() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) Take() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) Last() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) Find() ([]*model.AppConnectorReleaseRef, error) {
result, err := a.DO.Find()
return result.([]*model.AppConnectorReleaseRef), err
}
func (a appConnectorReleaseRefDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppConnectorReleaseRef, err error) {
buf := make([]*model.AppConnectorReleaseRef, 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 appConnectorReleaseRefDo) FindInBatches(result *[]*model.AppConnectorReleaseRef, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appConnectorReleaseRefDo) Attrs(attrs ...field.AssignExpr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appConnectorReleaseRefDo) Assign(attrs ...field.AssignExpr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appConnectorReleaseRefDo) Joins(fields ...field.RelationField) IAppConnectorReleaseRefDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appConnectorReleaseRefDo) Preload(fields ...field.RelationField) IAppConnectorReleaseRefDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a appConnectorReleaseRefDo) FirstOrInit() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) FirstOrCreate() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) FindByPage(offset int, limit int) (result []*model.AppConnectorReleaseRef, 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 appConnectorReleaseRefDo) 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 appConnectorReleaseRefDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a appConnectorReleaseRefDo) Delete(models ...*model.AppConnectorReleaseRef) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *appConnectorReleaseRefDo) withDO(do gen.Dao) *appConnectorReleaseRefDo {
a.DO = *do.(*gen.DO)
return a
}

View 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/app/internal/dal/model"
)
func newAppDraft(db *gorm.DB, opts ...gen.DOOption) appDraft {
_appDraft := appDraft{}
_appDraft.appDraftDo.UseDB(db, opts...)
_appDraft.appDraftDo.UseModel(&model.AppDraft{})
tableName := _appDraft.appDraftDo.TableName()
_appDraft.ALL = field.NewAsterisk(tableName)
_appDraft.ID = field.NewInt64(tableName, "id")
_appDraft.SpaceID = field.NewInt64(tableName, "space_id")
_appDraft.OwnerID = field.NewInt64(tableName, "owner_id")
_appDraft.IconURI = field.NewString(tableName, "icon_uri")
_appDraft.Name = field.NewString(tableName, "name")
_appDraft.Description = field.NewString(tableName, "description")
_appDraft.CreatedAt = field.NewInt64(tableName, "created_at")
_appDraft.UpdatedAt = field.NewInt64(tableName, "updated_at")
_appDraft.DeletedAt = field.NewField(tableName, "deleted_at")
_appDraft.fillFieldMap()
return _appDraft
}
// appDraft Draft Application
type appDraft struct {
appDraftDo
ALL field.Asterisk
ID field.Int64 // APP ID
SpaceID field.Int64 // Space ID
OwnerID field.Int64 // Owner ID
IconURI field.String // Icon URI
Name field.String // Application Name
Description field.String // Application Description
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
DeletedAt field.Field // Delete Time
fieldMap map[string]field.Expr
}
func (a appDraft) Table(newTableName string) *appDraft {
a.appDraftDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a appDraft) As(alias string) *appDraft {
a.appDraftDo.DO = *(a.appDraftDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *appDraft) updateTableName(table string) *appDraft {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt64(table, "id")
a.SpaceID = field.NewInt64(table, "space_id")
a.OwnerID = field.NewInt64(table, "owner_id")
a.IconURI = field.NewString(table, "icon_uri")
a.Name = field.NewString(table, "name")
a.Description = field.NewString(table, "description")
a.CreatedAt = field.NewInt64(table, "created_at")
a.UpdatedAt = field.NewInt64(table, "updated_at")
a.DeletedAt = field.NewField(table, "deleted_at")
a.fillFieldMap()
return a
}
func (a *appDraft) 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 *appDraft) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 9)
a.fieldMap["id"] = a.ID
a.fieldMap["space_id"] = a.SpaceID
a.fieldMap["owner_id"] = a.OwnerID
a.fieldMap["icon_uri"] = a.IconURI
a.fieldMap["name"] = a.Name
a.fieldMap["description"] = a.Description
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
a.fieldMap["deleted_at"] = a.DeletedAt
}
func (a appDraft) clone(db *gorm.DB) appDraft {
a.appDraftDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a appDraft) replaceDB(db *gorm.DB) appDraft {
a.appDraftDo.ReplaceDB(db)
return a
}
type appDraftDo struct{ gen.DO }
type IAppDraftDo interface {
gen.SubQuery
Debug() IAppDraftDo
WithContext(ctx context.Context) IAppDraftDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppDraftDo
WriteDB() IAppDraftDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppDraftDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppDraftDo
Not(conds ...gen.Condition) IAppDraftDo
Or(conds ...gen.Condition) IAppDraftDo
Select(conds ...field.Expr) IAppDraftDo
Where(conds ...gen.Condition) IAppDraftDo
Order(conds ...field.Expr) IAppDraftDo
Distinct(cols ...field.Expr) IAppDraftDo
Omit(cols ...field.Expr) IAppDraftDo
Join(table schema.Tabler, on ...field.Expr) IAppDraftDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo
Group(cols ...field.Expr) IAppDraftDo
Having(conds ...gen.Condition) IAppDraftDo
Limit(limit int) IAppDraftDo
Offset(offset int) IAppDraftDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppDraftDo
Unscoped() IAppDraftDo
Create(values ...*model.AppDraft) error
CreateInBatches(values []*model.AppDraft, batchSize int) error
Save(values ...*model.AppDraft) error
First() (*model.AppDraft, error)
Take() (*model.AppDraft, error)
Last() (*model.AppDraft, error)
Find() ([]*model.AppDraft, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppDraft, err error)
FindInBatches(result *[]*model.AppDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppDraft) (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) IAppDraftDo
Assign(attrs ...field.AssignExpr) IAppDraftDo
Joins(fields ...field.RelationField) IAppDraftDo
Preload(fields ...field.RelationField) IAppDraftDo
FirstOrInit() (*model.AppDraft, error)
FirstOrCreate() (*model.AppDraft, error)
FindByPage(offset int, limit int) (result []*model.AppDraft, 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) IAppDraftDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a appDraftDo) Debug() IAppDraftDo {
return a.withDO(a.DO.Debug())
}
func (a appDraftDo) WithContext(ctx context.Context) IAppDraftDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appDraftDo) ReadDB() IAppDraftDo {
return a.Clauses(dbresolver.Read)
}
func (a appDraftDo) WriteDB() IAppDraftDo {
return a.Clauses(dbresolver.Write)
}
func (a appDraftDo) Session(config *gorm.Session) IAppDraftDo {
return a.withDO(a.DO.Session(config))
}
func (a appDraftDo) Clauses(conds ...clause.Expression) IAppDraftDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appDraftDo) Returning(value interface{}, columns ...string) IAppDraftDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appDraftDo) Not(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appDraftDo) Or(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appDraftDo) Select(conds ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appDraftDo) Where(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appDraftDo) Order(conds ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appDraftDo) Distinct(cols ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appDraftDo) Omit(cols ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appDraftDo) Join(table schema.Tabler, on ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appDraftDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appDraftDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appDraftDo) Group(cols ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appDraftDo) Having(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appDraftDo) Limit(limit int) IAppDraftDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appDraftDo) Offset(offset int) IAppDraftDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appDraftDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppDraftDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appDraftDo) Unscoped() IAppDraftDo {
return a.withDO(a.DO.Unscoped())
}
func (a appDraftDo) Create(values ...*model.AppDraft) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a appDraftDo) CreateInBatches(values []*model.AppDraft, 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 appDraftDo) Save(values ...*model.AppDraft) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a appDraftDo) First() (*model.AppDraft, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) Take() (*model.AppDraft, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) Last() (*model.AppDraft, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) Find() ([]*model.AppDraft, error) {
result, err := a.DO.Find()
return result.([]*model.AppDraft), err
}
func (a appDraftDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppDraft, err error) {
buf := make([]*model.AppDraft, 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 appDraftDo) FindInBatches(result *[]*model.AppDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appDraftDo) Attrs(attrs ...field.AssignExpr) IAppDraftDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appDraftDo) Assign(attrs ...field.AssignExpr) IAppDraftDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appDraftDo) Joins(fields ...field.RelationField) IAppDraftDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appDraftDo) Preload(fields ...field.RelationField) IAppDraftDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a appDraftDo) FirstOrInit() (*model.AppDraft, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) FirstOrCreate() (*model.AppDraft, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) FindByPage(offset int, limit int) (result []*model.AppDraft, 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 appDraftDo) 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 appDraftDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a appDraftDo) Delete(models ...*model.AppDraft) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *appDraftDo) withDO(do gen.Dao) *appDraftDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@@ -0,0 +1,437 @@
// 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/app/internal/dal/model"
)
func newAppReleaseRecord(db *gorm.DB, opts ...gen.DOOption) appReleaseRecord {
_appReleaseRecord := appReleaseRecord{}
_appReleaseRecord.appReleaseRecordDo.UseDB(db, opts...)
_appReleaseRecord.appReleaseRecordDo.UseModel(&model.AppReleaseRecord{})
tableName := _appReleaseRecord.appReleaseRecordDo.TableName()
_appReleaseRecord.ALL = field.NewAsterisk(tableName)
_appReleaseRecord.ID = field.NewInt64(tableName, "id")
_appReleaseRecord.AppID = field.NewInt64(tableName, "app_id")
_appReleaseRecord.SpaceID = field.NewInt64(tableName, "space_id")
_appReleaseRecord.OwnerID = field.NewInt64(tableName, "owner_id")
_appReleaseRecord.IconURI = field.NewString(tableName, "icon_uri")
_appReleaseRecord.Name = field.NewString(tableName, "name")
_appReleaseRecord.Description = field.NewString(tableName, "description")
_appReleaseRecord.ConnectorIds = field.NewField(tableName, "connector_ids")
_appReleaseRecord.ExtraInfo = field.NewField(tableName, "extra_info")
_appReleaseRecord.Version = field.NewString(tableName, "version")
_appReleaseRecord.VersionDesc = field.NewString(tableName, "version_desc")
_appReleaseRecord.PublishStatus = field.NewInt32(tableName, "publish_status")
_appReleaseRecord.PublishAt = field.NewInt64(tableName, "publish_at")
_appReleaseRecord.CreatedAt = field.NewInt64(tableName, "created_at")
_appReleaseRecord.UpdatedAt = field.NewInt64(tableName, "updated_at")
_appReleaseRecord.fillFieldMap()
return _appReleaseRecord
}
// appReleaseRecord Application Release Record
type appReleaseRecord struct {
appReleaseRecordDo
ALL field.Asterisk
ID field.Int64 // Publish Record ID
AppID field.Int64 // Application ID
SpaceID field.Int64 // Space ID
OwnerID field.Int64 // Owner ID
IconURI field.String // Icon URI
Name field.String // Application Name
Description field.String // Application Description
ConnectorIds field.Field // Publish Connector IDs
ExtraInfo field.Field // Publish Extra Info
Version field.String // Release Version
VersionDesc field.String // Version Description
PublishStatus field.Int32 // Publish Status
PublishAt field.Int64 // Publish Time in Milliseconds
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
fieldMap map[string]field.Expr
}
func (a appReleaseRecord) Table(newTableName string) *appReleaseRecord {
a.appReleaseRecordDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a appReleaseRecord) As(alias string) *appReleaseRecord {
a.appReleaseRecordDo.DO = *(a.appReleaseRecordDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *appReleaseRecord) updateTableName(table string) *appReleaseRecord {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt64(table, "id")
a.AppID = field.NewInt64(table, "app_id")
a.SpaceID = field.NewInt64(table, "space_id")
a.OwnerID = field.NewInt64(table, "owner_id")
a.IconURI = field.NewString(table, "icon_uri")
a.Name = field.NewString(table, "name")
a.Description = field.NewString(table, "description")
a.ConnectorIds = field.NewField(table, "connector_ids")
a.ExtraInfo = field.NewField(table, "extra_info")
a.Version = field.NewString(table, "version")
a.VersionDesc = field.NewString(table, "version_desc")
a.PublishStatus = field.NewInt32(table, "publish_status")
a.PublishAt = field.NewInt64(table, "publish_at")
a.CreatedAt = field.NewInt64(table, "created_at")
a.UpdatedAt = field.NewInt64(table, "updated_at")
a.fillFieldMap()
return a
}
func (a *appReleaseRecord) 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 *appReleaseRecord) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 15)
a.fieldMap["id"] = a.ID
a.fieldMap["app_id"] = a.AppID
a.fieldMap["space_id"] = a.SpaceID
a.fieldMap["owner_id"] = a.OwnerID
a.fieldMap["icon_uri"] = a.IconURI
a.fieldMap["name"] = a.Name
a.fieldMap["description"] = a.Description
a.fieldMap["connector_ids"] = a.ConnectorIds
a.fieldMap["extra_info"] = a.ExtraInfo
a.fieldMap["version"] = a.Version
a.fieldMap["version_desc"] = a.VersionDesc
a.fieldMap["publish_status"] = a.PublishStatus
a.fieldMap["publish_at"] = a.PublishAt
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
}
func (a appReleaseRecord) clone(db *gorm.DB) appReleaseRecord {
a.appReleaseRecordDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a appReleaseRecord) replaceDB(db *gorm.DB) appReleaseRecord {
a.appReleaseRecordDo.ReplaceDB(db)
return a
}
type appReleaseRecordDo struct{ gen.DO }
type IAppReleaseRecordDo interface {
gen.SubQuery
Debug() IAppReleaseRecordDo
WithContext(ctx context.Context) IAppReleaseRecordDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppReleaseRecordDo
WriteDB() IAppReleaseRecordDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppReleaseRecordDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppReleaseRecordDo
Not(conds ...gen.Condition) IAppReleaseRecordDo
Or(conds ...gen.Condition) IAppReleaseRecordDo
Select(conds ...field.Expr) IAppReleaseRecordDo
Where(conds ...gen.Condition) IAppReleaseRecordDo
Order(conds ...field.Expr) IAppReleaseRecordDo
Distinct(cols ...field.Expr) IAppReleaseRecordDo
Omit(cols ...field.Expr) IAppReleaseRecordDo
Join(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo
Group(cols ...field.Expr) IAppReleaseRecordDo
Having(conds ...gen.Condition) IAppReleaseRecordDo
Limit(limit int) IAppReleaseRecordDo
Offset(offset int) IAppReleaseRecordDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppReleaseRecordDo
Unscoped() IAppReleaseRecordDo
Create(values ...*model.AppReleaseRecord) error
CreateInBatches(values []*model.AppReleaseRecord, batchSize int) error
Save(values ...*model.AppReleaseRecord) error
First() (*model.AppReleaseRecord, error)
Take() (*model.AppReleaseRecord, error)
Last() (*model.AppReleaseRecord, error)
Find() ([]*model.AppReleaseRecord, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppReleaseRecord, err error)
FindInBatches(result *[]*model.AppReleaseRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppReleaseRecord) (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) IAppReleaseRecordDo
Assign(attrs ...field.AssignExpr) IAppReleaseRecordDo
Joins(fields ...field.RelationField) IAppReleaseRecordDo
Preload(fields ...field.RelationField) IAppReleaseRecordDo
FirstOrInit() (*model.AppReleaseRecord, error)
FirstOrCreate() (*model.AppReleaseRecord, error)
FindByPage(offset int, limit int) (result []*model.AppReleaseRecord, 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) IAppReleaseRecordDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a appReleaseRecordDo) Debug() IAppReleaseRecordDo {
return a.withDO(a.DO.Debug())
}
func (a appReleaseRecordDo) WithContext(ctx context.Context) IAppReleaseRecordDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appReleaseRecordDo) ReadDB() IAppReleaseRecordDo {
return a.Clauses(dbresolver.Read)
}
func (a appReleaseRecordDo) WriteDB() IAppReleaseRecordDo {
return a.Clauses(dbresolver.Write)
}
func (a appReleaseRecordDo) Session(config *gorm.Session) IAppReleaseRecordDo {
return a.withDO(a.DO.Session(config))
}
func (a appReleaseRecordDo) Clauses(conds ...clause.Expression) IAppReleaseRecordDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appReleaseRecordDo) Returning(value interface{}, columns ...string) IAppReleaseRecordDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appReleaseRecordDo) Not(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appReleaseRecordDo) Or(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appReleaseRecordDo) Select(conds ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appReleaseRecordDo) Where(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appReleaseRecordDo) Order(conds ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appReleaseRecordDo) Distinct(cols ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appReleaseRecordDo) Omit(cols ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appReleaseRecordDo) Join(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appReleaseRecordDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appReleaseRecordDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appReleaseRecordDo) Group(cols ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appReleaseRecordDo) Having(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appReleaseRecordDo) Limit(limit int) IAppReleaseRecordDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appReleaseRecordDo) Offset(offset int) IAppReleaseRecordDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appReleaseRecordDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppReleaseRecordDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appReleaseRecordDo) Unscoped() IAppReleaseRecordDo {
return a.withDO(a.DO.Unscoped())
}
func (a appReleaseRecordDo) Create(values ...*model.AppReleaseRecord) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a appReleaseRecordDo) CreateInBatches(values []*model.AppReleaseRecord, 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 appReleaseRecordDo) Save(values ...*model.AppReleaseRecord) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a appReleaseRecordDo) First() (*model.AppReleaseRecord, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) Take() (*model.AppReleaseRecord, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) Last() (*model.AppReleaseRecord, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) Find() ([]*model.AppReleaseRecord, error) {
result, err := a.DO.Find()
return result.([]*model.AppReleaseRecord), err
}
func (a appReleaseRecordDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppReleaseRecord, err error) {
buf := make([]*model.AppReleaseRecord, 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 appReleaseRecordDo) FindInBatches(result *[]*model.AppReleaseRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appReleaseRecordDo) Attrs(attrs ...field.AssignExpr) IAppReleaseRecordDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appReleaseRecordDo) Assign(attrs ...field.AssignExpr) IAppReleaseRecordDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appReleaseRecordDo) Joins(fields ...field.RelationField) IAppReleaseRecordDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appReleaseRecordDo) Preload(fields ...field.RelationField) IAppReleaseRecordDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a appReleaseRecordDo) FirstOrInit() (*model.AppReleaseRecord, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) FirstOrCreate() (*model.AppReleaseRecord, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) FindByPage(offset int, limit int) (result []*model.AppReleaseRecord, 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 appReleaseRecordDo) 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 appReleaseRecordDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a appReleaseRecordDo) Delete(models ...*model.AppReleaseRecord) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *appReleaseRecordDo) withDO(do gen.Dao) *appReleaseRecordDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@@ -0,0 +1,119 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
AppConnectorReleaseRef *appConnectorReleaseRef
AppDraft *appDraft
AppReleaseRecord *appReleaseRecord
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
AppConnectorReleaseRef = &Q.AppConnectorReleaseRef
AppDraft = &Q.AppDraft
AppReleaseRecord = &Q.AppReleaseRecord
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
AppConnectorReleaseRef: newAppConnectorReleaseRef(db, opts...),
AppDraft: newAppDraft(db, opts...),
AppReleaseRecord: newAppReleaseRecord(db, opts...),
}
}
type Query struct {
db *gorm.DB
AppConnectorReleaseRef appConnectorReleaseRef
AppDraft appDraft
AppReleaseRecord appReleaseRecord
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
AppConnectorReleaseRef: q.AppConnectorReleaseRef.clone(db),
AppDraft: q.AppDraft.clone(db),
AppReleaseRecord: q.AppReleaseRecord.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,
AppConnectorReleaseRef: q.AppConnectorReleaseRef.replaceDB(db),
AppDraft: q.AppDraft.replaceDB(db),
AppReleaseRecord: q.AppReleaseRecord.replaceDB(db),
}
}
type queryCtx struct {
AppConnectorReleaseRef IAppConnectorReleaseRefDo
AppDraft IAppDraftDo
AppReleaseRecord IAppReleaseRecordDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
AppConnectorReleaseRef: q.AppConnectorReleaseRef.WithContext(ctx),
AppDraft: q.AppDraft.WithContext(ctx),
AppReleaseRecord: q.AppReleaseRecord.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
}