cmd

package module
v0.0.0-...-daaf348 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2019 License: BSD-3-Clause Imports: 26 Imported by: 0

README

中文

xorm tools

xorm tools is a set of tools for database operation.

Source Install

go get xorm.io/cmd/xorm

and you will install the depends below:

** For sqlite support, you need build via go build -tags sqlite3 because of this driver ask cgo.

Commands

All the commands below.

  • reverse reverse a db to codes
  • shell a general shell to operate all kinds of database
  • dump dump database all table struct's and data to standard output
  • source execute a sql from std in
  • driver list all supported drivers

Reverse

Reverse command is a tool to convert your database struct to all kinds languages of structs or classes. After you installed the tool, you can type

xorm help reverse

to get help

example:

cd $GOPATH/src/github.com/go-xorm/cmd/xorm

sqlite: xorm reverse sqite3 test.db templates/goxorm

mysql: xorm reverse mysql root:@/xorm_test?charset=utf8 templates/goxorm

mymysql: xorm reverse mymysql xorm_test2/root/ templates/goxorm

postgres: xorm reverse postgres "dbname=xorm_test sslmode=disable" templates/goxorm

mssql: xorm reverse mssql "server=test;user id=testid;password=testpwd;database=testdb" templates/goxorm

will generated go files in ./model directory

Template and Config

Now, xorm tool supports go and c++ two languages and have go, goxorm, c++ three of default templates. In template directory, we can put a config file to control how to generating.

lang=go
genJson=1

lang must be go or c++ now. genJson can be 1 or 0, if 1 then the struct will have json tag.

Shell

Shell command provides a tool to operate database. For example, you can create table, alter table, insert data, delete data and etc.

xorm shell sqlite3 test.db will connect to the sqlite3 database and you can type help to list all the shell commands.

Dump

Dump command provides a tool to dump all database structs and data as SQL to your standard output.

xorm dump sqlite3 test.db could dump sqlite3 database test.db to standard output. If you want to save to file, just type xorm dump sqlite3 test.db > test.sql.

Source

xorm source sqlite3 test.db < test.sql will execute sql file on the test.db.

Driver

List all supported drivers since default build will not include sqlite3.

LICENSE

BSD License http://creativecommons.org/licenses/BSD/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CmdDriver = &Command{
	UsageLine: "driver",
	Short:     "list all supported drivers",
	Long: `
list all supported drivers
`,
}
View Source
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
`,
}
View Source
var CmdReverse = &Command{
	UsageLine: "reverse [-s] driverName datasourceName tmplPath [generatedPath] [tableFilterReg]",
	Short:     "reverse a db to codes",
	Long: `
according database's tables and columns to generate codes for Go, C++ and etc.

    -s                Generated one go file for every table
    driverName        Database driver name, now supported four: mysql mymysql sqlite3 postgres
    datasourceName    Database connection uri, for detail infomation please visit driver's project page
    tmplPath          Template dir for generated. the default templates dir has provide 1 template
    generatedPath     This parameter is optional, if blank, the default value is models, then will
                      generated all codes in models dir
    tableFilterReg    Table name filter regexp
`,
}
View Source
var CmdShell = &Command{
	UsageLine: "shell driverName datasourceName",
	Short:     "a general shell to operate all kinds of database",
	Long: `
general database's shell 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
`,
}
View Source
var CmdSource = &Command{
	UsageLine: "source driverName datasourceName",
	Short:     "source execute std in to datasourceName",
	Long: `
source from standard std in 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
`,
}

Functions

This section is empty.

Types

type Command

type Command struct {
	// Run runs the command.
	// The args are the arguments after the command name.
	Run func(cmd *Command, args []string)

	// UsageLine is the one-line usage message.
	// The first word in the line is taken to be the command name.
	UsageLine string

	// Short is the short description shown in the 'go help' output.
	Short string

	// Long is the long message shown in the 'go help <this-command>' output.
	Long string

	// Flag is a set of flags specific to this command.
	Flags map[string]bool
}

A Command is an implementation of a go command like go build or go fix.

func (*Command) Name

func (c *Command) Name() string

Name returns the command's name: the first word in the usage line.

func (*Command) Runnable

func (c *Command) Runnable() bool

Runnable reports whether the command can be run; otherwise it is a documentation pseudo-command such as importpath.

func (*Command) Usage

func (c *Command) Usage()

type LangTmpl

type LangTmpl struct {
	Funcs      template.FuncMap
	Formater   func(string) (string, error)
	GenImports func([]*core.Table) map[string]string
}
var (
	CPlusTmpl LangTmpl = LangTmpl{
		template.FuncMap{"Mapper": mapper.Table2Obj,
			"Type":    cPlusTypeStr,
			"UnTitle": unTitle,
		},
		nil,
		genCPlusImports,
	}
)
var (
	GoLangTmpl LangTmpl = LangTmpl{
		template.FuncMap{"Mapper": mapper.Table2Obj,
			"Type":       typestring,
			"Tag":        tag,
			"UnTitle":    unTitle,
			"gt":         gt,
			"getCol":     getCol,
			"UpperTitle": upTitle,
		},
		formatGo,
		genGoImports,
	}
)
var (
	ObjcTmpl LangTmpl = LangTmpl{
		template.FuncMap{"Mapper": mapper.Table2Obj,
			"Type":    objcTypeStr,
			"UnTitle": unTitle,
		},
		nil,
		genCPlusImports,
	}
)

type Tmpl

type Tmpl struct {
	Tables  []*core.Table
	Imports map[string]string
	Models  string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL