db_skip token support

This commit is contained in:
Pavel Merzlyakov 2023-07-31 17:48:54 +03:00
parent 00bb2d96dd
commit e7fa182cb4
2 changed files with 10 additions and 11 deletions

View File

@ -39,6 +39,7 @@ function supported_tokens()
'table',
'table_pkey',
'table_json_kv',
'db_skip',
'data_root',
'bitfields',

View File

@ -189,7 +189,7 @@ func Save{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ s.name
{% macro root_save(s) %}
func Save{{ s.name }}(ctx context.Context, dbe metadb.Execer, rec {{ s.name }}) error {
{%~ for f in s.fields %}
{%~ for f in s.fields|filter(f => not has_token(f, 'db_skip')) %}
{%~ if f.type is array %}
if err := Save{{ f.type.value.name }}Collection(ctx, dbe, rec.{{ f|fname }}); err != nil {
return err
@ -207,7 +207,7 @@ func Save{{ s.name }}(ctx context.Context, dbe metadb.Execer, rec {{ s.name }})
{% macro root_save_diff(s) %}
func Save{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ s.name }}) error {
{%~ for f in s.fields %}
{%~ for f in s.fields|filter(f => not has_token(f, 'db_skip')) %}
{%~ if f.type is array %}
if err := Save{{ f.type.value.name }}CollectionDiff(ctx, dbe, rec.{{ f|fname }}); err != nil {
return err
@ -226,11 +226,15 @@ func Save{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ s.name
{% macro root_delete(s) %}
{% set delete_by = meta_field(token(s, 'data_root')) %}
func Delete{{ s.name }}(ctx context.Context, dbe metadb.Execer, {{ delete_by|varname }} {{ delete_by.type|go_type }}) error {
{%~ for f in s.fields %}
{%~ for f in s.fields|filter(f => not has_token(f, 'db_skip')) %}
{%~ if f.type is array %}
if err := Delete{{ f.type.value.name }}Collection(ctx, dbe, {{ delete_by|varname }}); err != nil {
return err
}
{%~ elseif f.type is struct %}
if _, err := Delete{{ f.type.name }}(ctx, dbe, {{ delete_by|varname }}); err != nil {
return err
}
{%~ else %}
if err := Delete{{ f.type.name }}(ctx, dbe, {{ delete_by|varname }}); err != nil {
return err
@ -244,16 +248,10 @@ func Delete{{ s.name }}(ctx context.Context, dbe metadb.Execer, {{ delete_by|var
{% macro root_delete_diff(s) %}
func Delete{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, ids {{ s.name }}RemovedIds) error {
{%~ for f in s.fields %}
{%~ if f.type is array %}
{%~ for f in s.fields|filter(f => not has_token(f, 'db_skip') and f.type is array) %}
if err := Delete{{ f.type.value.name }}CollectionById(ctx, dbe, ids.{{ f|fname }}); err != nil {
return err
}
{%~ else %}
if err := Delete{{ f.type.name }}ById(ctx, dbe, ids.{{ f|fname }}); err != nil {
return err
}
{%~ endif %}
{%~ endfor %}
return nil
}
@ -264,7 +262,7 @@ func Delete{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, ids {{ s.nam
{% set load_by = meta_field(token(s, 'data_root')) %}
func Load{{ s.name }}(ctx context.Context, dbq metadb.Querier, {{ load_by|varname }} {{ load_by.type|go_type }}) ({{ s.name }}, error) {
var s {{ s.name }}
{%~ for f in s.fields %}
{%~ for f in s.fields|filter(f => not has_token(f, 'db_skip')) %}
{%~ if f.type is array %}
{{ f|varname }}, err := Load{{ f.type.value.name }}Collection(ctx, dbq, {{ load_by|varname }})
{%~ else %}