From 0182a39113663aded5b9aee60c0983fca9a08ebf Mon Sep 17 00:00:00 2001 From: Stephen Nancekivell Date: Fri, 4 Oct 2024 13:34:04 +1000 Subject: [PATCH] add support for clickhouse settings --- named.go | 2 +- named_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/named.go b/named.go index 6ac44777..fb8e2916 100644 --- a/named.go +++ b/named.go @@ -224,7 +224,7 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) return bound, arglist, nil } -var valuesReg = regexp.MustCompile(`\)\s*(?i)VALUES\s*\(`) +var valuesReg = regexp.MustCompile(`\)\s*(?i)(?:SETTINGS\s+.*)?\s*VALUES\s*\(`) func findMatchingClosingBracketIndex(s string) int { count := 0 diff --git a/named_test.go b/named_test.go index 0ee5b85f..262a911b 100644 --- a/named_test.go +++ b/named_test.go @@ -422,13 +422,19 @@ func TestFixBounds(t *testing.T) { )`, loop: 2, }, + { + name: `clickhouse settings`, + query: `INSERT INTO foo (a,b) settings async_insert=1, wait_for_async_insert=1 VALUES(:a, :b)`, + expect: `INSERT INTO foo (a,b) settings async_insert=1, wait_for_async_insert=1 VALUES(:a, :b),(:a, :b)`, + loop: 2, + }, } for _, tc := range table { t.Run(tc.name, func(t *testing.T) { res := fixBound(tc.query, tc.loop) if res != tc.expect { - t.Errorf("mismatched results") + t.Errorf("mismatched results got %v", res) } }) }