forked from jarvanstack/mysqldump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
98 lines (84 loc) · 2.07 KB
/
plugin.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package mysqldump
import (
"compress/flate"
"io"
)
/*
Plugin functions for dump procedure
*/
// WithDropTable Delete table
func WithDropTable() DumpOption {
return func(option *dumpOption) {
option.isDropTable = true
}
}
// WithData Export table data
func WithData() DumpOption {
return func(option *dumpOption) {
option.isData = true
}
}
// WithAllDatabases Export all databases
func WithAllDatabases() DumpOption {
return func(option *dumpOption) {
option.isAllDB = true
}
}
// WithUseDb Whether to add a specified library statement.
// If there are multiple libraries, this setting is invalid.
func WithUseDb() DumpOption {
return func(option *dumpOption) {
option.isUseDb = true
}
}
// WithDBs Export specified databases, mutually exclusive with WithAllDatabases
// WithAllDatabases has higher priority
func WithDBs(databases ...string) DumpOption {
return func(option *dumpOption) {
option.Dbs = databases
}
}
// WithTables Export specific tables
func WithTables(tables ...string) DumpOption {
return func(option *dumpOption) {
option.tables = tables
}
}
// WithAllTables Export all tables
func WithAllTables() DumpOption {
return func(option *dumpOption) {
option.isAllTables = true
}
}
// WithMultiInsert Export multi-inserts in one command
func WithMultiInsert(num int) DumpOption {
return func(option *dumpOption) {
option.perDataNumber = num
}
}
// WithWriter Export to specified writer (file, stdOut, etc.)
func WithWriter(writer io.Writer) DumpOption {
return func(option *dumpOption) {
option.writer = writer
}
}
// WithLogErrors Whether to output logs
func WithLogErrors() DumpOption {
return func(option *dumpOption) {
option.log = true
}
}
// WithCompression Whether to compress desired file with gzip
func WithCompression(level string) DumpOption {
return func(option *dumpOption) {
option.isCompressed = true
switch level {
case "BEST", "MAX":
option.compressionLevel = flate.BestCompression
case "FAST", "MIN":
option.compressionLevel = flate.BestSpeed
default:
option.compressionLevel = flate.DefaultCompression
}
}
}