diff --git a/src/codegen.inc.php b/src/codegen.inc.php index fe2a607..36f4d54 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -36,6 +36,7 @@ function supported_tokens() 'statist', 'statist_skip', + 'statist_alias', ]; } diff --git a/tpl/macro.twig b/tpl/macro.twig index cbaff20..4b1ff80 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -93,7 +93,10 @@ func (self *{{o.name}}) WriteFields(writer meta.Writer) error { } %ext_methods% -%analytics_methods% + +{% if has_token(o, 'statist') %} +{{_self.stats_methods(meta, o)}} +{% endif %} {% endmacro %} @@ -209,6 +212,34 @@ self.fieldsMask = meta.FieldsMask{} {% endmacro %} +{% macro stats_methods(meta, o) %} + +func (self *{{o.name}}) Table() string { + return "{{token(o, 'statist')}}" +} + +func (self * {{o.name}}) Columns() []string { + return []string{ + {%- for f in get_all_fields(meta, o) ~%} + {%- if not has_token(f, 'statist_skip') ~%} + "{{token_or(f, 'statist_alias', f.name)}}", + {%- endif ~%} + {%- endfor ~%} + } +} + +func (self *{{o.name}}) Values() []interface{} { + return []interface{}{ + {%- for f in get_all_fields(meta, o) ~%} + {%- if not has_token(f, 'statist_skip') ~%} + self.{{f.name|ucfirst}}, + {%- endif ~%} + {%- endfor ~%} + } +} + +{% endmacro %} + {% macro decl_enum(o) %} //============================== @@ -269,3 +300,4 @@ func New{{o.name}}ByName(name string) ({{o.name}}, error) { {% macro decl_rpc(o) %} {% endmacro %} +