-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportDB.go
54 lines (44 loc) · 1.35 KB
/
ExportDB.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
package main
// func ExportDBToCSV(dbsetting Model_DBSetting, tables []string) {
// db, err := ConnectDB(dbsetting)
// path := filepath.Join(datafolder, dbsetting.Tenant_id)
// CreateFolderIfNotExists(path)
// if err == nil {
// for _, tablename := range tables {
// logrus.Info(tablename)
// //ignore tenantmas
// if tablename != table_tenant {
// ExportTableToCSV(db, path, tablename)
// }
// }
// }
// }
// func ExportTableToCSV(db *sql.DB, path string, tablename string) {
// sql := fmt.Sprintf("SELECT * FROM %s", tablename)
// logrus.Info(sql)
// rows, err := db.Query(sql)
// if err == nil {
// filename := filepath.Join(path, tablename+".csv")
// err = sqltocsv.WriteFile(filename, rows)
// if err == nil {
// logrus.Info("Exported ", tablename)
// } else {
// logrus.Fatal(err)
// }
// } else {
// logrus.Fatal(err)
// }
// }
// func WriteFile(csvFileName string, rows *sql.Rows) error {
// return New(rows).WriteFile(csvFileName)
// }
// // New will return a Converter which will write your CSV however you like
// // but will allow you to set a bunch of non-default behaivour like overriding
// // headers or injecting a pre-processing step into your conversion
// func New(rows *sql.Rows) *Converter {
// return &Converter{
// rows: rows,
// WriteHeaders: true,
// Delimiter: ',',
// }
// }