-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.go
More file actions
78 lines (63 loc) · 1.41 KB
/
schema.go
File metadata and controls
78 lines (63 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package batchflow
type SchemaInterface interface {
Name() string
Columns() []string
}
// ConflictStrategy 冲突处理策略
type ConflictStrategy uint8
const (
ConflictIgnore ConflictStrategy = iota
ConflictReplace
ConflictUpdate
)
// 操作配置
type SQLOperationConfig struct {
ConflictStrategy ConflictStrategy
// 其他操作相关配置...
}
// Schema 表结构定义
type Schema struct {
name string
columns []string
}
// NewSchema 创建新的Schema实例
func NewSchema(
name string,
columns ...string,
) *Schema {
return &Schema{
name: name,
columns: columns,
}
}
func (s *Schema) Name() string {
return s.name
}
func (s *Schema) Columns() []string {
return s.columns
}
type SQLSchema struct {
*Schema
operationConfig SQLOperationConfig
}
func NewSQLSchema(name string, operationConfig SQLOperationConfig, columns ...string) *SQLSchema {
return &SQLSchema{
Schema: NewSchema(name, columns...),
operationConfig: operationConfig,
}
}
func (s *SQLSchema) OperationConfig() any {
return s.operationConfig
}
var DefaultOperationConfig = SQLOperationConfig{
ConflictStrategy: ConflictIgnore,
}
var ConflictIgnoreOperationConfig = SQLOperationConfig{
ConflictStrategy: ConflictIgnore,
}
var ConflictReplaceOperationConfig = SQLOperationConfig{
ConflictStrategy: ConflictReplace,
}
var ConflictUpdateOperationConfig = SQLOperationConfig{
ConflictStrategy: ConflictUpdate,
}