add api2sql

This commit is contained in:
白茶清欢 2023-07-30 18:52:45 +08:00
parent de92cee2e2
commit fe548187d4
4 changed files with 109 additions and 0 deletions

18
api2sql/.gitignore vendored Normal file
View File

@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
.idea
logs
.vscode

View File

@ -0,0 +1,31 @@
// Package abstract ...
//
// Description : abstract ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-07-29 21:07
package abstract
import (
"git.zhangdeman.cn/zhangdeman/api2sql/define"
"gorm.io/gorm"
)
// IDatabase 数据库市里的约束
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:07 2023/7/29
type IDatabase interface {
// GetFlag 获取数据库标识
GetFlag() string
// GetFieldList 获取表字段列表
GetFieldList() []*define.TableField
// Connect 连接数据库
Connect() (*gorm.DB, error)
// GetMaster 获取主库连接
GetMaster() (*gorm.DB, error)
// GetSlave 获取从库连接
GetSlave() (*gorm.DB, error)
}

48
api2sql/define/core.go Normal file
View File

@ -0,0 +1,48 @@
// Package define ...
//
// Description : define ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-07-29 21:04
package define
// Database 数据库的配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:04 2023/7/29
type Database struct {
Driver string `json:"driver"` // 数据库驱动 : 暂时支持 mysql / sqlite
Flag string `json:"flag"` // 数据库标识, 全局唯一
Config map[string]interface{} `json:"config"` // 数据库的配置
}
// Table 数据表结构
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:43 2023/7/30
type Table struct {
Name string `json:"name"` // 数据表名称
Split bool `json:"split"` // 是否分表
SplitCount int64 `json:"split_count"` // 分表数量
SplitField string `json:"split_field"` // 分表字段
PrimaryField string `json:"primary_field"` // 主键字段
FieldList []*TableField `json:"field_list"` // 字段列表
}
// TableField 数据表字段配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:08 2023/7/29
type TableField struct {
Description string `json:"description"` // 字段描述
Name string `json:"name"` // 数据表中字段名称
Alias string `json:"alias"` // 字段别名 : 未设置和 Name 保持一致, 设置了将会以此字段值输出
Type string `json:"type"` // 数据类型 : int/uint/bool/float/string/object/array
AllowOutput bool `json:"allow_output"` // 是否允许对外输出
DefaultValue interface{} `json:"default_value"` // 针对 INSERT 语句, 在未指定字段值的情况下写入的默认值, 为nil不设置
ValidateRule interface{} `json:"validate_rule"` // 字段验证规则 : 不满足规则直接报错 TODO : 待完成
}

12
api2sql/go.sum Normal file
View File

@ -0,0 +1,12 @@
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=