Skip to content

Commit d543de1

Browse files
committed
fix: do not make fields for non-embeds singular
1 parent f57b44d commit d543de1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/drivers/postgres.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,11 @@ export class Driver {
477477
return factory.createObjectLiteralExpression(
478478
columns.map((col, i) =>
479479
factory.createPropertyAssignment(
480-
factory.createIdentifier(singularize(colName(i, col))),
480+
factory.createIdentifier(
481+
embeds.has(col.name)
482+
? singularize(colName(i, col))
483+
: colName(i, col),
484+
),
481485
!embeds.has(col.name)
482486
? this.buildColumnAccessExpression(col, "row", i)
483487
: factory.createObjectLiteralExpression(

test/cases/embed.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ await prepare(sql`
66
SELECT e.*, sqlc.embed(a) FROM emails e
77
join authors a on a.name = 'John Doe'
88
limit 1;
9+
10+
-- name: AuthorExists :one
11+
SELECT 1::int as noPrimitiveReturn, exists(select 1 from authors where name = 'John Doe') as exists;
912
`);
1013

1114
describe("sqlc.embed", () => {
@@ -21,4 +24,10 @@ describe("sqlc.embed", () => {
2124
born: new Date("1990-02-09"),
2225
});
2326
});
27+
28+
it("only singularizes fields for embeds", async () => {
29+
const result = await gen().authorExists(db);
30+
console.log(result);
31+
expect(result.exists).toBe(true);
32+
});
2433
});

0 commit comments

Comments
 (0)