This repository has been archived on 2020-04-27. You can view files and clone it, but cannot push or open issues or pull requests.
cmd/xorm/dump.go
Lunny Xiao 9ccdb0ebed
All checks were successful
continuous-integration/drone/push Build is passing
upgrade to xorm v1.0.1
2020-04-27 09:43:43 +08:00

59 lines
1.2 KiB
Go

// 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"
"xorm.io/xorm"
"xorm.io/xorm/log"
)
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 xorm 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(log.LOG_UNKNOWN)
err = engine.Ping()
if err != nil {
fmt.Println(err)
return
}
err = engine.DumpAll(os.Stdout)
if err != nil {
fmt.Println(err)
return
}
}