Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
corteza
corteza-server
Commits
6206aacd
Commit
6206aacd
authored
4 years ago
by
Denis Arh
Browse files
Options
Download
Email Patches
Plain Diff
Simplify RDBMS codegen templates
parent
62cae2c3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
47 deletions
+47
-47
pkg/codegen/assets/actions.gen.go.tpl
pkg/codegen/assets/actions.gen.go.tpl
+2
-2
pkg/codegen/assets/events.gen.go.tpl
pkg/codegen/assets/events.gen.go.tpl
+24
-24
pkg/codegen/assets/rest_request.go.tpl
pkg/codegen/assets/rest_request.go.tpl
+2
-2
pkg/codegen/assets/store_rdbms.gen.go.tpl
pkg/codegen/assets/store_rdbms.gen.go.tpl
+19
-19
No files found.
pkg/codegen/assets/actions.gen.go.tpl
View file @
6206aacd
...
...
@@ -19,8 +19,8 @@ import (
{{- end }}
"github.com/cortezaproject/corteza-server/pkg/actionlog"
{{- range
$import := $
.Import }}
{{ normalizeImport
$import
}}
{{- range .Import }}
{{ normalizeImport
.
}}
{{- end }}
)
...
...
This diff is collapsed.
Click to expand it.
pkg/codegen/assets/events.gen.go.tpl
View file @
6206aacd
...
...
@@ -10,8 +10,8 @@ package {{ .Package }}
import (
"encoding/json"
{{- range
$i, $import :=
.Imports }}
{{ normalizeImport
$import
}}
{{- range .Imports }}
{{ normalizeImport
.
}}
{{- end }}
)
...
...
@@ -25,8 +25,8 @@ type (
// This type is auto-generated.
{{ camelCase $r.ResourceIdent "base" }} struct {
immutable bool
{{- range
$p :=
$r.Properties }}
{{
$p
.Name }} {{
$p
.Type }}
{{- range $r.Properties }}
{{ .Name }} {{ .Type }}
{{- end }}
}
...
...
@@ -65,18 +65,18 @@ func ({{ camelCase $r.ResourceIdent $event }}) EventType() string {
//
// This function is auto-generated.
func {{ camelCase "" $r.ResourceIdent $event }}(
{{- range
$p :=
$r.Properties }}
{{- if not
$p
.Internal }}
{{ camelCase "arg"
$p
.Name }} {{
$p
.Type }},
{{- range $r.Properties }}
{{- if not .Internal }}
{{ camelCase "arg" .Name }} {{ .Type }},
{{- end -}}
{{- end}}
) *{{ camelCase $r.ResourceIdent $event }} {
return
&
{{ camelCase $r.ResourceIdent $event }}{
{{ camelCase $r.ResourceIdent "base" }}:
&
{{ camelCase $r.ResourceIdent "base" }}{
immutable: false,
{{- range
$p :=
$r.Properties }}
{{- if not
$p
.Internal }}
{{
$p
.Name }}: {{ camelCase "arg"
$p
.Name }},
{{- range $r.Properties }}
{{- if not .Internal }}
{{ .Name }}: {{ camelCase "arg" .Name }},
{{- end -}}
{{- end}}
},
...
...
@@ -89,18 +89,18 @@ func {{ camelCase "" $r.ResourceIdent $event }}(
//
// This function is auto-generated.
func {{ camelCase "" $r.ResourceIdent $event "Immutable" }}(
{{- range
$p :=
$r.Properties }}
{{- if not
$p
.Internal }}
{{ camelCase "arg"
$p
.Name }} {{
$p
.Type }},
{{- range $r.Properties }}
{{- if not .Internal }}
{{ camelCase "arg" .Name }} {{ .Type }},
{{- end -}}
{{- end}}
) *{{ camelCase $r.ResourceIdent $event }} {
return
&
{{ camelCase $r.ResourceIdent $event }}{
{{ camelCase $r.ResourceIdent "base" }}:
&
{{ camelCase $r.ResourceIdent "base" }}{
immutable: true,
{{- range
$p :=
$r.Properties }}
{{- if not
$p
.Internal }}
{{
$p
.Name }}: {{ camelCase "arg"
$p
.Name }},
{{- range $r.Properties }}
{{- if not .Internal }}
{{ .Name }}: {{ camelCase "arg" .Name }},
{{- end -}}
{{- end}}
},
...
...
@@ -110,21 +110,21 @@ func {{ camelCase "" $r.ResourceIdent $event "Immutable" }}(
{{ range
$p :=
$r.Properties }}
{{ if not
$p
.Immutable }}
// {{ camelCase "Set"
$p
.Name }} sets new {{
$p
.Name }} value
{{ range $r.Properties }}
{{ if not .Immutable }}
// {{ camelCase "Set" .Name }} sets new {{ .Name }} value
//
// This function is auto-generated.
func (res *{{ camelCase $r.ResourceIdent "base" }}) {{ camelCase "Set"
$p
.Name }}({{ camelCase "arg"
$p
.Name }} {{
$p
.Type }}) {
res.{{
$p
.Name }} = {{ camelCase "arg"
$p
.Name }}
func (res *{{ camelCase $r.ResourceIdent "base" }}) {{ camelCase "Set" .Name }}({{ camelCase "arg" .Name }} {{ .Type }}) {
res.{{ .Name }} = {{ camelCase "arg" .Name }}
}
{{ end }}
// {{ camelCase ""
$p
.Name }} returns {{
$p
.Name }}
// {{ camelCase "" .Name }} returns {{ .Name }}
//
// This function is auto-generated.
func (res {{ camelCase $r.ResourceIdent "base" }}) {{ camelCase ""
$p
.Name }}() {{
$p
.Type }} {
return res.{{
$p
.Name }}
func (res {{ camelCase $r.ResourceIdent "base" }}) {{ camelCase "" .Name }}() {{ .Type }} {
return res.{{ .Name }}
}
{{ end }}
...
...
This diff is collapsed.
Click to expand it.
pkg/codegen/assets/rest_request.go.tpl
View file @
6206aacd
...
...
@@ -17,8 +17,8 @@ import (
"mime/multipart"
"net/http"
"strings"
{{- range
$i, $import := $
.Imports }}
{{ normalizeImport
$import
}}
{{- range .Imports }}
{{ normalizeImport
.
}}
{{- end }}
)
...
...
This diff is collapsed.
Click to expand it.
pkg/codegen/assets/store_rdbms.gen.go.tpl
View file @
6206aacd
...
...
@@ -18,8 +18,8 @@ import (
{{- if $.Search.EnablePaging }}
"github.com/cortezaproject/corteza-server/pkg/filter"
{{- end }}
{{- range
$import := $
.Import }}
{{ normalizeImport
$import
}}
{{- range .Import }}
{{ normalizeImport
.
}}
{{- end }}
)
...
...
@@ -297,15 +297,15 @@ func (s Store) {{ export "query" $.Types.Plural }} (
{{
-
range
$
lookup
:=
$.Lookups
}}
//
{{
toggleExport
$
lookup
.Export
"
Lookup
"
$.
Types.Singular
"
By
"
$
lookup
.Suffix
}}
{{
comment
$
lookup
.Description
true
-
}}
func
(
s
Store
)
{{
toggleExport
$
lookup
.Export
"
Lookup
"
$.
Types.Singular
"
By
"
$
lookup
.Suffix
}}(
ctx
context.Context
{{
template
"
extraArgsDef
"
$
}}{{
-
range
$
lookup
.RDBMSColumns
}},
{{
cc2underscore
.
Field
}}
{{
.
Type
}}{{
-
end
}})
(
*
{{
$.
Types.GoType
}},
error
)
{
{{
-
range
$.
Lookups
}}
//
{{
toggleExport
.
Export
"
Lookup
"
$.
Types.Singular
"
By
"
.
Suffix
}}
{{
comment
.
Description
true
-
}}
func
(
s
Store
)
{{
toggleExport
.
Export
"
Lookup
"
$.
Types.Singular
"
By
"
.
Suffix
}}(
ctx
context.Context
{{
template
"
extraArgsDef
"
$
}}{{
-
range
.
RDBMSColumns
}},
{{
cc2underscore
.
Field
}}
{{
.
Type
}}{{
-
end
}})
(
*
{{
$.
Types.GoType
}},
error
)
{
return
s.execLookup
{{
$.
Types.Singular
}}(
ctx
{{
template
"
extraArgsCall
"
$
}},
squirrel.Eq
{
{{
-
range
$
lookup
.RDBMSColumns
}}
{{
-
range
.
RDBMSColumns
}}
s.preprocessColumn
({{
printf
"%
q
"
.
AliasedColumn
}},
{{
printf
"%
q
"
.
LookupFilterPreprocess
}})
:
s.preprocessValue
({{
cc2underscore
.
Field
}},
{{
printf
"%
q
"
.
LookupFilterPreprocess
}}),
{{
-
end
}}
{{
range
$
field
,
$
value
:=
$lookup
.Filter
}}
{{
range
$
field
,
$
value
:=
.Filter
}}
"{{
($
field
|
$.
RDBMS.Columns.Find
).
AliasedColumn
}}"
:
{{
$
value
}},
{{
-
end
}}
})
...
...
@@ -362,8 +362,8 @@ func (s Store) {{ toggleExport .Update.Export "Partial" $.Types.Singular "Update
ctx
,
{{
template
"
filterByPrimaryKeys
"
$.
RDBMS.Columns.PrimaryKeyFields
}},
s.internal
{{
export
$.
Types.Singular
}}
Encoder
(
res
).
Skip
(
{{
-
range
$
field
:=
$.RDBMS.Columns.PrimaryKeyFields
-
}}
{{
printf
"%
q
"
$
field
.Column
}},
{{
-
range
$.
RDBMS.Columns.PrimaryKeyFields
-
}}
{{
printf
"%
q
"
.
Column
}},
{{
-
end
-
}}
).
Only
(
onlyColumns...
))
if
err
!=
nil
{
...
...
@@ -655,9 +655,9 @@ func (s *Store) check{{ export $.Types.Singular }}Constraints(ctx context.Contex
// Only string and uint64 are supported for now
// feel free to add additional types if needed
var valid = true
{{- range
$lookup :=
$.Lookups }}
{{ if
$lookup
.UniqueConstraintCheck }}
{{- range
$lookup
.RDBMSColumns }}
{{- range $.Lookups }}
{{ if .UniqueConstraintCheck }}
{{- range .RDBMSColumns }}
{{ if eq .Type "uint64" }}
valid = valid
&&
res.{{ .Field }} > 0
{{ else if eq .Type "string" }}
...
...
@@ -674,10 +674,10 @@ func (s *Store) check{{ export $.Types.Singular }}Constraints(ctx context.Contex
}
{{- range
$lookup :=
$.Lookups }}
{{ if
$lookup
.UniqueConstraintCheck }}
{{- range $.Lookups }}
{{ if .UniqueConstraintCheck }}
{
ex, err := s.{{ toggleExport
$lookup
.Export "Lookup" $.Types.Singular "By"
$lookup
.Suffix }}(ctx{{ template "extraArgsCall" $ }}{{- range
$lookup
.RDBMSColumns }}, res.{{ .Field }} {{- end }})
ex, err := s.{{ toggleExport .Export "Lookup" $.Types.Singular "By" .Suffix }}(ctx{{ template "extraArgsCall" $ }}{{- range .RDBMSColumns }}, res.{{ .Field }} {{- end }})
if err == nil
&&
ex != nil
&&
ex.ID != res.ID {
return store.ErrNotUnique
} else if !errors.Is(err, store.ErrNotFound) {
...
...
@@ -705,16 +705,16 @@ func (s *Store) {{ unexport $.Types.Singular }}Hook(ctx context.Context, key tri
{{- define "filterByPrimaryKeys" -}}
squirrel.Eq{
{{ range
$field :=
. -}}
s.preprocessColumn({{ printf "%q"
$field
.AliasedColumn }}, {{ printf "%q"
$field
.LookupFilterPreprocess }}): s.preprocessValue(res.{{
$field
.Field }}, {{ printf "%q"
$field
.LookupFilterPreprocess }}),
{{ range . -}}
s.preprocessColumn({{ printf "%q" .AliasedColumn }}, {{ printf "%q" .LookupFilterPreprocess }}): s.preprocessValue(res.{{ .Field }}, {{ printf "%q" .LookupFilterPreprocess }}),
{{- end }}
}
{{- end -}}
{{- define "filterByPrimaryKeysWithArgs" -}}
squirrel.Eq{
{{ range
$field :=
. -}}
s.preprocessColumn({{ printf "%q"
$field
.AliasedColumn }}, {{ printf "%q"
$field
.LookupFilterPreprocess }}): s.preprocessValue({{
$field
.Arg }}, {{ printf "%q"
$field
.LookupFilterPreprocess }}),
{{ range . -}}
s.preprocessColumn({{ printf "%q" .AliasedColumn }}, {{ printf "%q" .LookupFilterPreprocess }}): s.preprocessValue({{ .Arg }}, {{ printf "%q" .LookupFilterPreprocess }}),
{{ end }}
}
{{- end -}}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment