Skip to content

Commit 4facc77

Browse files
committed
fix: remove generated tuples
1 parent a2f71b6 commit 4facc77

File tree

9 files changed

+35
-126
lines changed

9 files changed

+35
-126
lines changed

examples/bun-pg/src/db/query_sql.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ export interface GetAuthorRow {
2020
bio: string | null;
2121
}
2222

23-
export type GetAuthorRowValues = [
24-
string,
25-
string,
26-
string | null
27-
];
28-
2923
export async function getAuthor(client: Client, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
3024
const result = await client.query({
3125
text: getAuthorQuery,
@@ -53,12 +47,6 @@ export interface ListAuthorsRow {
5347
bio: string | null;
5448
}
5549

56-
export type ListAuthorsRowValues = [
57-
string,
58-
string,
59-
string | null
60-
];
61-
6250
export async function listAuthors(client: Client): Promise<ListAuthorsRow[]> {
6351
const result = await client.query({
6452
text: listAuthorsQuery,
@@ -93,12 +81,6 @@ export interface CreateAuthorRow {
9381
bio: string | null;
9482
}
9583

96-
export type CreateAuthorRowValues = [
97-
string,
98-
string,
99-
string | null
100-
];
101-
10284
export async function createAuthor(client: Client, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
10385
const result = await client.query({
10486
text: createAuthorQuery,

examples/bun-postgres/src/db/query_sql.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code generated by sqlc. DO NOT EDIT.
22

3-
import type { Sql as SQL } from "postgres";
3+
import type { Sql } from "postgres";
44

55
export const getAuthorQuery = `-- name: GetAuthor :one
66
SELECT id, name, bio FROM authors
@@ -16,13 +16,7 @@ export interface GetAuthorRow {
1616
bio: string | null;
1717
}
1818

19-
export type GetAuthorRowValues = [
20-
number,
21-
string,
22-
string | null
23-
];
24-
25-
export async function getAuthor(sql: SQL, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
19+
export async function getAuthor(sql: Sql, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
2620
const rows = await sql.unsafe(getAuthorQuery, [args.id]) as GetAuthorRow[];
2721
if (rows.length !== 1) {
2822
return null;
@@ -40,13 +34,7 @@ export interface ListAuthorsRow {
4034
bio: string | null;
4135
}
4236

43-
export type ListAuthorsRowValues = [
44-
number,
45-
string,
46-
string | null
47-
];
48-
49-
export async function listAuthors(sql: SQL): Promise<ListAuthorsRow[]> {
37+
export async function listAuthors(sql: Sql): Promise<ListAuthorsRow[]> {
5038
return await sql.unsafe(listAuthorsQuery, []) as ListAuthorsRow[];
5139
}
5240

@@ -69,13 +57,7 @@ export interface CreateAuthorRow {
6957
bio: string | null;
7058
}
7159

72-
export type CreateAuthorRowValues = [
73-
number,
74-
string,
75-
string | null
76-
];
77-
78-
export async function createAuthor(sql: SQL, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
60+
export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
7961
const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]) as CreateAuthorRow[];
8062
if (rows.length !== 1) {
8163
return null;
@@ -91,7 +73,7 @@ export interface DeleteAuthorArgs {
9173
id: number;
9274
}
9375

94-
export async function deleteAuthor(sql: SQL, args: DeleteAuthorArgs): Promise<void> {
76+
export async function deleteAuthor(sql: Sql, args: DeleteAuthorArgs): Promise<void> {
9577
await sql.unsafe(deleteAuthorQuery, [args.id]);
9678
}
9779

examples/bun-sql/src/db/query_sql.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ export interface GetAuthorRow {
1616
bio: string | null;
1717
}
1818

19-
export type GetAuthorRowValues = [
20-
number,
21-
string,
22-
string | null
23-
];
24-
2519
export async function getAuthor(sql: SQL, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
26-
const rows = await sql.unsafe(getAuthorQuery, [args.id]).values() as GetAuthorRowValues[];
20+
const rows = await sql.unsafe(getAuthorQuery, [args.id]).values() as any[];
2721
if (rows.length !== 1) {
2822
return null;
2923
}
@@ -48,14 +42,8 @@ export interface ListAuthorsRow {
4842
bio: string | null;
4943
}
5044

51-
export type ListAuthorsRowValues = [
52-
number,
53-
string,
54-
string | null
55-
];
56-
5745
export async function listAuthors(sql: SQL): Promise<ListAuthorsRow[]> {
58-
return (await sql.unsafe(listAuthorsQuery, []).values() as ListAuthorsRowValues[]).map(row => ({
46+
return (await sql.unsafe(listAuthorsQuery, []).values() as any[]).map((row: any[]) => ({
5947
id: Number(row[0]),
6048
name: row[1],
6149
bio: row[2]
@@ -81,14 +69,8 @@ export interface CreateAuthorRow {
8169
bio: string | null;
8270
}
8371

84-
export type CreateAuthorRowValues = [
85-
number,
86-
string,
87-
string | null
88-
];
89-
9072
export async function createAuthor(sql: SQL, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
91-
const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]).values() as CreateAuthorRowValues[];
73+
const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]).values() as any[];
9274
if (rows.length !== 1) {
9375
return null;
9476
}

examples/node-pg/src/db/query_sql.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ export interface GetAuthorRow {
2020
bio: string | null;
2121
}
2222

23-
export type GetAuthorRowValues = [
24-
string,
25-
string,
26-
string | null
27-
];
28-
2923
export async function getAuthor(client: Client, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
3024
const result = await client.query({
3125
text: getAuthorQuery,
@@ -53,12 +47,6 @@ export interface ListAuthorsRow {
5347
bio: string | null;
5448
}
5549

56-
export type ListAuthorsRowValues = [
57-
string,
58-
string,
59-
string | null
60-
];
61-
6250
export async function listAuthors(client: Client): Promise<ListAuthorsRow[]> {
6351
const result = await client.query({
6452
text: listAuthorsQuery,
@@ -93,12 +81,6 @@ export interface CreateAuthorRow {
9381
bio: string | null;
9482
}
9583

96-
export type CreateAuthorRowValues = [
97-
string,
98-
string,
99-
string | null
100-
];
101-
10284
export async function createAuthor(client: Client, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
10385
const result = await client.query({
10486
text: createAuthorQuery,

examples/node-postgres/src/db/query_sql.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code generated by sqlc. DO NOT EDIT.
22

3-
import type { Sql as SQL } from "postgres";
3+
import type { Sql } from "postgres";
44

55
export const getAuthorQuery = `-- name: GetAuthor :one
66
SELECT id, name, bio FROM authors
@@ -16,13 +16,7 @@ export interface GetAuthorRow {
1616
bio: string | null;
1717
}
1818

19-
export type GetAuthorRowValues = [
20-
number,
21-
string,
22-
string | null
23-
];
24-
25-
export async function getAuthor(sql: SQL, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
19+
export async function getAuthor(sql: Sql, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
2620
const rows = await sql.unsafe(getAuthorQuery, [args.id]) as GetAuthorRow[];
2721
if (rows.length !== 1) {
2822
return null;
@@ -40,13 +34,7 @@ export interface ListAuthorsRow {
4034
bio: string | null;
4135
}
4236

43-
export type ListAuthorsRowValues = [
44-
number,
45-
string,
46-
string | null
47-
];
48-
49-
export async function listAuthors(sql: SQL): Promise<ListAuthorsRow[]> {
37+
export async function listAuthors(sql: Sql): Promise<ListAuthorsRow[]> {
5038
return await sql.unsafe(listAuthorsQuery, []) as ListAuthorsRow[];
5139
}
5240

@@ -69,13 +57,7 @@ export interface CreateAuthorRow {
6957
bio: string | null;
7058
}
7159

72-
export type CreateAuthorRowValues = [
73-
number,
74-
string,
75-
string | null
76-
];
77-
78-
export async function createAuthor(sql: SQL, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
60+
export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
7961
const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]) as CreateAuthorRow[];
8062
if (rows.length !== 1) {
8163
return null;
@@ -91,7 +73,7 @@ export interface DeleteAuthorArgs {
9173
id: number;
9274
}
9375

94-
export async function deleteAuthor(sql: SQL, args: DeleteAuthorArgs): Promise<void> {
76+
export async function deleteAuthor(sql: Sql, args: DeleteAuthorArgs): Promise<void> {
9577
await sql.unsafe(deleteAuthorQuery, [args.id]);
9678
}
9779

src/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from "./gen/plugin/codegen_pb";
2424

2525
import { argName, colName } from "./drivers/utlis";
26-
import { rowValuesDecl } from "./decls";
26+
2727
import { assertUniqueNames } from "./validate";
2828
import { Driver as PgDriver } from "./drivers/pg";
2929
import { Driver as PostgresDriver } from "./drivers/postgres";
@@ -147,7 +147,6 @@ ${query.text}`,
147147
fileName: filename,
148148
}),
149149
);
150-
nodes.push(rowValuesDecl(`${returnIface}Values`, driver, query.columns));
151150
}
152151

153152
switch (query.cmd) {

src/drivers/bun-sql.codegen.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe("bun-sql driver codegen", () => {
4747

4848
const output = print(node);
4949

50-
expect(output).toContain("as ListThingsRowValues[]");
51-
expect(output).toContain(".map(row =>");
50+
expect(output).toContain("values() as any[]");
51+
expect(output).toContain(".map((row: any[]) =>");
5252
});
5353

5454
it("casts values() result to RowValues tuple array for :one", () => {
@@ -74,7 +74,7 @@ describe("bun-sql driver codegen", () => {
7474
);
7575

7676
const output = print(node);
77-
expect(output).toContain("as GetThingRowValues[]");
77+
expect(output).toContain("values() as any[]");
7878
});
7979

8080
it("wraps bigint columns with Number() in :many", () => {
@@ -187,13 +187,13 @@ describe("bun-sql driver codegen", () => {
187187
});
188188

189189
describe("postgres driver codegen", () => {
190-
it("generates correct import statement with alias", () => {
190+
it("generates correct import statement", () => {
191191
const driver = new PostgresDriver();
192192

193193
const preamble = driver.preamble([]);
194194
const output = print(preamble[0]);
195195

196-
expect(output).toContain('import type { Sql as SQL } from "postgres"');
196+
expect(output).toContain('import type { Sql } from "postgres"');
197197
});
198198

199199
it("generates simpler code that casts directly to Row type", () => {

src/drivers/postgres-common.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,7 @@ export class PostgresCommonDriver {
535535
),
536536
),
537537
factory.createArrayTypeNode(
538-
factory.createTypeReferenceNode(
539-
factory.createIdentifier(`${returnIface}Values`),
540-
undefined,
541-
),
538+
factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
542539
),
543540
),
544541
),
@@ -549,7 +546,18 @@ export class PostgresCommonDriver {
549546
factory.createArrowFunction(
550547
undefined,
551548
undefined,
552-
[factory.createParameterDeclaration(undefined, undefined, "row")],
549+
[
550+
factory.createParameterDeclaration(
551+
undefined,
552+
undefined,
553+
"row",
554+
undefined,
555+
factory.createArrayTypeNode(
556+
factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
557+
),
558+
undefined,
559+
),
560+
],
553561
undefined,
554562
factory.createToken(SyntaxKind.EqualsGreaterThanToken),
555563
factory.createObjectLiteralExpression(
@@ -633,10 +641,7 @@ export class PostgresCommonDriver {
633641
),
634642
),
635643
factory.createArrayTypeNode(
636-
factory.createTypeReferenceNode(
637-
factory.createIdentifier(`${returnIface}Values`),
638-
undefined,
639-
),
644+
factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
640645
),
641646
),
642647
),

src/drivers/postgres.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function funcParamsDecl(iface: string | undefined, params: Parameter[]) {
1818
undefined,
1919
factory.createIdentifier("sql"),
2020
undefined,
21-
factory.createTypeReferenceNode(factory.createIdentifier("SQL"), undefined),
21+
factory.createTypeReferenceNode(factory.createIdentifier("Sql"), undefined),
2222
undefined,
2323
),
2424
];
@@ -167,19 +167,14 @@ export class Driver {
167167
}
168168

169169
preamble(_queries: unknown) {
170-
// Import Sql and alias to SQL for consistency with bun-sql generated code
171170
return [
172171
factory.createImportDeclaration(
173172
undefined,
174173
factory.createImportClause(
175174
true, // type-only import
176175
undefined,
177176
factory.createNamedImports([
178-
factory.createImportSpecifier(
179-
false,
180-
factory.createIdentifier("Sql"),
181-
factory.createIdentifier("SQL"),
182-
),
177+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("Sql")),
183178
]),
184179
),
185180
factory.createStringLiteral("postgres"),

0 commit comments

Comments
 (0)