From 50c91a360ac3f42682d998a826087c4bb41d0af4 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Wed, 26 Aug 2026 21:49:42 +0200 Subject: add ReadOnly plan option --- plan_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'plan_test.go') diff --git a/plan_test.go b/plan_test.go index 4338865..3247928 100644 --- a/plan_test.go +++ b/plan_test.go @@ -100,6 +100,7 @@ func TestQueryConstructionBasic(t *testing.T) { } t.Run("MariaDBDialect", func(t *testing.T) { + opts.ReadOnly = false p, err := buildPlan(reflect.TypeFor[record](), MariaDBDialect(), opts) if err != nil { t.Error(err) @@ -123,9 +124,20 @@ func TestQueryConstructionBasic(t *testing.T) { ArgumentIndexes: [][]int{{0}}, }, }) + + opts.ReadOnly = true + p2, err := buildPlan(reflect.TypeFor[record](), MariaDBDialect(), opts) + if err != nil { + t.Error(err) + } + assert.Equal(t, onlyQueryPlans(p2), plan{ + ReadOnly: true, + Select: p.Select, + }) }) t.Run("PostgresDialect", func(t *testing.T) { + opts.ReadOnly = false p, err := buildPlan(reflect.TypeFor[record](), PostgresDialect(), opts) if err != nil { t.Error(err) @@ -150,9 +162,21 @@ func TestQueryConstructionBasic(t *testing.T) { ArgumentIndexes: [][]int{{0}}, }, }) + + opts.ReadOnly = true + p2, err := buildPlan(reflect.TypeFor[record](), PostgresDialect(), opts) + if err != nil { + t.Error(err) + } + assert.Equal(t, onlyQueryPlans(p2), plan{ + InsertUsesQueryRow: true, + ReadOnly: true, + Select: p.Select, + }) }) t.Run("SqliteDialect", func(t *testing.T) { + opts.ReadOnly = false p, err := buildPlan(reflect.TypeFor[record](), SqliteDialect(), opts) if err != nil { t.Error(err) @@ -176,6 +200,16 @@ func TestQueryConstructionBasic(t *testing.T) { ArgumentIndexes: [][]int{{0}}, }, }) + + opts.ReadOnly = true + p2, err := buildPlan(reflect.TypeFor[record](), SqliteDialect(), opts) + if err != nil { + t.Error(err) + } + assert.Equal(t, onlyQueryPlans(p2), plan{ + ReadOnly: true, + Select: p.Select, + }) }) } -- cgit v1.3.1