sqlbuilder added

This commit is contained in:
Pavel Merzlyakov 2023-06-14 14:45:20 +03:00
parent 1b4defc4f7
commit 8a54c8af96
2 changed files with 20 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import (
"git.bit5.ru/backend/versioning"
"git.bit5.ru/gomodules/metadb"
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/dialect/mysql"
"github.com/doug-martin/goqu/v9/exp"
"github.com/go-logr/logr"
"github.com/pkg/errors"
@ -177,3 +178,18 @@ func (rctx *RpcContext) SetLogger(logger logr.Logger) {
func (rctx *RpcContext) Logger() logr.Logger {
return rctx.logger
}
const (
goquDialect = "mysql8bit"
)
func init() {
opts := mysql.DialectOptionsV8()
opts.SupportsInsertIgnoreSyntax = false
goqu.RegisterDialect(goquDialect, opts)
}
func SqlBuilder() goqu.DialectWrapper {
return goqu.Dialect(goquDialect)
}

View File

@ -84,7 +84,7 @@ func Save{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ s.name
return err
}
ds := metadb.SqlBuilder().
ds := SqlBuilder().
Insert(goqu.T("{{ table_name }}")).
Cols(
{% for c in insert_columns -%}
@ -140,7 +140,7 @@ func Save{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ s.name
{{ _self.table_delete_diff(_context) }}
func Save{{ s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ s.name }}) error {
ds := metadb.SqlBuilder().
ds := SqlBuilder().
Insert(goqu.T("{{ table_name }}")).
Cols(
{% for f in pkey %}
@ -269,7 +269,7 @@ func Save{{ ctx.s.name }}Collection(ctx context.Context, dbe metadb.Execer, recs
return nil
}
ds := metadb.SqlBuilder().
ds := SqlBuilder().
Insert(goqu.T("{{ ctx.table_name }}")).
Cols(
{%~ for c in ctx.insert_columns %}
@ -471,7 +471,7 @@ func Delete{{ ctx.s.name }}CollectionById(
))
}
ds := metadb.SqlBuilder().
ds := SqlBuilder().
Delete(goqu.T("level_state")).
Where(goqu.L("({{ pkey_values_expr }}) IN ?",
{% for f in ctx.pkey %}