Skip to content

Commit 827055e

Browse files
authored
Apply upstream PR #58: Add driver for native Bun SQL and SQLite (#1)
This adds native Bun SQL support using Bun's built-in PostgreSQL API (since Bun 1.2). No external npm dependencies required for PostgreSQL when using bun-sql driver. Upstream PR: sqlc-dev/sqlc-gen-typescript#58 Author: davisriedel
1 parent 395a0ba commit 827055e

File tree

21 files changed

+1960
-11
lines changed

21 files changed

+1960
-11
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sql:
2626
2727
## Supported engines and drivers
2828
29-
- PostgreSQL via [pg](https://www.npmjs.com/package/pg) or [postgres](https://www.npmjs.com/package/postgres).
29+
- PostgreSQL via [pg](https://www.npmjs.com/package/pg), [postgres](https://www.npmjs.com/package/postgres) or [Bun SQL](https://bun.sh/docs/api/sql).
3030
- MySQL via [mysql2](https://www.npmjs.com/package/mysql2).
3131
- SQLite via [sqlite3](https://www.npmjs.com/package/better-sqlite3).
3232
@@ -291,6 +291,26 @@ sql:
291291
driver: postgres # npm package name
292292
```
293293

294+
### PostgreSQL and Bun SQL
295+
296+
```yaml
297+
version: '2'
298+
plugins:
299+
- name: ts
300+
wasm:
301+
url: https://downloads.sqlc.dev/plugin/sqlc-gen-typescript_0.1.4.wasm
302+
sha256: 9b2f4eca095a3ba1f0f5e971e371ae52f991396efdb63728fc3e8df92c31ff5f
303+
sql:
304+
- schema: "schema.sql"
305+
queries: "query.sql"
306+
engine: postgresql
307+
codegen:
308+
- out: db
309+
plugin: ts
310+
options:
311+
runtime: bun
312+
driver: bun-sql # to use native SQL library of Bun 1.2
313+
```
294314

295315
### MySQL and mysql2
296316

@@ -334,6 +354,27 @@ sql:
334354
driver: better-sqlite3 # npm package name
335355
```
336356

357+
### SQLite and Bun SQLite
358+
359+
```yaml
360+
version: '2'
361+
plugins:
362+
- name: ts
363+
wasm:
364+
url: https://downloads.sqlc.dev/plugin/sqlc-gen-typescript_0.1.4.wasm
365+
sha256: 9b2f4eca095a3ba1f0f5e971e371ae52f991396efdb63728fc3e8df92c31ff5f
366+
sql:
367+
- schema: "schema.sql"
368+
queries: "query.sql"
369+
engine: sqlite
370+
codegen:
371+
- out: db
372+
plugin: ts
373+
options:
374+
runtime: bun
375+
driver: bun-sqlite # to use native SQLite library of Bun
376+
```
377+
337378
## Development
338379

339380
If you want to build and test sqlc-gen-typescript locally, follow these steps:
@@ -390,4 +431,4 @@ Check the `Makefile` for details.
390431
```
391432

392433
For more details on sqlc development, refer to the sqlc core development guide. This guide provides additional information on setting up and working with sqlc in general, which may be useful for contributors to this project.
393-
https://docs.sqlc.dev/en/latest/guides/development.html
434+
https://docs.sqlc.dev/en/latest/guides/development.html

examples/bun-sql/.gitignore

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
15+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
16+
17+
# Runtime data
18+
19+
pids
20+
_.pid
21+
_.seed
22+
\*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
26+
lib-cov
27+
28+
# Coverage directory used by tools like istanbul
29+
30+
coverage
31+
\*.lcov
32+
33+
# nyc test coverage
34+
35+
.nyc_output
36+
37+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
38+
39+
.grunt
40+
41+
# Bower dependency directory (https://bower.io/)
42+
43+
bower_components
44+
45+
# node-waf configuration
46+
47+
.lock-wscript
48+
49+
# Compiled binary addons (https://nodejs.org/api/addons.html)
50+
51+
build/Release
52+
53+
# Dependency directories
54+
55+
node_modules/
56+
jspm_packages/
57+
58+
# Snowpack dependency directory (https://snowpack.dev/)
59+
60+
web_modules/
61+
62+
# TypeScript cache
63+
64+
\*.tsbuildinfo
65+
66+
# Optional npm cache directory
67+
68+
.npm
69+
70+
# Optional eslint cache
71+
72+
.eslintcache
73+
74+
# Optional stylelint cache
75+
76+
.stylelintcache
77+
78+
# Microbundle cache
79+
80+
.rpt2_cache/
81+
.rts2_cache_cjs/
82+
.rts2_cache_es/
83+
.rts2_cache_umd/
84+
85+
# Optional REPL history
86+
87+
.node_repl_history
88+
89+
# Output of 'npm pack'
90+
91+
\*.tgz
92+
93+
# Yarn Integrity file
94+
95+
.yarn-integrity
96+
97+
# dotenv environment variable files
98+
99+
.env
100+
.env.development.local
101+
.env.test.local
102+
.env.production.local
103+
.env.local
104+
105+
# parcel-bundler cache (https://parceljs.org/)
106+
107+
.cache
108+
.parcel-cache
109+
110+
# Next.js build output
111+
112+
.next
113+
out
114+
115+
# Nuxt.js build / generate output
116+
117+
.nuxt
118+
dist
119+
120+
# Gatsby files
121+
122+
.cache/
123+
124+
# Comment in the public line in if your project uses Gatsby and not Next.js
125+
126+
# https://nextjs.org/blog/next-9-1#public-directory-support
127+
128+
# public
129+
130+
# vuepress build output
131+
132+
.vuepress/dist
133+
134+
# vuepress v2.x temp and cache directory
135+
136+
.temp
137+
.cache
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.\*
170+
171+
# IntelliJ based IDEs
172+
.idea
173+
174+
# Finder (MacOS) folder config
175+
.DS_Store
176+

examples/bun-sql/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# bun-postgres
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run src/main.ts
13+
```
14+
15+
This project was created using `bun init` in bun v1.0.11. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

examples/bun-sql/bun.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"lockfileVersion": 1,
3+
"workspaces": {
4+
"": {
5+
"name": "bun-postgres",
6+
"devDependencies": {
7+
"bun-types": "latest",
8+
},
9+
"peerDependencies": {
10+
"typescript": "^5.0.0",
11+
},
12+
},
13+
},
14+
"packages": {
15+
"@types/node": ["@types/node@22.13.4", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg=="],
16+
17+
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
18+
19+
"bun-types": ["bun-types@1.2.2", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-RCbMH5elr9gjgDGDhkTTugA21XtJAy/9jkKe/G3WR2q17VPGhcquf9Sir6uay9iW+7P/BV0CAHA1XlHXMAVKHg=="],
20+
21+
"typescript": ["typescript@5.7.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw=="],
22+
23+
"undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
24+
}
25+
}

examples/bun-sql/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "bun-sql",
3+
"module": "src/main.ts",
4+
"type": "module",
5+
"devDependencies": {
6+
"bun-types": "latest"
7+
},
8+
"peerDependencies": {
9+
"typescript": "^5.0.0"
10+
}
11+
}

0 commit comments

Comments
 (0)