Skip to content

Commit 4e06d27

Browse files
committed
Regenerate examples with type-only SQL import
1 parent 58ddc81 commit 4e06d27

4 files changed

Lines changed: 43 additions & 25 deletions

File tree

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

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

3-
import { SQL } from "bun";
3+
import type { SQL } from "bun";
44

55
export const getAuthorQuery = `-- name: GetAuthor :one
66
SELECT id, name, bio FROM authors
77
WHERE id = $1 LIMIT 1`;
88

99
export interface GetAuthorArgs {
10-
id: string;
10+
id: number;
1111
}
1212

1313
export interface GetAuthorRow {
14-
id: string;
14+
id: number;
1515
name: string;
1616
bio: string | null;
1717
}
1818

19+
export type GetAuthorRowValues = [
20+
number,
21+
string,
22+
string | null
23+
];
24+
1925
export async function getAuthor(sql: SQL, args: GetAuthorArgs): Promise<GetAuthorRow | null> {
20-
const rows = await sql.unsafe(getAuthorQuery, [args.id]).values();
26+
const rows = await sql.unsafe(getAuthorQuery, [args.id]).values() as GetAuthorRowValues[];
2127
if (rows.length !== 1) {
2228
return null;
2329
}
@@ -26,7 +32,7 @@ export async function getAuthor(sql: SQL, args: GetAuthorArgs): Promise<GetAutho
2632
return null;
2733
}
2834
return {
29-
id: row[0],
35+
id: Number(row[0]),
3036
name: row[1],
3137
bio: row[2]
3238
};
@@ -37,14 +43,20 @@ SELECT id, name, bio FROM authors
3743
ORDER BY name`;
3844

3945
export interface ListAuthorsRow {
40-
id: string;
46+
id: number;
4147
name: string;
4248
bio: string | null;
4349
}
4450

51+
export type ListAuthorsRowValues = [
52+
number,
53+
string,
54+
string | null
55+
];
56+
4557
export async function listAuthors(sql: SQL): Promise<ListAuthorsRow[]> {
46-
return (await sql.unsafe(listAuthorsQuery, []).values()).map(row => ({
47-
id: row[0],
58+
return (await sql.unsafe(listAuthorsQuery, []).values() as ListAuthorsRowValues[]).map(row => ({
59+
id: Number(row[0]),
4860
name: row[1],
4961
bio: row[2]
5062
}));
@@ -64,13 +76,19 @@ export interface CreateAuthorArgs {
6476
}
6577

6678
export interface CreateAuthorRow {
67-
id: string;
79+
id: number;
6880
name: string;
6981
bio: string | null;
7082
}
7183

84+
export type CreateAuthorRowValues = [
85+
number,
86+
string,
87+
string | null
88+
];
89+
7290
export async function createAuthor(sql: SQL, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> {
73-
const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]).values();
91+
const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]).values() as CreateAuthorRowValues[];
7492
if (rows.length !== 1) {
7593
return null;
7694
}
@@ -79,7 +97,7 @@ export async function createAuthor(sql: SQL, args: CreateAuthorArgs): Promise<Cr
7997
return null;
8098
}
8199
return {
82-
id: row[0],
100+
id: Number(row[0]),
83101
name: row[1],
84102
bio: row[2]
85103
};
@@ -90,7 +108,7 @@ DELETE FROM authors
90108
WHERE id = $1`;
91109

92110
export interface DeleteAuthorArgs {
93-
id: string;
111+
id: number;
94112
}
95113

96114
export async function deleteAuthor(sql: SQL, args: DeleteAuthorArgs): Promise<void> {

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

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

3-
import { SQL } from "bun";
3+
import type { SQL } from "bun";
44

55
export const getAuthorQuery = `-- name: GetAuthor :one
66
SELECT id, name, bio FROM authors

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ SELECT id, name, bio FROM authors
99
WHERE id = ? LIMIT 1`;
1010

1111
export interface GetAuthorArgs {
12-
id: string;
12+
id: number;
1313
}
1414

1515
export interface GetAuthorRow {
16-
id: string;
16+
id: number;
1717
name: string;
1818
bio: string | null;
1919
}
2020

2121
export type GetAuthorRowValues = [
22-
string,
22+
number,
2323
string,
2424
string | null
2525
];
@@ -46,13 +46,13 @@ SELECT id, name, bio FROM authors
4646
ORDER BY name`;
4747

4848
export interface ListAuthorsRow {
49-
id: string;
49+
id: number;
5050
name: string;
5151
bio: string | null;
5252
}
5353

5454
export type ListAuthorsRowValues = [
55-
string,
55+
number,
5656
string,
5757
string | null
5858
];
@@ -116,7 +116,7 @@ DELETE FROM authors
116116
WHERE id = ?`;
117117

118118
export interface DeleteAuthorArgs {
119-
id: string;
119+
id: number;
120120
}
121121

122122
export async function deleteAuthor(client: Client, args: DeleteAuthorArgs): Promise<void> {
@@ -139,8 +139,8 @@ export interface TestRow {
139139
cMediumint: number | null;
140140
cInt: number | null;
141141
cInteger: number | null;
142-
cBigint: string | null;
143-
cSerial: string;
142+
cBigint: number | null;
143+
cSerial: number;
144144
cDecimal: string | null;
145145
cDec: string | null;
146146
cNumeric: string | null;
@@ -179,8 +179,8 @@ export type TestRowValues = [
179179
number | null,
180180
number | null,
181181
number | null,
182-
string | null,
183-
string,
182+
number | null,
183+
number,
184184
string | null,
185185
string | null,
186186
string | null,

examples/sqlc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ version: "2"
22
plugins:
33
- name: ts
44
wasm:
5-
url: https://downloads.sqlc.dev/plugin/sqlc-gen-typescript_0.1.3.wasm
6-
sha256: 287df8f6cc06377d67ad5ba02c9e0f00c585509881434d15ea8bd9fc751a9368
5+
url: https://github.com/pagerguild/sqlc-gen-typescript/releases/download/v0.2.7/sqlc-gen-typescript.wasm
6+
sha256: e767b29b6d40e53563be95ebaf6eb7e0964d72cfeebc36167ba00a3bc8afba92
77
sql:
88
- schema: "authors/postgresql/schema.sql"
99
queries: "authors/postgresql/query.sql"

0 commit comments

Comments
 (0)