Simplify construction of new expressions.

Fixes: IS_NOT_NULL() does not always add enough parentheses to the compiled SQL #500
This commit is contained in:
go-jet 2026-02-02 13:18:19 +01:00
parent 95224a793f
commit 4995a90483
26 changed files with 466 additions and 543 deletions

View file

@ -2,6 +2,10 @@ package sqlite
import (
"encoding/hex"
"strings"
"testing"
"time"
"github.com/go-jet/jet/v2/internal/testutils"
"github.com/go-jet/jet/v2/internal/utils/ptr"
. "github.com/go-jet/jet/v2/sqlite"
@ -12,9 +16,6 @@ import (
"github.com/google/uuid"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
"strings"
"testing"
"time"
)
func TestAllTypes(t *testing.T) {
@ -232,8 +233,8 @@ func TestExpressionOperators(t *testing.T) {
).LIMIT(2)
testutils.AssertStatementSql(t, query, strings.Replace(`
SELECT all_types.integer IS NULL AS "result.is_null",
all_types.date_ptr IS NOT NULL AS "result.is_not_null",
SELECT (all_types.integer IS NULL) AS "result.is_null",
(all_types.date_ptr IS NOT NULL) AS "result.is_not_null",
(all_types.small_int_ptr IN (?, ?)) AS "result.in",
(all_types.small_int_ptr IN ((
SELECT all_types.integer AS "all_types.integer"
@ -299,12 +300,12 @@ SELECT (all_types.boolean = all_types.boolean_ptr) AS "EQ1",
(all_types.boolean IS NOT ?) AS "distinct2",
(all_types.boolean IS all_types.boolean_ptr) AS "not_distinct_1",
(all_types.boolean IS ?) AS "NOTDISTINCT2",
all_types.boolean IS TRUE AS "ISTRUE",
all_types.boolean IS NOT TRUE AS "isnottrue",
all_types.boolean IS FALSE AS "is_False",
all_types.boolean IS NOT FALSE AS "is not false",
all_types.boolean IS NULL AS "is unknown",
all_types.boolean IS NOT NULL AS "is_not_unknown",
(all_types.boolean IS TRUE) AS "ISTRUE",
(all_types.boolean IS NOT TRUE) AS "isnottrue",
(all_types.boolean IS FALSE) AS "is_False",
(all_types.boolean IS NOT FALSE) AS "is not false",
(all_types.boolean IS NULL) AS "is unknown",
(all_types.boolean IS NOT NULL) AS "is_not_unknown",
((all_types.boolean AND all_types.boolean) = (all_types.boolean AND all_types.boolean)) AS "complex1",
((all_types.boolean OR all_types.boolean) = (all_types.boolean AND all_types.boolean)) AS "complex2"
FROM all_types;

View file

@ -2,11 +2,12 @@ package sqlite
import (
"context"
"testing"
"time"
"github.com/go-jet/jet/v2/qrm"
model2 "github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/sakila/model"
"github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/sakila/table"
"testing"
"time"
"github.com/go-jet/jet/v2/internal/testutils"
. "github.com/go-jet/jet/v2/sqlite"
@ -156,7 +157,7 @@ RETURNING link.id AS "link.id",
(link.id + ?) AS "dest.binary_operator",
CAST(link.id AS TEXT) AS "dest.cast_operator",
(link.name LIKE ?) AS "dest.like_operator",
link.description IS NULL AS "dest.is_null",
(link.description IS NULL) AS "dest.is_null",
(CASE link.name WHEN ? THEN ? WHEN ? THEN ? ELSE ? END) AS "dest.case_operator";
`
testutils.AssertStatementSql(t, stmt, expectedSQL, int32(20), "http://www.duckduckgo.com", "DuckDuckGo", nil, int32(20),