diff --git a/internal/endtoend/testdata/inflection/mysql/go/models.go b/internal/endtoend/testdata/inflection/mysql/go/models.go index cc60f36582..1fa48e00f3 100644 --- a/internal/endtoend/testdata/inflection/mysql/go/models.go +++ b/internal/endtoend/testdata/inflection/mysql/go/models.go @@ -12,6 +12,10 @@ type Campus struct { ID string } +type ProductMetadatum struct { + ID string +} + type ProductMetum struct { ID string } diff --git a/internal/endtoend/testdata/inflection/mysql/go/query.sql.go b/internal/endtoend/testdata/inflection/mysql/go/query.sql.go index f6282cceed..c33eea852e 100644 --- a/internal/endtoend/testdata/inflection/mysql/go/query.sql.go +++ b/internal/endtoend/testdata/inflection/mysql/go/query.sql.go @@ -9,6 +9,33 @@ import ( "context" ) +const getProductMetadata = `-- name: GetProductMetadata :many +SELECT id FROM product_metadata +` + +func (q *Queries) GetProductMetadata(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, getProductMetadata) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const listCalories = `-- name: ListCalories :many SELECT id FROM calories ` diff --git a/internal/endtoend/testdata/inflection/mysql/query.sql b/internal/endtoend/testdata/inflection/mysql/query.sql index e3917086b9..74e1aaf8c3 100644 --- a/internal/endtoend/testdata/inflection/mysql/query.sql +++ b/internal/endtoend/testdata/inflection/mysql/query.sql @@ -9,3 +9,6 @@ SELECT * FROM product_meta; /* name: ListCalories :many */ SELECT * FROM calories; + +/* name: GetProductMetadata :many */ +SELECT * FROM product_metadata; \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/mysql/schema.sql b/internal/endtoend/testdata/inflection/mysql/schema.sql index b0d88c8695..f7d5c7c2a5 100644 --- a/internal/endtoend/testdata/inflection/mysql/schema.sql +++ b/internal/endtoend/testdata/inflection/mysql/schema.sql @@ -2,4 +2,4 @@ CREATE TABLE campus (id text not null); CREATE TABLE students (id text not null); CREATE TABLE product_meta (id text not null); CREATE TABLE calories (id text not null); - +CREATE TABLE product_metadata (id text not null); diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/models.go b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/models.go index cc60f36582..1fa48e00f3 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/models.go +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/models.go @@ -12,6 +12,10 @@ type Campus struct { ID string } +type ProductMetadatum struct { + ID string +} + type ProductMetum struct { ID string } diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/query.sql.go b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/query.sql.go index 2791144914..31a5440758 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/query.sql.go +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/go/query.sql.go @@ -9,6 +9,30 @@ import ( "context" ) +const getProductMetadata = `-- name: GetProductMetadata :many +SELECT id FROM product_metadata +` + +func (q *Queries) GetProductMetadata(ctx context.Context) ([]string, error) { + rows, err := q.db.Query(ctx, getProductMetadata) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const listCalories = `-- name: ListCalories :many SELECT id FROM calories ` diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/query.sql b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/query.sql index 6e2828d458..abc0da2ef2 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/query.sql +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/query.sql @@ -9,3 +9,6 @@ SELECT * FROM product_meta; -- name: ListCalories :many SELECT * FROM calories; + +-- name: GetProductMetadata :many +SELECT * FROM product_metadata; \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/schema.sql b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/schema.sql index b0d88c8695..ad17ad7427 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v4/schema.sql +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v4/schema.sql @@ -2,4 +2,4 @@ CREATE TABLE campus (id text not null); CREATE TABLE students (id text not null); CREATE TABLE product_meta (id text not null); CREATE TABLE calories (id text not null); - +CREATE TABLE product_metadata (id text not null); \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/models.go b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/models.go index cc60f36582..1fa48e00f3 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/models.go +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/models.go @@ -12,6 +12,10 @@ type Campus struct { ID string } +type ProductMetadatum struct { + ID string +} + type ProductMetum struct { ID string } diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/query.sql.go b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/query.sql.go index 2791144914..31a5440758 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/query.sql.go +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/go/query.sql.go @@ -9,6 +9,30 @@ import ( "context" ) +const getProductMetadata = `-- name: GetProductMetadata :many +SELECT id FROM product_metadata +` + +func (q *Queries) GetProductMetadata(ctx context.Context) ([]string, error) { + rows, err := q.db.Query(ctx, getProductMetadata) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const listCalories = `-- name: ListCalories :many SELECT id FROM calories ` diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/query.sql b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/query.sql index 6e2828d458..abc0da2ef2 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/query.sql +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/query.sql @@ -9,3 +9,6 @@ SELECT * FROM product_meta; -- name: ListCalories :many SELECT * FROM calories; + +-- name: GetProductMetadata :many +SELECT * FROM product_metadata; \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/schema.sql b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/schema.sql index b0d88c8695..ad17ad7427 100644 --- a/internal/endtoend/testdata/inflection/postgresql/pgx/v5/schema.sql +++ b/internal/endtoend/testdata/inflection/postgresql/pgx/v5/schema.sql @@ -2,4 +2,4 @@ CREATE TABLE campus (id text not null); CREATE TABLE students (id text not null); CREATE TABLE product_meta (id text not null); CREATE TABLE calories (id text not null); - +CREATE TABLE product_metadata (id text not null); \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/postgresql/stdlib/go/models.go b/internal/endtoend/testdata/inflection/postgresql/stdlib/go/models.go index cc60f36582..1fa48e00f3 100644 --- a/internal/endtoend/testdata/inflection/postgresql/stdlib/go/models.go +++ b/internal/endtoend/testdata/inflection/postgresql/stdlib/go/models.go @@ -12,6 +12,10 @@ type Campus struct { ID string } +type ProductMetadatum struct { + ID string +} + type ProductMetum struct { ID string } diff --git a/internal/endtoend/testdata/inflection/postgresql/stdlib/go/query.sql.go b/internal/endtoend/testdata/inflection/postgresql/stdlib/go/query.sql.go index f6282cceed..c33eea852e 100644 --- a/internal/endtoend/testdata/inflection/postgresql/stdlib/go/query.sql.go +++ b/internal/endtoend/testdata/inflection/postgresql/stdlib/go/query.sql.go @@ -9,6 +9,33 @@ import ( "context" ) +const getProductMetadata = `-- name: GetProductMetadata :many +SELECT id FROM product_metadata +` + +func (q *Queries) GetProductMetadata(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, getProductMetadata) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const listCalories = `-- name: ListCalories :many SELECT id FROM calories ` diff --git a/internal/endtoend/testdata/inflection/postgresql/stdlib/query.sql b/internal/endtoend/testdata/inflection/postgresql/stdlib/query.sql index 6e2828d458..abc0da2ef2 100644 --- a/internal/endtoend/testdata/inflection/postgresql/stdlib/query.sql +++ b/internal/endtoend/testdata/inflection/postgresql/stdlib/query.sql @@ -9,3 +9,6 @@ SELECT * FROM product_meta; -- name: ListCalories :many SELECT * FROM calories; + +-- name: GetProductMetadata :many +SELECT * FROM product_metadata; \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/postgresql/stdlib/schema.sql b/internal/endtoend/testdata/inflection/postgresql/stdlib/schema.sql index b0d88c8695..ad17ad7427 100644 --- a/internal/endtoend/testdata/inflection/postgresql/stdlib/schema.sql +++ b/internal/endtoend/testdata/inflection/postgresql/stdlib/schema.sql @@ -2,4 +2,4 @@ CREATE TABLE campus (id text not null); CREATE TABLE students (id text not null); CREATE TABLE product_meta (id text not null); CREATE TABLE calories (id text not null); - +CREATE TABLE product_metadata (id text not null); \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/sqlite/go/models.go b/internal/endtoend/testdata/inflection/sqlite/go/models.go index cc60f36582..1fa48e00f3 100644 --- a/internal/endtoend/testdata/inflection/sqlite/go/models.go +++ b/internal/endtoend/testdata/inflection/sqlite/go/models.go @@ -12,6 +12,10 @@ type Campus struct { ID string } +type ProductMetadatum struct { + ID string +} + type ProductMetum struct { ID string } diff --git a/internal/endtoend/testdata/inflection/sqlite/go/query.sql.go b/internal/endtoend/testdata/inflection/sqlite/go/query.sql.go index f6282cceed..c33eea852e 100644 --- a/internal/endtoend/testdata/inflection/sqlite/go/query.sql.go +++ b/internal/endtoend/testdata/inflection/sqlite/go/query.sql.go @@ -9,6 +9,33 @@ import ( "context" ) +const getProductMetadata = `-- name: GetProductMetadata :many +SELECT id FROM product_metadata +` + +func (q *Queries) GetProductMetadata(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, getProductMetadata) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const listCalories = `-- name: ListCalories :many SELECT id FROM calories ` diff --git a/internal/endtoend/testdata/inflection/sqlite/query.sql b/internal/endtoend/testdata/inflection/sqlite/query.sql index e3917086b9..74e1aaf8c3 100644 --- a/internal/endtoend/testdata/inflection/sqlite/query.sql +++ b/internal/endtoend/testdata/inflection/sqlite/query.sql @@ -9,3 +9,6 @@ SELECT * FROM product_meta; /* name: ListCalories :many */ SELECT * FROM calories; + +/* name: GetProductMetadata :many */ +SELECT * FROM product_metadata; \ No newline at end of file diff --git a/internal/endtoend/testdata/inflection/sqlite/schema.sql b/internal/endtoend/testdata/inflection/sqlite/schema.sql index b0d88c8695..ad17ad7427 100644 --- a/internal/endtoend/testdata/inflection/sqlite/schema.sql +++ b/internal/endtoend/testdata/inflection/sqlite/schema.sql @@ -2,4 +2,4 @@ CREATE TABLE campus (id text not null); CREATE TABLE students (id text not null); CREATE TABLE product_meta (id text not null); CREATE TABLE calories (id text not null); - +CREATE TABLE product_metadata (id text not null); \ No newline at end of file diff --git a/internal/inflection/singular.go b/internal/inflection/singular.go index edac927603..64e042a6ab 100644 --- a/internal/inflection/singular.go +++ b/internal/inflection/singular.go @@ -43,5 +43,10 @@ func Singular(s SingularParams) string { if strings.ToLower(s.Name) == "waves" { return "wave" } + + if strings.ToLower(s.Name) == "metadata" { + return "metadata" + } + return upstream.Singular(s.Name) }