Restructured CUE resource definitions (struct, attributes)

This commit is contained in:
Denis Arh
2022-08-17 19:12:20 +02:00
parent 4f26fc5f6b
commit ccfb4c09bb
44 changed files with 2606 additions and 635 deletions
+8 -6
View File
@@ -5,8 +5,10 @@ import (
)
#Model: {
// Each field can be
[name=_]: {"name": name} & #ModelAttribute
ident: string
attributes: {
[name=_]: {"name": name} & #ModelAttribute
}
}
// logic in struct fields is a bit different
@@ -38,7 +40,7 @@ import (
#ModelAttributeJsonTag
}
IdField: #ModelAttribute & {
IdField: {
// Expecting ID field to always have name ID
name: "id"
expIdent: "ID"
@@ -49,7 +51,7 @@ IdField: #ModelAttribute & {
goType: "uint64"
}
HandleField: #ModelAttribute & {
HandleField: {
// Expecting ID field to always have name handle
name: "handle"
unique: true
@@ -58,12 +60,12 @@ HandleField: #ModelAttribute & {
goType: "string"
}
SortableTimestampField: #ModelAttribute & {
SortableTimestampField: {
sortable: true
goType: "time.Time"
}
SortableTimestampNilField: #ModelAttribute & {
SortableTimestampNilField: {
sortable: true
goType: "*time.Time"
}
+10 -12
View File
@@ -18,11 +18,18 @@ import (
// Fully qualified resource name
fqrn: string | *(platform + "::" + component + ":" + handle)
model: #Model
model: #Model & {
// use resource handle (plural) as model ident as default
// model ident represents a db table or a container name
ident: string | *"\(strings.Replace(handle, "-", "_", -1))s"
}
filter: {
"expIdent": #expIdent | *"\(expIdent)Filter"
model: #Model
struct: {
[name=_]: {"name": name} & #ModelAttribute
}
// generate filtering by-nil-state for the specified fields
"byNilState": [...string]
@@ -86,7 +93,7 @@ import (
api?: {
lookups: [...{
_expFields: [ for f in fields {strings.ToTitle(model[f].expIdent)}]
_expFields: [ for f in fields {strings.ToTitle(model.attributes[f].expIdent)}]
"expIdent": "Lookup\(store.expIdent)By" + strings.Join(_expFields, "")
description: string | *""
@@ -108,15 +115,6 @@ import (
return: [...string]
}]
}
settings: {
defaultOrder: [...{ field: string, descending: bool | *false }]
rdbms: {
// use resource handle (plural) as RDBMS table name as default
table: string | *"\(strings.Replace(handle, "-", "_", -1))s"
}
}
}
}