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) %} //==============================