From 45d7b0bfacc2a313a2698ea2b217868b7d4b2021 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 8 Dec 2022 17:09:44 +0300 Subject: [PATCH] Gradually adding support for all features --- tpl/macro.twig | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tpl/macro.twig b/tpl/macro.twig index 078adf5..908c3f6 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -100,6 +100,10 @@ func (self *{{o.name}}) WriteFields(writer meta.Writer) error { {{_self.stats_methods(meta, o)}} {% endif %} +{% if has_token(o, 'POD') and has_token(o, 'id') and has_token(o, 'table') and has_token(o, 'owner') %} +{{_self.db_item_methods(meta, o)}} +{% endif %} + {% endmacro %} {% macro props_map(tokens) %} @@ -260,6 +264,54 @@ func (self *{{o.name}}) Values() []interface{} { {% endmacro %} +{% macro db_item_methods(meta, o) %} + +func (self *{{o.name}}) NewInstance() meta.IMetaDataItem { + return New{{o.name}}() +} + +func (self *{{o.name}}) GetDbTableName() string { + return "{{token(o, 'table')}}" +} + +func (self *{{o.name}}) GetDbFields() []string { + return self.CLASS_FIELDS() +} + +func (self *{{o.name}}) GetOwnerFieldName() string { + return "{{token(o, 'owner')}}" +} + +func (self *{{o.name}}) GetIdFieldName() string { + return "{{token(o, 'id')}}" +} + +func (self *{{o.name}}) GetIdValue() uint64 { + return uint64(self.{{token(o, 'id')|ucfirst}}) +} + +func (self *{{o.name}}) Import(data interface{}) { + switch data.(type) { + case {{o.name}}: + { + row := data.({{o.name}}) +{%- for f in get_all_fields(meta, o) ~%} + self.{{f.name|ucfirst}} = row.{{f.name|ucfirst}} +{%- endfor ~%} + break + } + default: + break + } +} + +func (self *{{o.name}}) Export(data []interface{}) { +{%- for f in get_all_fields(meta, o) ~%} + data[{{loop.index0}}] = self.{{f.name|ucfirst}} +{%- endfor ~%} +} +{% endmacro %} + {% macro decl_enum(o) %} //==============================