Browse Source

add mgr src

main
root 5 years ago
parent
commit
35f32a19ef
  1. 68
      src/components/HelloWorld.vue

68
src/components/HelloWorld.vue

@ -147,9 +147,69 @@ export default {
const properties = v.properties; const properties = v.properties;
const tableName = toCamelCase(v.title); const tableName = toCamelCase(v.title);
const tableNameLower = lowerCase(tableName); const tableNameLower = lowerCase(tableName);
var primary = ``;
var primaryLower = lowerCase(primary)
Object.keys(properties).forEach(function (key) {
const o = properties[key];
const skey = toCamelCase(key);
if (Object.prototype.hasOwnProperty.call(o, "$comment")) {
primary = skey;
}
});
var enumUpdate = ``; var enumUpdate = ``;
var enumdefine = ``; var enumdefine = ``;
var paramsheader = ` var paramsheader = `
var ${tableName}Set = wire.NewSet(wire.Struct(new(${tableName}Mgr), "*"))
type ${tableName}Mgr struct {
DB *gorm.DB
Cache cache.Cache
}
// GetTableName get sql table name.
func (obj *${tableName}Mgr) TableName() string {
return "${v.title}"
}
func (obj *${tableName}Mgr) PreTableName(s string) string {
b := strings.Builder{}
b.WriteString(obj.TableName())
b.WriteString(".")
b.WriteString(s)
return b.String()
}
// Delete By ID
func (obj *${tableName}Mgr) Delete(ctx context.Context, ${primaryLower} int64) error {
err := obj.DB.WithContext(ctx).Delete(&${tableName}{}, ${primaryLower}).Error
return err
}
// CacheKey${primary} CacheKey generate by ids
func (obj *${tableName}Mgr) CacheKey${primary}(${primaryLower} int64) string {
return strings.Join([]string{obj.TableName(), "${primaryLower}", utils.AsString(${primaryLower})}, "_")
}
// Updates
func (obj *${tableName}Mgr) Updates(ctx context.Context, input *${tableName}, q *${tableNameLower}Q) error {
Q := q.Query(ctx)
key := ""
if k, _ := Q.InstanceGet("cache_key"); k != nil {
key = utils.AsString(k)
}
return obj.Cache.Exec(ctx, key, func(ctx context.Context) error {
return Q.Updates(*input).Error
})
}
// Create
func (obj *${tableName}Mgr) Create(ctx context.Context, input *${tableName}) (*${tableName}, error) {
if err := obj.DB.WithContext(ctx).Create(input).Error; err != nil {
return nil, err
}
return input, nil
}
type ${tableNameLower}Q struct { type ${tableNameLower}Q struct {
Mgr *${tableName}Mgr Mgr *${tableName}Mgr
opts []GormOptionFunc opts []GormOptionFunc
@ -233,14 +293,6 @@ export default {
var filtertail = `}} var filtertail = `}}
return opt}`; return opt}`;
var primary = ``;
Object.keys(properties).forEach(function (key) {
const o = properties[key];
const skey = toCamelCase(key);
if (Object.prototype.hasOwnProperty.call(o, "$comment")) {
primary = skey;
}
});
Object.keys(properties).forEach(function (key) { Object.keys(properties).forEach(function (key) {
const o = properties[key]; const o = properties[key];

Loading…
Cancel
Save