Adding @statist support

This commit is contained in:
Pavel Shevaev 2022-12-08 16:51:08 +03:00
parent e9b7dbf1fa
commit 5b32ba2c09
2 changed files with 34 additions and 1 deletions

View File

@ -36,6 +36,7 @@ function supported_tokens()
'statist',
'statist_skip',
'statist_alias',
];
}

View File

@ -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 %}