2024-01-12 13:15:30 +08:00
|
|
|
package dbi
|
2022-10-15 17:38:34 +08:00
|
|
|
|
2023-05-24 12:32:17 +08:00
|
|
|
import (
|
2024-01-06 22:36:50 +08:00
|
|
|
"database/sql"
|
2024-03-18 12:25:40 +08:00
|
|
|
"errors"
|
2024-03-15 09:01:51 +00:00
|
|
|
)
|
|
|
|
|
|
2024-03-01 04:03:03 +00:00
|
|
|
const (
|
|
|
|
|
// -1. 无操作
|
|
|
|
|
DuplicateStrategyNone = -1
|
|
|
|
|
// 1. 忽略
|
|
|
|
|
DuplicateStrategyIgnore = 1
|
|
|
|
|
// 2. 更新
|
|
|
|
|
DuplicateStrategyUpdate = 2
|
|
|
|
|
)
|
|
|
|
|
|
2024-01-23 04:08:02 +00:00
|
|
|
type DbCopyTable struct {
|
|
|
|
|
Id uint64 `json:"id"`
|
|
|
|
|
Db string `json:"db" `
|
|
|
|
|
TableName string `json:"tableName"`
|
|
|
|
|
CopyData bool `json:"copyData"` // 是否复制数据
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-16 14:22:19 +08:00
|
|
|
// -----------------------------------元数据接口定义------------------------------------------
|
2024-03-11 20:04:20 +08:00
|
|
|
// 数据库方言 用于获取元信息接口、批量插入等各个数据库方言不一致的实现方式
|
2024-01-12 13:15:30 +08:00
|
|
|
type Dialect interface {
|
2024-01-24 08:29:16 +00:00
|
|
|
|
2024-01-05 08:55:34 +08:00
|
|
|
// GetDbProgram 获取数据库程序模块,用于数据库备份与恢复
|
2024-02-06 07:16:56 +00:00
|
|
|
GetDbProgram() (DbProgram, error)
|
2024-01-05 05:31:32 +00:00
|
|
|
|
|
|
|
|
// 批量保存数据
|
2024-03-01 04:03:03 +00:00
|
|
|
BatchInsert(tx *sql.Tx, tableName string, columns []string, values [][]any, duplicateStrategy int) (int64, error)
|
2024-01-05 05:31:32 +00:00
|
|
|
|
2024-03-15 13:31:53 +08:00
|
|
|
// 拷贝表
|
2024-01-23 04:08:02 +00:00
|
|
|
CopyTable(copy *DbCopyTable) error
|
2024-03-15 09:01:51 +00:00
|
|
|
|
2024-03-18 12:25:40 +08:00
|
|
|
CreateTable(columns []Column, tableInfo Table, dropOldTable bool) (int, error)
|
2024-03-15 09:01:51 +00:00
|
|
|
|
|
|
|
|
CreateIndex(tableInfo Table, indexs []Index) error
|
|
|
|
|
|
|
|
|
|
// 有些数据库迁移完数据之后,需要更新表自增序列为当前表最大值
|
|
|
|
|
UpdateSequence(tableName string, columns []Column)
|
2024-03-18 12:25:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DefaultDialect struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetDbProgram 获取数据库程序模块,用于数据库备份与恢复
|
|
|
|
|
func (dd *DefaultDialect) GetDbProgram() (DbProgram, error) {
|
|
|
|
|
return nil, errors.New("not support db program")
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 21:46:03 +08:00
|
|
|
func (dd *DefaultDialect) UpdateSequence(tableName string, columns []Column) {}
|