Base support for creating RDBMS tables from models

This commit is contained in:
Denis Arh
2022-09-14 12:18:43 +02:00
parent c0631666d1
commit a6c0d8ecee
48 changed files with 4456 additions and 3658 deletions
@@ -23,27 +23,22 @@ var (
ResourceType: {{ .resType }},
Attributes: dal.AttributeSet{
{{ range .attributes }}
{{- range .attributes }}
&dal.Attribute{
Ident: {{ printf "%q" .expIdent }},
{{ if .primaryKey }}PrimaryKey: true, {{ end -}}
{{ if .sortable }}Sortable: true, {{ end -}}
{{ if .filterable }}Filterable: true, {{ end }}
Type: {{ .dal.fqType }}{
Type: &{{ .dal.fqType }}{
{{ if .dal.nullable }}Nullable: true,{{ end -}}
{{ if eq .dal.type "Ref" }}
RefAttribute: {{ printf "%q" .dal.attribute }},
RefModel: &dal.ModelRef{
ResourceType: {{ printf "%q" .dal.refModelResType }},
},
{{ end }}
{{ end -}}
},
{{ if .store }}
Store: &dal.CodecAlias{Ident: {{ printf "%q" .storeIdent }}},
{{ end }}
},
{{ end -}}
},
@@ -51,6 +46,15 @@ var (
{{ end }}
)
func All() dal.ModelSet {
return dal.ModelSet{
{{- range .models }}
{{ .var }},
{{- end }}
}
}
func Register(ctx context.Context, mr modelReplacer) (err error) {
{{- range .models }}
if err = mr.ReplaceModel(ctx, {{ .var }}); err != nil {
+7
View File
@@ -40,7 +40,12 @@ import (
expIdent: #expIdent | *strings.ToTitle(ident)
// store identifier
// @todo this should be moved to dal.ident
storeIdent: #ident | *name
// enable or disable store for this attribute
// @todo we should use dal prop for this, and extend it to support bool "false"
// so that it can be disabled
store: bool | *true
unique: bool | *false
@@ -60,6 +65,8 @@ import (
nullable: bool | *false
default?: string
if type == "ID" {
generatedByStore: bool | *false
}