Compare commits
No commits in common. "master" and "v0.0.2" have entirely different histories.
30
README.md
30
README.md
|
@ -1,31 +1 @@
|
||||||
# 数据库组件
|
# 数据库组件
|
||||||
|
|
||||||
组件提供了操作`mysql`一些相关的内容,通过组件可以方便的实现怎删改查的接口
|
|
||||||
|
|
||||||
|
|
||||||
## 插件
|
|
||||||
|
|
||||||
### 主键插件
|
|
||||||
|
|
||||||
主键插件是指的是用于生成数据库主键的插件,非自增长的ID主键插件,使用方式
|
|
||||||
|
|
||||||
```go
|
|
||||||
db.Use(&identified.Identify{})
|
|
||||||
```
|
|
||||||
|
|
||||||
### 数据校验插件
|
|
||||||
|
|
||||||
数据校验插件用户增改的时候对数据格式进行校验,使用方式
|
|
||||||
|
|
||||||
```go
|
|
||||||
db.Use(validate.New())
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### 分表插件
|
|
||||||
|
|
||||||
分表插件提供了自动分表的功能,使用方式
|
|
||||||
|
|
||||||
```go
|
|
||||||
db.Use(sharding.New())
|
|
||||||
```
|
|
14
rest.go
14
rest.go
|
@ -312,7 +312,6 @@ func fieldAttribute(field *schema.Field) types.Attribute {
|
||||||
attr.Live.Columns = strings.Split(kv[1], ",")
|
attr.Live.Columns = strings.Split(kv[1], ",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attr.Match = types.MatchExactly
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dropdown := field.Tag.Get("dropdown")
|
dropdown := field.Tag.Get("dropdown")
|
||||||
|
@ -380,7 +379,6 @@ func fieldAttribute(field *schema.Field) types.Attribute {
|
||||||
}
|
}
|
||||||
attr.Values = append(attr.Values, fv)
|
attr.Values = append(attr.Values, fv)
|
||||||
}
|
}
|
||||||
attr.Match = types.MatchExactly
|
|
||||||
}
|
}
|
||||||
if !field.Creatable {
|
if !field.Creatable {
|
||||||
attr.Disable = append(attr.Disable, types.ScenarioCreate)
|
attr.Disable = append(attr.Disable, types.ScenarioCreate)
|
||||||
|
@ -554,9 +552,6 @@ func CloneSchemas(ctx context.Context, db *gorm.DB, domain string) (err error) {
|
||||||
models []*types.Schema
|
models []*types.Schema
|
||||||
)
|
)
|
||||||
tx := db.WithContext(ctx)
|
tx := db.WithContext(ctx)
|
||||||
if domain == "" {
|
|
||||||
domain = defaultDomain
|
|
||||||
}
|
|
||||||
if err = tx.Where("domain=?", defaultDomain).Find(&values).Error; err != nil {
|
if err = tx.Where("domain=?", defaultDomain).Find(&values).Error; err != nil {
|
||||||
return fmt.Errorf("schema not found")
|
return fmt.Errorf("schema not found")
|
||||||
}
|
}
|
||||||
|
@ -613,9 +608,6 @@ func GetSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableName
|
||||||
|
|
||||||
// VisibleSchemas 获取某个场景下面的schema
|
// VisibleSchemas 获取某个场景下面的schema
|
||||||
func VisibleSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableName, scenario string) ([]*types.Schema, error) {
|
func VisibleSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableName, scenario string) ([]*types.Schema, error) {
|
||||||
if domain == "" {
|
|
||||||
domain = defaultDomain
|
|
||||||
}
|
|
||||||
schemas, err := GetSchemas(ctx, db, domain, moduleName, tableName)
|
schemas, err := GetSchemas(ctx, db, domain, moduleName, tableName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -637,11 +629,7 @@ func VisibleSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableN
|
||||||
func ModelTypes(ctx context.Context, db *gorm.DB, model any, domainName, labelColumn, valueColumn string) (values []*types.TypeValue) {
|
func ModelTypes(ctx context.Context, db *gorm.DB, model any, domainName, labelColumn, valueColumn string) (values []*types.TypeValue) {
|
||||||
tx := db.WithContext(ctx)
|
tx := db.WithContext(ctx)
|
||||||
result := make([]map[string]any, 0, 10)
|
result := make([]map[string]any, 0, 10)
|
||||||
if domainName == "" {
|
tx.Model(model).Select(labelColumn, valueColumn).Where("domain=?", domainName).Scan(&result)
|
||||||
tx.Model(model).Select(labelColumn, valueColumn).Scan(&result)
|
|
||||||
} else {
|
|
||||||
tx.Model(model).Select(labelColumn, valueColumn).Where("domain=?", domainName).Scan(&result)
|
|
||||||
}
|
|
||||||
values = make([]*types.TypeValue, 0, len(result))
|
values = make([]*types.TypeValue, 0, len(result))
|
||||||
for _, pairs := range result {
|
for _, pairs := range result {
|
||||||
feed := &types.TypeValue{}
|
feed := &types.TypeValue{}
|
||||||
|
|
Loading…
Reference in New Issue