Skip to content

Commit 4f8da00

Browse files
authored
Manual fix for incorrect handling of "calories" (#2018)
* Manual fix for incorrect handling of "calories" * e2e: Add queries * e2e: Regenerate files
1 parent 68f1530 commit 4f8da00

File tree

16 files changed

+176
-0
lines changed

16 files changed

+176
-0
lines changed

internal/endtoend/testdata/inflection/mysql/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/inflection/mysql/go/query.sql.go

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CREATE TABLE campus (id text not null);
22
CREATE TABLE students (id text not null);
33
CREATE TABLE product_meta (id text not null);
4+
CREATE TABLE calories (id text not null);
45

56
/* name: ListCampuses :many */
67
SELECT * FROM campus;
@@ -10,3 +11,6 @@ SELECT * FROM students;
1011

1112
/* name: ListMetadata :many */
1213
SELECT * FROM product_meta;
14+
15+
/* name: ListCalories :many */
16+
SELECT * FROM calories;

internal/endtoend/testdata/inflection/postgresql/pgx/v4/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/inflection/postgresql/pgx/v4/go/query.sql.go

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

internal/endtoend/testdata/inflection/postgresql/pgx/v4/query.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CREATE TABLE campus (id text not null);
22
CREATE TABLE students (id text not null);
33
CREATE TABLE product_meta (id text not null);
4+
CREATE TABLE calories (id text not null);
45

56
-- name: ListCampuses :many
67
SELECT * FROM campus;
@@ -10,3 +11,6 @@ SELECT * FROM students;
1011

1112
-- name: ListMetadata :many
1213
SELECT * FROM product_meta;
14+
15+
-- name: ListCalories :many
16+
SELECT * FROM calories;

internal/endtoend/testdata/inflection/postgresql/pgx/v5/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/inflection/postgresql/pgx/v5/go/query.sql.go

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

internal/endtoend/testdata/inflection/postgresql/pgx/v5/query.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CREATE TABLE campus (id text not null);
22
CREATE TABLE students (id text not null);
33
CREATE TABLE product_meta (id text not null);
4+
CREATE TABLE calories (id text not null);
45

56
-- name: ListCampuses :many
67
SELECT * FROM campus;
@@ -10,3 +11,6 @@ SELECT * FROM students;
1011

1112
-- name: ListMetadata :many
1213
SELECT * FROM product_meta;
14+
15+
-- name: ListCalories :many
16+
SELECT * FROM calories;

internal/endtoend/testdata/inflection/postgresql/stdlib/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/inflection/postgresql/stdlib/go/query.sql.go

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

internal/endtoend/testdata/inflection/postgresql/stdlib/query.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CREATE TABLE campus (id text not null);
22
CREATE TABLE students (id text not null);
33
CREATE TABLE product_meta (id text not null);
4+
CREATE TABLE calories (id text not null);
45

56
-- name: ListCampuses :many
67
SELECT * FROM campus;
@@ -10,3 +11,6 @@ SELECT * FROM students;
1011

1112
-- name: ListMetadata :many
1213
SELECT * FROM product_meta;
14+
15+
-- name: ListCalories :many
16+
SELECT * FROM calories;

internal/endtoend/testdata/inflection/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/inflection/sqlite/go/query.sql.go

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CREATE TABLE campus (id text not null);
22
CREATE TABLE students (id text not null);
33
CREATE TABLE product_meta (id text not null);
4+
CREATE TABLE calories (id text not null);
45

56
/* name: ListCampuses :many */
67
SELECT * FROM campus;
@@ -10,3 +11,6 @@ SELECT * FROM students;
1011

1112
/* name: ListMetadata :many */
1213
SELECT * FROM product_meta;
14+
15+
/* name: ListCalories :many */
16+
SELECT * FROM calories;

internal/inflection/singular.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@ func Singular(s SingularParams) string {
3232
if strings.ToLower(s.Name) == "meta" {
3333
return s.Name
3434
}
35+
// Manual fix for incorrect handling of "calories"
36+
//
37+
// https://github.com/kyleconroy/sqlc/issues/2017
38+
// https://github.com/jinzhu/inflection/issues/23
39+
if strings.ToLower(s.Name) == "calories" {
40+
return "calorie"
41+
}
3542
return upstream.Singular(s.Name)
3643
}

0 commit comments

Comments
 (0)