Skip to content

Commit 837d7c9

Browse files
authored
Coerce SQLite JSONB output regardless of type casing (#4385)
1 parent 244a90b commit 837d7c9

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

internal/compiler/selector.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package compiler
22

3+
import "strings"
4+
35
// selector is an interface used by a compiler for generating expressions for
46
// output columns in a `SELECT ...` or `RETURNING ...` statement.
57
//
@@ -39,7 +41,7 @@ func (s *sqliteSelector) ColumnExpr(name string, column *Column) string {
3941
// outside of the database itself. For jsonb columns in SQLite, wrap values
4042
// in `json(col)` to coerce the internal binary format to JSON parsable by
4143
// the user-space application.
42-
if column.DataType == "jsonb" {
44+
if strings.EqualFold(column.DataType, "jsonb") {
4345
return "json(" + name + ")"
4446
}
4547
return name

internal/endtoend/testdata/jsonb/sqlite/go/models.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/jsonb/sqlite/go/query.sql.go

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/jsonb/sqlite/query.sql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ INSERT INTO foo (
33
a,
44
b,
55
c,
6-
d
6+
d,
7+
e,
8+
f,
9+
g,
10+
h
711
) VALUES (
812
@a,
913
@b,
1014
@c,
11-
@d
15+
@d,
16+
@e,
17+
@f,
18+
@g,
19+
@h
1220
) RETURNING *;
1321

1422
-- name: SelectFoo :exec

internal/endtoend/testdata/jsonb/sqlite/schema.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ CREATE TABLE foo (
22
a json not null,
33
b jsonb not null,
44
c json,
5-
d jsonb
5+
d jsonb,
6+
e JSON not null,
7+
f JSONB not null,
8+
g JSON,
9+
h JSONB
610
);
711

0 commit comments

Comments
 (0)