Documentation
¶
Overview ¶
通用目录布局重排引擎:声明式 glob 规则驱动的路径重排(复制语义)。 纯机制层,不含任何业务语义——业务布局映射(如"flow/ → 5_flow/")由宿主 按自身配置推导成规则传入。服务于宿主旧布局与引擎标准布局的双向适配。
render.go 行数据 → 方言正确 SQL 文本渲染 + SQL 文本归一:库模式宿主(如 tl-env) 导出写盘薄壳复用。复用 cydb dialect 的 GetReplaceSql(与导入/回滚链路同源转义), 替代宿主手写方言补丁(PG 保留字表、MySQL 转义转换、bool→int 等均由方言层权威处理)。
Package dqex 提供 dqex 的库化公开门面(docs/library-api-design.md 第 3 章)。
外部 Go 程序只 import 本包即可调用核心能力(迁移/导出/导入/对比/查询/元数据/快照), 无需启动 dqex 进程或经 HTTP 调用。门面为薄包装,业务实现复用 internal/service, 类型经别名公开:internal/service 的 Options/Result 结构体字段自 v1 起冻结为公开契约。
基本用法(安装工具场景,进程内完成一次迁移):
client, err := dqex.New(
dqex.WithLang("zh"),
dqex.WithInlineConns(
dqex.ConnInfo{ID: "src", Name: "源库", Conn: dqex.NewConn("mysql", "10.0.0.1", 3306, "root", "***", "app")},
dqex.ConnInfo{ID: "tgt", Name: "目标库", Conn: dqex.NewConn("mysql", "10.0.0.2", 3306, "root", "***", "app_new")},
),
)
if err != nil { panic(err) }
defer client.Close()
conns := client.ListConnections()
err = client.RunMigrate(context.Background(), dqex.MigrateOptions{
SourceConn: conns[0].ID, TargetConn: conns[1].ID,
}, func(p dqex.ProgressInfo) { fmt.Printf("%s\n", p.Message) })
并发契约:Client 可被多个 goroutine 并发使用;Close() 幂等,关闭后调用能力方法返回 ErrClientClosed。同进程多 Client 实例可用但共享元数据缓存与连接池(v0 语义)。
Index ¶
- Constants
- func AsSvcErr(err error, target **SvcError) bool
- func IsArtifactLogicalPath(p string) bool
- func RelayoutDir(srcDir, dstDir string, rules []LayoutRule, dropUnmatched bool) error
- func RelayoutDirWithMap(srcDir, dstDir string, rules []LayoutRule, dropUnmatched bool, ...) error
- func RenderRowsSQL(cli *cydb.DBCli, table string, rows []map[string]any) (string, error)
- func StripSQLDBPrefix(isMySQL bool, sql string, knownDBs ...string) string
- func WithLangCtx(ctx context.Context, lang string) context.Context
- type AIConfig
- type ArtifactRef
- type Client
- func (c *Client) AddConnection(ctx context.Context, rec ConnRecord) (ConnRecord, error)
- func (c *Client) CancelTask(taskID string) error
- func (c *Client) Close() error
- func (c *Client) CompareSnapshot(ctx context.Context, snap *Snapshot, target *DBConnInfo, ...) (*CompareResult, error)
- func (c *Client) CreateSnapshot(ctx context.Context, connKey string, dbs []string, opts SnapshotParams, ...) (*Snapshot, error)
- func (c *Client) Databases(ctx context.Context, connKey string, force bool) ([]string, error)
- func (c *Client) DeleteConnection(key string) error
- func (c *Client) DeleteTableRows(ctx context.Context, connKey, db, table string, pkColumns []string, ...) (int64, error)
- func (c *Client) GenerateSQL(ctx context.Context, connKey, db string, p GenSQLParams) (string, error)
- func (c *Client) GetCellValue(ctx context.Context, connKey, db, table, column string, pkColumns []string, ...) (any, error)
- func (c *Client) InsertTableRow(ctx context.Context, connKey, db string, p InsertRowParams) (int64, error)
- func (c *Client) ListConnections() []ConnInfo
- func (c *Client) LoadSnapshot(path string) (*Snapshot, error)
- func (c *Client) ObjectDDL(ctx context.Context, connKey, db, objType, name string) (*ObjectDDLResult, error)
- func (c *Client) Objects(ctx context.Context, connKey, db, schema string, force bool) (*DBSchema, error)
- func (c *Client) PingConnection(ctx context.Context, connKey string) (int64, error)
- func (c *Client) QueryTablePage(ctx context.Context, connKey, db, table string, p PageParams) (*TablePageResult, error)
- func (c *Client) RunCompare(ctx context.Context, opts CompareOptions, cb ProgressFunc) (*CompareResult, error)
- func (c *Client) RunDictionary(ctx context.Context, opts DictionaryOptions, cb ProgressFunc) (*ArtifactRef, error)
- func (c *Client) RunExport(ctx context.Context, opts ExportOptions, cb ProgressFunc) (*ArtifactRef, error)
- func (c *Client) RunImport(ctx context.Context, opts ImportOptions, cb ProgressFunc) (*ImportResult, error)
- func (c *Client) RunMigrate(ctx context.Context, opts MigrateOptions, cb ProgressFunc) error
- func (c *Client) RunSQLScript(ctx context.Context, connKey, db, sql string, p ScriptParams) ([]*SQLQueryResult, error)
- func (c *Client) Schemas(ctx context.Context, connKey, db string, force bool) ([]SchemaSummary, error)
- func (c *Client) Service() *service.Service
- func (c *Client) StoreMode() StoreMode
- func (c *Client) TableColumns(ctx context.Context, connKey, db, table string) ([]TableColumnInfo, error)
- func (c *Client) TestConnection(ctx context.Context, conn DBConnInfo) error
- func (c *Client) UpdateTableCell(ctx context.Context, connKey, db string, p UpdateCellParams) (int64, error)
- type ColumnFilter
- type CompareDBPair
- type CompareOptions
- type CompareResult
- type ConnHooks
- type ConnInfo
- type ConnProvider
- type ConnRecord
- type ConnSource
- type Contributor
- type ContributorImportRequest
- type ContributorRequest
- type ContributorResult
- type DBConnInfo
- type DBSchema
- type DBTables
- type DataEntry
- type DataPackage
- type DataPrepareRequest
- type DataPreparer
- type DeleteRowParams
- type DictionaryOptions
- type ExportDetail
- type ExportFormat
- type ExportOptions
- type GenSQLParams
- type ImportOptions
- type ImportResult
- type InsertRowParams
- type LayoutRule
- type MigrateOptions
- type ObjectDDLResult
- type Option
- func WithAIConfig(ai AIConfig) Option
- func WithArtifactStore(store *cystore.Store, bucket string) Option
- func WithCacheClient(rc *cydist.RedisClient) Option
- func WithCacheRedis(addr, pwd string) Option
- func WithConfigFile(path string) Option
- func WithConnHooks(hooks ConnHooks) Option
- func WithConnProvider(p ConnProvider) Option
- func WithContributors(ctbs ...Contributor) Option
- func WithDataDir(dir string) Option
- func WithDataPreparers(preparers map[string]DataPreparer) Option
- func WithInlineConns(conns ...ConnInfo) Option
- func WithLang(lang string) Option
- func WithMinio(endpoint, accessKey, secretKey, bucket string) Option
- func WithQueryHooks(hooks QueryHooks) Option
- func WithS3(region, bucket string) Option
- func WithStoreConn(conn def.DBConnection) Option
- func WithStoreDB(cli *cydb.DBCli) Option
- func WithTaskHooks(h TaskHooks) Option
- type PageParams
- type ProgressFunc
- type ProgressInfo
- type QueryHooks
- type SQLQueryResult
- type SchemaSummary
- type ScriptParams
- type Snapshot
- type SnapshotCompareOptions
- type SnapshotInfo
- type SnapshotParams
- type SortSpec
- type StoreMode
- type SvcError
- type TableAlias
- type TableColumnInfo
- type TableCondition
- type TablePageResult
- type TaskHooks
- type TaskStartInfo
- type UpdateCellParams
Constants ¶
const ( // ErrParamsInvalid 参数无效(cygin 系统码) ErrParamsInvalid = cygin.ErrParamsInvalid // ErrInternalServer 内部错误(cygin 系统码) ErrInternalServer = cygin.ErrInternalServer // ErrConnNotFound 连接配置不存在(key 不在任何解析来源中) ErrConnNotFound = service.ErrConnNotFound // ErrConnNotSpecified 未指定数据库连接 ErrConnNotSpecified = service.ErrConnNotSpecified // ErrUnsupportedType 不支持的数据库类型 ErrUnsupportedType = service.ErrUnsupportedType // ErrConnFailed 数据库连接/操作失败 ErrConnFailed = service.ErrConnFailed // ErrTaskNotFound 任务/记录不存在 ErrTaskNotFound = service.ErrTaskNotFound // ErrTaskInvalid 任务配置无效 ErrTaskInvalid = service.ErrTaskInvalid // ErrExecFailed 执行操作失败(导出/导入/迁移/获取元数据等) ErrExecFailed = service.ErrExecFailed // ErrFileType 不支持的文件类型 ErrFileType = service.ErrFileType // ErrNoArtifact 任务没有可下载产物 ErrNoArtifact = service.ErrNoArtifact // ErrCryptoFailed 配置文件加解密失败 ErrCryptoFailed = service.ErrCryptoFailed // ErrExpOutDir 未显式指定产物输出目录(StoreNone 库模式且无 DataDir 时,RunExport/RunDictionary 必须显式指定 OutputDir) ErrExpOutDir = service.ErrExpOutDir // ErrClientClosed 客户端已关闭(Close 后调用能力方法) ErrClientClosed = service.ErrClientClosed // ErrNotImplemented 触发式能力尚未实现(WithStoreConn/WithCacheRedis/WithArtifactStore 等,随 4.4 触发落地) ErrNotImplemented = service.ErrNotImplemented ErrStoreUnavailable = service.ErrStoreUnavailable )
错误码常量(与 internal/service 一一对应)
const ( ConnSourceInline = service.ConnSourceInline ConnSourceMemory = service.ConnSourceMemory ConnSourceProvider = service.ConnSourceProvider ConnSourceStore = service.ConnSourceStore )
连接解析来源常量
const ( // StoreNone 纯内存:不建存储、不写历史/任务/连接库(默认,库模式) StoreNone = service.StoreNone // StoreSQLite 数据目录 + SQLite(WithDataDir 便捷糖) StoreSQLite = service.StoreSQLite // StoreExternal 外部注入存储(触发式,v0.x 仅定义) StoreExternal = service.StoreExternal )
持久化模式常量
const ( ResetNone = service.ResetNone ResetTruncate = service.ResetTruncate ResetDrop = service.ResetDrop // FormatSQL / FormatJSON 导出产物格式(ExportOptions.Format) FormatSQL = service.FormatSQL FormatJSON = service.FormatJSON // DetailKindTable/View/Function/Procedure 导出明细类型(ExportDetail.Kind) DetailKindTable = engine.DetailKindTable DetailKindView = engine.DetailKindView DetailKindFunction = engine.DetailKindFunction DetailKindProcedure = engine.DetailKindProcedure )
重置数据模式常量(ImportOptions/MigrateOptions.ResetMode)
const ArtifactStorageLocal = "local"
ArtifactStorageLocal 本地产物存储常量(ArtifactRef.Storage 取值)
Variables ¶
This section is empty.
Functions ¶
func AsSvcErr ¶
AsSvcErr 提取错误链中的 *SvcError(无则返回 false,target 不变)。
var se *dqex.SvcError
if dqex.AsSvcErr(err, &se) { fmt.Println(se.Code) }
func IsArtifactLogicalPath ¶
IsArtifactLogicalPath 判断 dqex 任务产物路径是否为逻辑路径(exports/、compares/ 前缀)。 逻辑路径产物在库模式(WithArtifactStore 注入)下已由 dqex 直传对象存储, 宿主登记引用即可,无需再从本地文件搬运。
func RelayoutDir ¶
func RelayoutDir(srcDir, dstDir string, rules []LayoutRule, dropUnmatched bool) error
RelayoutDir 按 rules 将 srcDir 重排复制到 dstDir。
- 文件按相对路径('/' 分隔)依序匹配规则,首个命中者生效;
- Dest 中的 '*' 按顺序替换为 Match 捕获段,目标目录自动创建,同名文件覆盖;
- 无规则命中的文件:dropUnmatched 为 false 时按原路径复制,true 时丢弃;
- srcDir/dstDir 均须为已存在的目录,可相同(原地重排,此时以复制后再删除源文件实现);
- dstDir 不得位于 srcDir 内部(遍历会重复处理已复制的产物),返回错误。
func RelayoutDirWithMap ¶
func RelayoutDirWithMap(srcDir, dstDir string, rules []LayoutRule, dropUnmatched bool, observed func(src, dst string)) error
RelayoutDirWithMap 同 RelayoutDir,额外通过 observed 回调上报每条"源相对路径 → 目标相对路径" 实际映射(含未命中按原路径复制的),便于宿主校验与调试;dst 为空表示该文件被丢弃。
func RenderRowsSQL ¶
RenderRowsSQL 把行数据(map 切片,键为列名)渲染为方言正确的可执行 SQL 文本, 每行一条语句(MySQL 为 REPLACE INTO,PG/Oracle 为方言 upsert),统一结尾分号。 列类型/标识符引用/值转义均取自 cli.GetTableInfo 元数据(与 cydb 导入链路同源); 行中缺失的列自动省略(与旧宿主导出行为一致)。cli 为 nil 或无行时返回空串。
func StripSQLDBPrefix ¶
StripSQLDBPrefix 清除 SQL 中的源库名前缀(`db`. / db.),使 MySQL 风格 SQL 可在 PG/openGauss 等目标库上执行。前缀仅当命中 knownDBs(宿主按业务配置传入的库名 集合)时清除,避免误伤表别名前缀(t.col);isMySQL 为 false 时同时移除全部反引号。
Types ¶
type ArtifactRef ¶
type ArtifactRef struct {
// Storage 产物存储后端:local / minio / s3 / obs / oss
Storage string
// Ref 本地文件路径或对象存储 object key
Ref string
// Size 字节数;目录产物为 0
Size int64
}
ArtifactRef 产物引用(阶段二即引入,避免未来签名破坏): 本地模式 Storage="local"、Ref=文件路径;对象存储模式 Ref=object key (存储实现见设计文档 4.4.3,触发式)。
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client dqex 库客户端:进程内调用核心能力的统一入口。
并发契约(3.6):
- Client 可被多个 goroutine 并发使用:并发调用任意能力方法(含同一方法)安全。
- 连接池为进程级共享(engine cliPool);Close() 幂等,之后调用能力方法返回 ErrClientClosed。 注意:Close 会释放进程级连接池,同进程其他 Client 实例的池化连接一并释放(进程级语义)。
- 同进程多 Client 实例可用但共享元数据缓存与连接池(v0 语义,安全无冲突)。
func New ¶
New 创建库客户端。零依赖即可用:不传任何 Option 时为"库模式"(StoreNone), 不发现全局配置、不建 SQLite 存储;连接经 WithInlineConns/WithConnProvider 注入。
func (*Client) AddConnection ¶
func (c *Client) AddConnection(ctx context.Context, rec ConnRecord) (ConnRecord, error)
AddConnection 保存连接配置:rec.ID 非空为按主键更新,否则新建(自动生成 ID)。 StoreNone 库模式下不落盘、仅内存注册表生效;连接配置变更会使元数据缓存失效。
func (*Client) CancelTask ¶
CancelTask 取消运行中的 dqex 任务(任务不存在或已结束返回错误,宿主自行决定 是否忽略)。库模式宿主经 TaskHooks 镜像任务时,取消应先经本方法转发到引擎, 再更新镜像状态(仅改镜像不取消引擎会导致引擎仍在写库而环境并发保护已放开)。
func (*Client) Close ¶
Close 释放资源(幂等):关闭 SQLite 存储(StoreSQLite)+ 释放进程级连接池。 Close 之后再调用能力方法返回 ErrClientClosed。
func (*Client) CompareSnapshot ¶
func (c *Client) CompareSnapshot(ctx context.Context, snap *Snapshot, target *DBConnInfo, opts SnapshotCompareOptions, cb ProgressFunc) (*CompareResult, error)
CompareSnapshot 快照与目标库对比,返回结构 + 数据差异结果。 target 用完整连接信息而非 connKey:对比目标常为临时环境,未必已注册(3.2)。
func (*Client) CreateSnapshot ¶
func (c *Client) CreateSnapshot(ctx context.Context, connKey string, dbs []string, opts SnapshotParams, cb ProgressFunc) (*Snapshot, error)
CreateSnapshot 创建快照(同步):dbs 支持多库,空库名回退到连接默认库。 StoreSQLite(WithDataDir)下自动落盘到快照目录;StoreNone 库模式下仅内存返回, 调用方自行持久化(可用 json.Marshal 序列化 *Snapshot,LoadSnapshot 读回)。
func (*Client) DeleteConnection ¶
DeleteConnection 删除连接(按主键 ID,兼容名称/短名)。 StoreNone 库模式下仅删除内存注册表连接;StoreSQLite 落盘删除并级联清理。
func (*Client) DeleteTableRows ¶
func (c *Client) DeleteTableRows(ctx context.Context, connKey, db, table string, pkColumns []string, rows [][]any) (int64, error)
DeleteTableRows 按主键批量删除整行,返回累计影响行数。
func (*Client) GenerateSQL ¶
func (c *Client) GenerateSQL(ctx context.Context, connKey, db string, p GenSQLParams) (string, error)
GenerateSQL 由行/单元格/过滤条件生成方言正确的 SQL 文本(只产出不执行)。
func (*Client) GetCellValue ¶
func (c *Client) GetCellValue(ctx context.Context, connKey, db, table, column string, pkColumns []string, pkValues []any) (any, error)
GetCellValue 按主键 + 列名定位单行单列,返回该单元格完整值(大字段懒加载取值)。
func (*Client) InsertTableRow ¶
func (c *Client) InsertTableRow(ctx context.Context, connKey, db string, p InsertRowParams) (int64, error)
InsertTableRow 新增一行(named bind 防注入),返回影响行数。
func (*Client) ListConnections ¶
ListConnections 列出所有连接(按名称排序,展示稳定)。 来源合并:内存注册表 + 持久层(StoreSQLite)+ ConnProvider.ListConns(外部持有)。 该方法为只读视图,Close 后仍可安全调用(返回当前内存快照)。
func (*Client) LoadSnapshot ¶
LoadSnapshot 离线读快照文件,不需要连接(Close 后仍可安全调用)。
func (*Client) ObjectDDL ¶
func (c *Client) ObjectDDL(ctx context.Context, connKey, db, objType, name string) (*ObjectDDLResult, error)
ObjectDDL 查询对象的创建语句(表/视图/索引等)。
func (*Client) Objects ¶
func (c *Client) Objects(ctx context.Context, connKey, db, schema string, force bool) (*DBSchema, error)
Objects 列出指定库/schema 的对象清单(表/视图等分组)。
func (*Client) PingConnection ¶
PingConnection 对已注册连接执行 SELECT 探活,返回往返耗时(毫秒)。
func (*Client) QueryTablePage ¶
func (c *Client) QueryTablePage(ctx context.Context, connKey, db, table string, p PageParams) (*TablePageResult, error)
QueryTablePage 分页查询单表数据并返回全表总行数(对象树数据浏览专用)。
func (*Client) RunCompare ¶
func (c *Client) RunCompare(ctx context.Context, opts CompareOptions, cb ProgressFunc) (*CompareResult, error)
RunCompare 执行数据库对比(作用域为单个库对,或经 Databases/DBMapping 多库对比), 返回结构 + 数据差异结果。
func (*Client) RunDictionary ¶
func (c *Client) RunDictionary(ctx context.Context, opts DictionaryOptions, cb ProgressFunc) (*ArtifactRef, error)
RunDictionary 执行数据字典生成,返回产物引用(落位规则同 RunExport)。
func (*Client) RunExport ¶
func (c *Client) RunExport(ctx context.Context, opts ExportOptions, cb ProgressFunc) (*ArtifactRef, error)
RunExport 执行导出任务,返回产物引用。 产物落位:ExportOptions.OutputDir 显式指定则用之;为空时回填持久化 export 目录; StoreNone 库模式且未设 WithDataDir 时必须显式指定,否则返回 ErrExpOutDir。
func (*Client) RunImport ¶
func (c *Client) RunImport(ctx context.Context, opts ImportOptions, cb ProgressFunc) (*ImportResult, error)
RunImport 执行导入任务(目标连接可传 connKey 或完整连接信息): 支持 .sql / .zip / .json(DataPackage 数据包)输入;Rollback=true 时返回精确回滚产物。
func (*Client) RunMigrate ¶
func (c *Client) RunMigrate(ctx context.Context, opts MigrateOptions, cb ProgressFunc) error
RunMigrate 执行结构 + 数据迁移任务。
func (*Client) RunSQLScript ¶
func (c *Client) RunSQLScript(ctx context.Context, connKey, db, sql string, p ScriptParams) ([]*SQLQueryResult, error)
RunSQLScript 执行 SQL 脚本(可含多语句),返回各语句结果集。
func (*Client) Schemas ¶
func (c *Client) Schemas(ctx context.Context, connKey, db string, force bool) ([]SchemaSummary, error)
Schemas 列出指定库下的 schema 摘要(PG 系;MySQL/Oracle 返回空)。
func (*Client) TableColumns ¶
func (c *Client) TableColumns(ctx context.Context, connKey, db, table string) ([]TableColumnInfo, error)
TableColumns 获取表的列信息(名称/类型/可空/主键/默认值)。
func (*Client) TestConnection ¶
func (c *Client) TestConnection(ctx context.Context, conn DBConnInfo) error
TestConnection 测试连接可用性(拨号即断开,不进入连接池)。
func (*Client) UpdateTableCell ¶
func (c *Client) UpdateTableCell(ctx context.Context, connKey, db string, p UpdateCellParams) (int64, error)
UpdateTableCell 更新单个单元格(named bind + 标识符引用防注入),返回影响行数。
type ConnProvider ¶
type ConnProvider = service.ConnProvider
ConnProvider 连接提供者回调:连接列表完全由外部持有(见 options.go WithConnProvider)
type ConnSource ¶
type ConnSource = service.ConnSource
ConnSource 连接解析来源(ConnHooks.OnResolved 参数:inline/memory/provider/store)
type Contributor ¶
type Contributor = service.Contributor
Contributor 业务对象贡献者(代理层扩展点):宿主注册取数/回写回调, 导出/导入编排(目录、进度、打包、清单)由 dqex 统一负责
type ContributorImportRequest ¶
type ContributorImportRequest = service.ContributorImportRequest
ContributorImportRequest 贡献者导入回调请求
type ContributorRequest ¶
type ContributorRequest = service.ContributorRequest
ContributorRequest 贡献者导出回调请求
type ContributorResult ¶
type ContributorResult = service.ContributorResult
ContributorResult 贡献者导出回调结果
type DBConnInfo ¶
type DBConnInfo = service.DBConnInfo
DBConnInfo 数据库连接信息(含子类型,内嵌 def.DBConnection)
func NewConn ¶
func NewConn(dbType, host string, port int, user, pwd, dbName string) DBConnInfo
NewConn 构造网络型数据库连接信息(mysql/postgresql/oracle 及兼容产品)。 DBConnInfo 内嵌 cydb def.DBConnection(复合字面量不能直接写提升字段), 提供此便捷构造器;SubType/Service 等特殊字段对返回值直接赋值即可:
c := dqex.NewConn("mysql", "10.0.0.1", 3306, "root", "***", "app")
c.SubType = "mariadb" // 兼容产品按需指定
type DataPackage ¶
type DataPackage = service.DataPackage
DataPackage 数据交换包(dqex 数据格式契约,字段冻结): FormatJSON 导出 / .json 导入 / 精确回滚的载体
func LoadDataPackage ¶
func LoadDataPackage(data []byte) (*DataPackage, error)
LoadDataPackage 从 JSON 字节解析数据包(DataPackage 格式契约,与 tl-env DataHolder 兼容)。 供宿主 DataPreparer 回调在修改包内容后重建数据包(JSON 往返)。
type DataPrepareRequest ¶
type DataPrepareRequest = service.DataPrepareRequest
DataPrepareRequest 数据前置处理请求
type DataPreparer ¶
type DataPreparer = service.DataPreparer
DataPreparer 数据前置处理器(代理层扩展点,key=目标库名):.json 数据包 导入应用前回调宿主执行业务策略(如流程/表单版本合并),可修改包内容
type DictionaryOptions ¶
type DictionaryOptions = service.DictionaryOptions
DictionaryOptions 数据字典导出选项
type ExportDetail ¶
type ExportDetail = engine.ExportDetail
ExportDetail 导出明细回调条目(ExportOptions.OnDetail 参数): 单表/单对象导出完成时同步通知宿主,供清单/审计等旁路采集
type GenSQLParams ¶
type GenSQLParams = engine.GenSQLParams
GenSQLParams 快速生成 SQL 的参数(行/单元格/过滤条件 → 方言正确语句)
type ImportResult ¶
type ImportResult struct {
// TotalDatabases 导入的库数(.sql/.zip/.json 合计)
TotalDatabases int
// TotalStmts 执行的语句数
TotalStmts int64
// RollbackRef 精确回滚产物引用(仅 .json 数据包导入且 ImportOptions.Rollback=true 时非空;
// .sql 导入为盲执行,无行级语义不生成回滚产物)
RollbackRef *ArtifactRef
// SkippedTables 跳过的表(无主键,无法精确导入/回滚;宿主侧应告警)
SkippedTables []string
// Unrollback 执行了但无法生成精确回滚的语句(如目标方言不支持的 ALTER 列变更;
// 宿主侧应告警,必要时人工补偿)
Unrollback []string
}
ImportResult 导入任务结果
type LayoutRule ¶
LayoutRule 单条路径重排规则。 Match 为源相对路径 glob(path.Match 语义,'/' 分隔,不支持跨级 **); Dest 为目标相对路径模板,其中每个 '*' 依次替换为 Match 中各 '*' 捕获段。 例:{Match: "flow/*", Dest: "5_flow/*"}、{Match: "camunda.sql", Dest: "1_coe/camunda.sql"}。
type Option ¶
type Option func(*options)
func WithAIConfig ¶
WithAIConfig 注入 AI 辅助 SQL 配置(OpenAI 兼容协议)。 BaseURL / APIKey / Model 三项非空即启用 AI 助手(前端 AI 入口随之显示); 配置由宿主持有(如宿主 config.yml),dqex 不落盘、不持久化 APIKey。 与 WithConfigFile 同时提供时,本注入优先(覆盖配置文件中的 ai 段)。
func WithArtifactStore ¶
WithArtifactStore 注入对象存储(复用 infrakit cystore,见 4.4.3)。 现阶段用于快照持久化:snapshots/index.json 与 <id>.json 落对象存储 (key 前缀 snapshots/),解决容器化部署本地盘易失导致的快照丢失; exports/compares 仍为本地工作目录(最终交付由宿主自行处理)。 未注入时快照落本地目录(CLI/独立部署默认行为不变);产物对象化 (ArtifactRef 对象存储化)仍为后续触发式规划,届时复用本 store。 bucket 为空时使用 store 自带的默认 bucket;所需 provider(minio/local) 已由本包 blank import 注册,独立二进制无需宿主侧注册。
func WithCacheClient ¶
func WithCacheClient(rc *cydist.RedisClient) Option
WithCacheClient 实例注入元数据缓存 Redis(宿主复用已有 Redis,触发式)。
func WithCacheRedis ¶
WithCacheRedis 元数据缓存走 Redis(参数注入,见 4.4.2,触发式)。
func WithConfigFile ¶
WithConfigFile 显式指定全局配置 config.yaml,空 = 不加载全局配置(不自动发现 ~/.dqex/config.yaml)。
func WithConnHooks ¶
WithConnHooks 注入连接生命周期回调(审计/监控,3.5)。
回调契约:回调运行在 dqex 的调用 goroutine 上,OnConnect 在关键路径上必须快速返回 (重活自己起 goroutine);回调内不得再回调 Client 方法;回调参数中的连接结构由 dqex 持有副本,回调方不得复用修改;OnResolved/OnConnect 参数含 Pwd 字段,日志注意遮蔽。
func WithConnProvider ¶
func WithConnProvider(p ConnProvider) Option
WithConnProvider 注入连接提供者回调:连接列表完全由外部持有(3.5)。 连接可来自宿主的配置中心、密钥管理系统(Vault/KMS)、自身数据库等任何地方, dqex 不落盘、不缓存密码;每次真实建连都走 GetConn 取最新凭证(密码轮换天然支持)。
回调契约:ListConns/GetConn 可能被并发调用,实现方必须线程安全; GetConn 返回 (nil, nil) 表示不认识该 key(继续尝试后续解析来源)。
func WithContributors ¶
func WithContributors(ctbs ...Contributor) Option
WithContributors 注册业务对象贡献者模板(代理层扩展点)。 宿主业务对象(流程/面板/规则/数据表等)的"取数"与"回写"经此回调代理给宿主实现, 导出/导入的编排(任务目录、进度、zip 打包、<Type>/ 目录约定)由 dqex 统一负责。 任务侧仅需在 ExportOptions/ImportOptions.Contributors 填 Type(+ IDs)即可引用。
回调契约:Export/Import 运行在任务执行 goroutine 上,阻塞会暂停进度推送; 取消由回调参数 ctx 控制;回调内不得再回调 Client 方法。
func WithDataDir ¶
WithDataDir 设置持久化根目录(快照/历史/连接库),空 = 纯内存。 非空即 StoreSQLite 便捷糖(内部等价 sqlite 连接,CLI/Web 同款行为)。
func WithDataPreparers ¶
func WithDataPreparers(preparers map[string]DataPreparer) Option
WithDataPreparers 注册数据前置处理器(代理层扩展点,key=目标库名): .json 数据包(DataPackage)导入应用前回调宿主执行业务策略(如业务对象版本 合并),宿主可直接修改包内容后返回。
func WithInlineConns ¶
WithInlineConns 便捷方式:静态注入少量连接(内部转成只读内存注册表)。 连接 key 取 ID,缺省回退 Name,均为空时自动生成(conn-1/conn-2/...)。
func WithQueryHooks ¶
func WithQueryHooks(hooks QueryHooks) Option
WithQueryHooks 注入 SQL 审计钩子(代理层扩展点):任务(导出/导入/迁移)与 RunSQLScript 执行的每条语句都会回调 OnQuery,宿主接合规审计/慢查询采集。
回调契约:同步调用且必须快速返回(重活自行起 goroutine,审计耗时直接计入语句 响应时间);回调内不得再回调 Client 方法;失败语句同样回调(rowsAffected=-1); 超长语句会被截断至 4096 字节后回调(截断点回退至 UTF-8 字符边界)。
func WithStoreConn ¶
func WithStoreConn(conn def.DBConnection) Option
WithStoreConn 注入内部存储连接(已落地,4.4.1):元数据(连接/任务/历史/审计/ 工作区/AI 会话)经 cydb 跨方言落入宿主数据库(sqlite/mysql/postgresql/oracle, 表自动迁移;MySQL 需 EnsureDB=true 预建 database),不写本地 SQLite。 产物类目录资源仍为本地目录(无 DataDir 时回退系统临时目录;产物对象存储化见 WithArtifactStore)。
func WithStoreDB ¶
WithStoreDB 实例注入内部存储(宿主复用已有 cydb client/连接池,触发式)。
func WithTaskHooks ¶
WithTaskHooks 注入任务生命周期回调(代理层扩展点):Web 异步任务(导出/字典/ 导入/迁移/对比)启动与进度推送(含终态)时回调宿主,用于任务镜像/通知等。
回调契约:OnTaskStart 在任务登记完成后、执行 goroutine 启动前同步调用(宿主 落库应快速返回,重活自行起 goroutine);OnTaskProgress 在任务执行 goroutine 中随进度推送调用,宿主需自行保证并发安全;回调内不得再回调 Client 方法。 未注入(nil)时零开销,CLI/Web 独立形态不注入、行为不变。
type PageParams ¶
type PageParams struct {
// Page 页码(1 起)
Page int
// PageSize 每页行数
PageSize int
// SortSpecs 多列排序(按顺序叠加 ORDER BY,优先级从高到低)
SortSpecs []SortSpec
// ExcludeColumns 需省略的大字段列(二进制/超长文本,查询时 NULL 占位)
ExcludeColumns []string
// Filters 列过滤条件(AND 叠加,值参数化绑定防注入)
Filters []ColumnFilter
}
PageParams QueryTablePage 参数(参数对象化)。
type ProgressFunc ¶
type ProgressFunc = service.ProgressFunc
ProgressFunc 进度回调。 契约(3.6):回调在 dqex 执行 goroutine 上同步调用,回调内阻塞会暂停任务; 回调返回不是取消机制——取消统一由 ctx 控制;不保证串行、不保证每阶段恰好触发一次, 消费方按幂等展示设计。
type QueryHooks ¶
type QueryHooks = service.QueryHooks
QueryHooks SQL 审计钩子(逐语句回调 OnQuery,经 WithQueryHooks 注册)
type ScriptParams ¶
type ScriptParams struct {
// Limit 结果集单语句最大返回行数(<=0 走服务层默认值)
Limit int
// Offset 结果集偏移(分页浏览)
Offset int
// Mode 执行模式(保留字段,透传服务层)
Mode string
}
ScriptParams RunSQLScript 参数(参数对象化)。
type SnapshotCompareOptions ¶
type SnapshotCompareOptions = service.SnapshotCompareOptions
SnapshotCompareOptions 快照对比选项
type SnapshotParams ¶
type SnapshotParams struct {
// Name 快照名称(展示用)
Name string
// Description 快照描述
Description string
// IncludeSamples 是否采样表数据行
IncludeSamples bool
// SampleLimit 每表采样行数上限(<=0 走引擎默认值)
SampleLimit int
}
SnapshotParams CreateSnapshot 参数(参数对象化)。
type TableColumnInfo ¶
type TableColumnInfo = engine.TableColumnInfo
TableColumnInfo 表列信息(名称/类型/可空/主键/默认值)
type TableCondition ¶
type TableCondition = service.TableCondition
TableCondition 表级过滤条件(迁移/导出/对比取数)
type TaskStartInfo ¶
type TaskStartInfo = service.TaskStartInfo
TaskStartInfo 任务启动信息(TaskHooks.OnTaskStart 参数)
type UpdateCellParams ¶
type UpdateCellParams = engine.UpdateCellParams
UpdateCellParams 单元格更新参数(named bind 防注入)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package changelog 嵌入版本升级记录(双语 Markdown),供前端 API 按语言返回。
|
Package changelog 嵌入版本升级记录(双语 Markdown),供前端 API 按语言返回。 |
|
Package dqexweb 提供 dqex Web UI + API 向宿主 gin engine 的挂载能力 (docs/library-api-design.md 6.5.1 主形态 B:宿主 Go 程序同进程内嵌,同源 iframe)。
|
Package dqexweb 提供 dqex Web UI + API 向宿主 gin engine 的挂载能力 (docs/library-api-design.md 6.5.1 主形态 B:宿主 Go 程序同进程内嵌,同源 iframe)。 |
|
examples
|
|
|
common
Package common 提供 examples 共用的小工具:从环境变量构造连接信息与错误退出。
|
Package common 提供 examples 共用的小工具:从环境变量构造连接信息与错误退出。 |
|
compare
command
compare 演示库对结构 + 数据对比,结果按库分组返回。
|
compare 演示库对结构 + 数据对比,结果按库分组返回。 |
|
export
command
export 演示导出任务:结构 + 数据导出为 zip 产物,RunExport 返回 ArtifactRef。
|
export 演示导出任务:结构 + 数据导出为 zip 产物,RunExport 返回 ArtifactRef。 |
|
migrate
command
migrate 演示安装工具场景的最小形态:进程内完成一次结构 + 数据迁移。
|
migrate 演示安装工具场景的最小形态:进程内完成一次结构 + 数据迁移。 |
|
query
command
query 演示元数据浏览 + SQL 执行 + 表分页查询。
|
query 演示元数据浏览 + SQL 执行 + 表分页查询。 |
|
snapshot
command
snapshot 演示创建快照(StoreNone 下仅内存返回)→ 落盘 JSON → 离线读回 → 与目标库对比。
|
snapshot 演示创建快照(StoreNone 下仅内存返回)→ 落盘 JSON → 离线读回 → 与目标库对比。 |
|
webmount
command
webmount 演示宿主 gin engine 同进程挂载 dqex(形态 B,docs/library-api-design.md 6.5.1): 库 API 与 Web UI 同进程共享同一 Service,宿主页面同源 iframe 嵌入。
|
webmount 演示宿主 gin engine 同进程挂载 dqex(形态 B,docs/library-api-design.md 6.5.1): 库 API 与 Web UI 同进程共享同一 Service,宿主页面同源 iframe 嵌入。 |
|
internal
|
|
|
cli/sqlcmd
Package sqlcmd 提供 dqex sql 子命令:交互式 SQL 终端 + JSON 输出。
|
Package sqlcmd 提供 dqex sql 子命令:交互式 SQL 终端 + JSON 输出。 |
|
engine
Package engine 核心引擎层:导出/导入/迁移。
|
Package engine 核心引擎层:导出/导入/迁移。 |
|
llm
Package llm 提供对大模型 OpenAI 兼容协议的薄封装(基于 Eino ChatModel)。
|
Package llm 提供对大模型 OpenAI 兼容协议的薄封装(基于 Eino ChatModel)。 |
|
service
Package service 业务服务层:模型定义 + 持久化 + 任务调度 + CLI。
|
Package service 业务服务层:模型定义 + 持久化 + 任务调度 + CLI。 |
|
store
Package store 存储领域:领域模型(值对象)+ 存储接口 + SQLite 实现 + 自动迁移。
|
Package store 存储领域:领域模型(值对象)+ 存储接口 + SQLite 实现 + 自动迁移。 |
|
web
Package web Web 层:遵循 cygin 规范的服务启动 + 路由注册 + API handler。
|
Package web Web 层:遵循 cygin 规范的服务启动 + 路由注册 + API handler。 |