aboutsummaryrefslogtreecommitdiff
path: root/plan_test.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-08-26 21:49:42 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-08-26 21:49:42 +0200
commit50c91a360ac3f42682d998a826087c4bb41d0af4 (patch)
treed96f112c4fe4d0eaac1b018ff568ab7343068e3b /plan_test.go
parentd2118d8e07f9486d8880eee59d5ff83cd8c13c0c (diff)
downloadgo-oblast-50c91a360ac3f42682d998a826087c4bb41d0af4.tar.gz
add ReadOnly plan option
Diffstat (limited to 'plan_test.go')
-rw-r--r--plan_test.go34
1 files changed, 34 insertions, 0 deletions
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,
+ })
})
}