From 8a54c8af963d3f8542a8c90bf37e78603da38715 Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Wed, 14 Jun 2023 14:45:20 +0300 Subject: [PATCH] sqlbuilder added --- tpl/codegen_bundle.twig | 16 ++++++++++++++++ tpl/macros_struct.twig | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tpl/codegen_bundle.twig b/tpl/codegen_bundle.twig index 119a89e..3c07bac 100644 --- a/tpl/codegen_bundle.twig +++ b/tpl/codegen_bundle.twig @@ -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) +} diff --git a/tpl/macros_struct.twig b/tpl/macros_struct.twig index 557e41f..dd99686 100644 --- a/tpl/macros_struct.twig +++ b/tpl/macros_struct.twig @@ -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 %}