Github地址
中文文档 | DOCUMENT
okcli 可以将指定数据表生成为对应的model文件,目前支持将列名、数据类型、默认值、注释带入指定model中,
就像如下文件:
import "time"
type (
Student struct {
Id int32 `db:"id"`
Name string `db:"name"` // the student's name
Gender int8 `db:"gender"` // the student's gender,0-male,1-female,DEFAULT:0
Age int8 `db:"age"` // the student's age,DEFAULT:0
Class string `db:"class"` // the student's class
CreateTime time.Time `db:"create_time"` // the column create time,DEFAULT:CURRENT_TIMESTAMP
UpdateTime time.Time `db:"update_time"` // the column last update time,DEFAULT:CURRENT_TIMESTAMP
}
)
准备工作
根据自己的操作系统平台下载不同的二进制文件
- windows: okcli_windows.exe
- mac OS: okcli_darwin
- linux: okcli_linux
或者clone源码进行编译。
其次,将下载或编译后的二进制文件设置到环境变量中,以mac OS为例子:
假设二进制文件okcli存放在/usr/local/okcli文件目录下
$ sudo vi ~/.bash_profile
在文件末尾添加:
$ export OKCLI=/usr/local/okcli
$ export PATH=$PATH:$OKCLI
最后执行以下source ~/.bash_profile
使用说明
数据库准备
这里以本地数据库举例,在demo库下新建student、course、student_score表,sql如下:
CREATE TABLE `student` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`name