Skip to content

Commit b1336f8

Browse files
authored
fix: Fix type overrides not working with sqlc.slice (#2351)
* Add incorrect test-case that showcases overrides not working with sqlc.slice The new method should've taken a []mysql.ID instead * Fix type overrides not working with sqlc.slice
1 parent 56de602 commit b1336f8

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

internal/codegen/golang/go_type.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func goType(req *plugin.CodeGenRequest, col *plugin.Column) string {
4141
}
4242
sameTable := sdk.Matches(oride, col.Table, req.Catalog.DefaultSchema)
4343
if oride.Column != "" && sdk.MatchString(oride.ColumnName, cname) && sameTable {
44+
if col.IsSqlcSlice {
45+
return "[]" + oride.GoType.TypeName
46+
}
4447
return oride.GoType.TypeName
4548
}
4649
}

internal/endtoend/testdata/sqlc_slice/mysql/go/models.go

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

internal/endtoend/testdata/sqlc_slice/mysql/go/query.sql.go

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

internal/endtoend/testdata/sqlc_slice/mysql/query.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE TABLE foo (id int not null, name text not null, bar text null);
1+
CREATE TABLE foo (id int not null, name text not null, bar text null, mystr text not null);
22

33
/* name: FuncParamIdent :many */
44
SELECT name FROM foo
@@ -20,4 +20,8 @@ WHERE id IN (sqlc.slice(favourites));
2020

2121
/* name: FuncNullable :many */
2222
SELECT bar FROM foo
23-
WHERE id IN (sqlc.slice('favourites'));
23+
WHERE id IN (sqlc.slice('favourites'));
24+
25+
/* name: TypedMyStr :many */
26+
SELECT bar FROM foo
27+
WHERE mystr IN (sqlc.slice(mystr));

internal/endtoend/testdata/sqlc_slice/mysql/sqlc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@
88
"schema": "query.sql",
99
"queries": "query.sql"
1010
}
11+
],
12+
"overrides": [
13+
{
14+
"column": "foo.mystr",
15+
"go_type": "github.com/kyleconroy/sqlc-testdata/mysql.ID"
16+
}
1117
]
1218
}

0 commit comments

Comments
 (0)