-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.go
executable file
·58 lines (47 loc) · 1.17 KB
/
dump.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
// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"github.com/liangyt123/gorm/xorm"
"xorm.io/core"
)
var CmdDump = &Command{
UsageLine: "dump driverName datasourceName",
Short: "dump database all table struct's and data to standard output",
Long: `
dump database for sqlite3, mysql, postgres.
driverName Database driver name, now supported four: mysql mymysql sqlite3 postgres
datasourceName Database connection uri, for detail infomation please visit driver's project page
`,
}
func init() {
CmdDump.Run = runDump
CmdDump.Flags = map[string]bool{}
}
func runDump(cmd *Command, args []string) {
if len(args) != 2 {
fmt.Println("params error, please see gorm help dump")
return
}
var err error
engine, err = xorm.NewEngine(args[0], args[1])
if err != nil {
fmt.Println(err)
return
}
engine.ShowSQL(false)
engine.Logger().SetLevel(core.LOG_UNKNOWN)
err = engine.Ping()
if err != nil {
fmt.Println(err)
return
}
err = engine.DumpAll(os.Stdout)
if err != nil {
fmt.Println(err)
return
}
}