1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-28 20:14:14 +00:00
Beego/orm/docs/zh/Cmd.md
2013-08-19 22:37:53 +08:00

804 B

命令模式

注册模型与数据库以后,调用 RunCommand 执行 orm 命令

func main() {
	// orm.RegisterModel...
	// orm.RegisterDataBase...
	...
	orm.RunCommand()
}
go build main.go
./main orm
# 直接执行可以显示帮助
# 如果你的程序可以支持的话,直接运行 go run main.go orm 也是一样的效果

自动建表

./main orm syncdb -h
Usage of orm command: syncdb:
  -db="default": DataBase alias name
  -force=false: drop tables before create
  -v=false: verbose info

使用 -force=1 可以 drop table 后再建表

使用 -v 可以查看执行的 sql 语句

打印建表SQL

./main orm sqlall -h
Usage of orm command: syncdb:
  -db="default": DataBase alias name

默认使用别名为 default 的数据库