bun-types 1.2.22-canary.20250828T140722 → 1.2.22-canary.20250830T140622
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/api/fetch.md +1 -1
- package/docs/api/spawn.md +1 -1
- package/docs/api/sql.md +357 -10
- package/docs/cli/pm.md +1 -1
- package/docs/cli/publish.md +1 -1
- package/docs/guides/ecosystem/nuxt.md +1 -1
- package/docs/guides/install/add-peer.md +2 -2
- package/docs/guides/install/from-npm-install-to-bun-install.md +1 -1
- package/docs/guides/test/run-tests.md +3 -3
- package/docs/guides/test/snapshot.md +3 -3
- package/docs/guides/test/update-snapshots.md +1 -1
- package/docs/guides/util/version.md +1 -1
- package/docs/installation.md +4 -4
- package/docs/runtime/debugger.md +3 -3
- package/docs/test/dom.md +1 -1
- package/package.json +1 -1
package/docs/api/fetch.md
CHANGED
|
@@ -336,7 +336,7 @@ This will print the request and response headers to your terminal:
|
|
|
336
336
|
```sh
|
|
337
337
|
[fetch] > HTTP/1.1 GET http://example.com/
|
|
338
338
|
[fetch] > Connection: keep-alive
|
|
339
|
-
[fetch] > User-Agent: Bun/1.2.22-canary.
|
|
339
|
+
[fetch] > User-Agent: Bun/1.2.22-canary.20250830T140622
|
|
340
340
|
[fetch] > Accept: */*
|
|
341
341
|
[fetch] > Host: example.com
|
|
342
342
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/api/spawn.md
CHANGED
|
@@ -140,7 +140,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
|
|
|
140
140
|
```ts
|
|
141
141
|
const proc = Bun.spawn(["bun", "--version"]);
|
|
142
142
|
const text = await proc.stdout.text();
|
|
143
|
-
console.log(text); // => "1.2.22-canary.
|
|
143
|
+
console.log(text); // => "1.2.22-canary.20250830T140622\n"
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
Configure the output stream by passing one of the following values to `stdout/stderr`:
|
package/docs/api/sql.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Bun provides native bindings for working with SQL databases through a unified Promise-based API that supports
|
|
1
|
+
Bun provides native bindings for working with SQL databases through a unified Promise-based API that supports PostgreSQL, MySQL, and SQLite. The interface is designed to be simple and performant, using tagged template literals for queries and offering features like connection pooling, transactions, and prepared statements.
|
|
2
2
|
|
|
3
3
|
```ts
|
|
4
4
|
import { sql, SQL } from "bun";
|
|
@@ -10,9 +10,16 @@ const users = await sql`
|
|
|
10
10
|
LIMIT ${10}
|
|
11
11
|
`;
|
|
12
12
|
|
|
13
|
-
// With
|
|
13
|
+
// With MySQL
|
|
14
|
+
const mysql = new SQL("mysql://user:pass@localhost:3306/mydb");
|
|
15
|
+
const mysqlResults = await mysql`
|
|
16
|
+
SELECT * FROM users
|
|
17
|
+
WHERE active = ${true}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
// With SQLite
|
|
14
21
|
const sqlite = new SQL("sqlite://myapp.db");
|
|
15
|
-
const
|
|
22
|
+
const sqliteResults = await sqlite`
|
|
16
23
|
SELECT * FROM users
|
|
17
24
|
WHERE active = ${1}
|
|
18
25
|
`;
|
|
@@ -52,7 +59,7 @@ Bun.SQL provides a unified API for multiple database systems:
|
|
|
52
59
|
|
|
53
60
|
PostgreSQL is used when:
|
|
54
61
|
|
|
55
|
-
- The connection string doesn't match SQLite patterns (it's the fallback adapter)
|
|
62
|
+
- The connection string doesn't match SQLite or MySQL patterns (it's the fallback adapter)
|
|
56
63
|
- The connection string explicitly uses `postgres://` or `postgresql://` protocols
|
|
57
64
|
- No connection string is provided and environment variables point to PostgreSQL
|
|
58
65
|
|
|
@@ -66,9 +73,82 @@ const pg = new SQL("postgres://user:pass@localhost:5432/mydb");
|
|
|
66
73
|
await pg`SELECT ...`;
|
|
67
74
|
```
|
|
68
75
|
|
|
76
|
+
### MySQL
|
|
77
|
+
|
|
78
|
+
MySQL support is built into Bun.SQL, providing the same tagged template literal interface with full compatibility for MySQL 5.7+ and MySQL 8.0+:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { SQL } from "bun";
|
|
82
|
+
|
|
83
|
+
// MySQL connection
|
|
84
|
+
const mysql = new SQL("mysql://user:password@localhost:3306/database");
|
|
85
|
+
const mysql2 = new SQL("mysql2://user:password@localhost:3306/database"); // mysql2 protocol also works
|
|
86
|
+
|
|
87
|
+
// Using options object
|
|
88
|
+
const mysql3 = new SQL({
|
|
89
|
+
adapter: "mysql",
|
|
90
|
+
hostname: "localhost",
|
|
91
|
+
port: 3306,
|
|
92
|
+
database: "myapp",
|
|
93
|
+
username: "dbuser",
|
|
94
|
+
password: "secretpass",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Works with parameters - automatically uses prepared statements
|
|
98
|
+
const users = await mysql`SELECT * FROM users WHERE id = ${userId}`;
|
|
99
|
+
|
|
100
|
+
// Transactions work the same as PostgreSQL
|
|
101
|
+
await mysql.begin(async tx => {
|
|
102
|
+
await tx`INSERT INTO users (name) VALUES (${"Alice"})`;
|
|
103
|
+
await tx`UPDATE accounts SET balance = balance - 100 WHERE user_id = ${userId}`;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Bulk inserts
|
|
107
|
+
const newUsers = [
|
|
108
|
+
{ name: "Alice", email: "alice@example.com" },
|
|
109
|
+
{ name: "Bob", email: "bob@example.com" },
|
|
110
|
+
];
|
|
111
|
+
await mysql`INSERT INTO users ${mysql(newUsers)}`;
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
{% details summary="MySQL Connection String Formats" %}
|
|
115
|
+
|
|
116
|
+
MySQL accepts various URL formats for connection strings:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
// Standard mysql:// protocol
|
|
120
|
+
new SQL("mysql://user:pass@localhost:3306/database");
|
|
121
|
+
new SQL("mysql://user:pass@localhost/database"); // Default port 3306
|
|
122
|
+
|
|
123
|
+
// mysql2:// protocol (compatibility with mysql2 npm package)
|
|
124
|
+
new SQL("mysql2://user:pass@localhost:3306/database");
|
|
125
|
+
|
|
126
|
+
// With query parameters
|
|
127
|
+
new SQL("mysql://user:pass@localhost/db?ssl=true");
|
|
128
|
+
|
|
129
|
+
// Unix socket connection
|
|
130
|
+
new SQL("mysql://user:pass@/database?socket=/var/run/mysqld/mysqld.sock");
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
{% /details %}
|
|
134
|
+
|
|
135
|
+
{% details summary="MySQL-Specific Features" %}
|
|
136
|
+
|
|
137
|
+
MySQL databases support:
|
|
138
|
+
|
|
139
|
+
- **Prepared statements**: Automatically created for parameterized queries with statement caching
|
|
140
|
+
- **Binary protocol**: For better performance with prepared statements and accurate type handling
|
|
141
|
+
- **Multiple result sets**: Support for stored procedures returning multiple result sets
|
|
142
|
+
- **Authentication plugins**: Support for mysql_native_password, caching_sha2_password (MySQL 8.0 default), and sha256_password
|
|
143
|
+
- **SSL/TLS connections**: Configurable SSL modes similar to PostgreSQL
|
|
144
|
+
- **Connection attributes**: Client information sent to server for monitoring
|
|
145
|
+
- **Query pipelining**: Execute multiple prepared statements without waiting for responses
|
|
146
|
+
|
|
147
|
+
{% /details %}
|
|
148
|
+
|
|
69
149
|
### SQLite
|
|
70
150
|
|
|
71
|
-
SQLite support is
|
|
151
|
+
SQLite support is built into Bun.SQL, providing the same tagged template literal interface:
|
|
72
152
|
|
|
73
153
|
```ts
|
|
74
154
|
import { SQL } from "bun";
|
|
@@ -362,7 +442,24 @@ await query;
|
|
|
362
442
|
|
|
363
443
|
### Automatic Database Detection
|
|
364
444
|
|
|
365
|
-
When using `Bun.sql()` without arguments or `new SQL()` with a connection string, the adapter is automatically detected based on the URL format
|
|
445
|
+
When using `Bun.sql()` without arguments or `new SQL()` with a connection string, the adapter is automatically detected based on the URL format:
|
|
446
|
+
|
|
447
|
+
#### MySQL Auto-Detection
|
|
448
|
+
|
|
449
|
+
MySQL is automatically selected when the connection string matches these patterns:
|
|
450
|
+
|
|
451
|
+
- `mysql://...` - MySQL protocol URLs
|
|
452
|
+
- `mysql2://...` - MySQL2 protocol URLs (compatibility alias)
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
// These all use MySQL automatically (no adapter needed)
|
|
456
|
+
const sql1 = new SQL("mysql://user:pass@localhost/mydb");
|
|
457
|
+
const sql2 = new SQL("mysql2://user:pass@localhost:3306/mydb");
|
|
458
|
+
|
|
459
|
+
// Works with DATABASE_URL environment variable
|
|
460
|
+
DATABASE_URL="mysql://user:pass@localhost/mydb" bun run app.js
|
|
461
|
+
DATABASE_URL="mysql2://user:pass@localhost:3306/mydb" bun run app.js
|
|
462
|
+
```
|
|
366
463
|
|
|
367
464
|
#### SQLite Auto-Detection
|
|
368
465
|
|
|
@@ -388,17 +485,42 @@ DATABASE_URL="file://./data/app.db" bun run app.js
|
|
|
388
485
|
|
|
389
486
|
#### PostgreSQL Auto-Detection
|
|
390
487
|
|
|
391
|
-
PostgreSQL is the default for
|
|
488
|
+
PostgreSQL is the default for connection strings that don't match MySQL or SQLite patterns:
|
|
392
489
|
|
|
393
490
|
```bash
|
|
394
491
|
# PostgreSQL is detected for these patterns
|
|
395
492
|
DATABASE_URL="postgres://user:pass@localhost:5432/mydb" bun run app.js
|
|
396
493
|
DATABASE_URL="postgresql://user:pass@localhost:5432/mydb" bun run app.js
|
|
397
494
|
|
|
398
|
-
# Or any URL that doesn't match SQLite patterns
|
|
495
|
+
# Or any URL that doesn't match MySQL or SQLite patterns
|
|
399
496
|
DATABASE_URL="localhost:5432/mydb" bun run app.js
|
|
400
497
|
```
|
|
401
498
|
|
|
499
|
+
### MySQL Environment Variables
|
|
500
|
+
|
|
501
|
+
MySQL connections can be configured via environment variables:
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
# Primary connection URL (checked first)
|
|
505
|
+
MYSQL_URL="mysql://user:pass@localhost:3306/mydb"
|
|
506
|
+
|
|
507
|
+
# Alternative: DATABASE_URL with MySQL protocol
|
|
508
|
+
DATABASE_URL="mysql://user:pass@localhost:3306/mydb"
|
|
509
|
+
DATABASE_URL="mysql2://user:pass@localhost:3306/mydb"
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
If no connection URL is provided, MySQL checks these individual parameters:
|
|
513
|
+
|
|
514
|
+
| Environment Variable | Default Value | Description |
|
|
515
|
+
| ------------------------ | ------------- | -------------------------------- |
|
|
516
|
+
| `MYSQL_HOST` | `localhost` | Database host |
|
|
517
|
+
| `MYSQL_PORT` | `3306` | Database port |
|
|
518
|
+
| `MYSQL_USER` | `root` | Database user |
|
|
519
|
+
| `MYSQL_PASSWORD` | (empty) | Database password |
|
|
520
|
+
| `MYSQL_DATABASE` | `mysql` | Database name |
|
|
521
|
+
| `MYSQL_URL` | (empty) | Primary connection URL for MySQL |
|
|
522
|
+
| `TLS_MYSQL_DATABASE_URL` | (empty) | SSL/TLS-enabled connection URL |
|
|
523
|
+
|
|
402
524
|
### PostgreSQL Environment Variables
|
|
403
525
|
|
|
404
526
|
The following environment variables can be used to define the PostgreSQL connection:
|
|
@@ -456,6 +578,54 @@ The `--sql-preconnect` flag will automatically establish a PostgreSQL connection
|
|
|
456
578
|
|
|
457
579
|
You can configure your database connection manually by passing options to the SQL constructor. Options vary depending on the database adapter:
|
|
458
580
|
|
|
581
|
+
### MySQL Options
|
|
582
|
+
|
|
583
|
+
```ts
|
|
584
|
+
import { SQL } from "bun";
|
|
585
|
+
|
|
586
|
+
const db = new SQL({
|
|
587
|
+
// Required for MySQL when using options object
|
|
588
|
+
adapter: "mysql",
|
|
589
|
+
|
|
590
|
+
// Connection details
|
|
591
|
+
hostname: "localhost",
|
|
592
|
+
port: 3306,
|
|
593
|
+
database: "myapp",
|
|
594
|
+
username: "dbuser",
|
|
595
|
+
password: "secretpass",
|
|
596
|
+
|
|
597
|
+
// Unix socket connection (alternative to hostname/port)
|
|
598
|
+
// socket: "/var/run/mysqld/mysqld.sock",
|
|
599
|
+
|
|
600
|
+
// Connection pool settings
|
|
601
|
+
max: 20, // Maximum connections in pool (default: 10)
|
|
602
|
+
idleTimeout: 30, // Close idle connections after 30s
|
|
603
|
+
maxLifetime: 0, // Connection lifetime in seconds (0 = forever)
|
|
604
|
+
connectionTimeout: 30, // Timeout when establishing new connections
|
|
605
|
+
|
|
606
|
+
// SSL/TLS options
|
|
607
|
+
ssl: "prefer", // or "disable", "require", "verify-ca", "verify-full"
|
|
608
|
+
// tls: {
|
|
609
|
+
// rejectUnauthorized: true,
|
|
610
|
+
// ca: "path/to/ca.pem",
|
|
611
|
+
// key: "path/to/key.pem",
|
|
612
|
+
// cert: "path/to/cert.pem",
|
|
613
|
+
// },
|
|
614
|
+
|
|
615
|
+
// Callbacks
|
|
616
|
+
onconnect: client => {
|
|
617
|
+
console.log("Connected to MySQL");
|
|
618
|
+
},
|
|
619
|
+
onclose: (client, err) => {
|
|
620
|
+
if (err) {
|
|
621
|
+
console.error("MySQL connection error:", err);
|
|
622
|
+
} else {
|
|
623
|
+
console.log("MySQL connection closed");
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
```
|
|
628
|
+
|
|
459
629
|
### PostgreSQL Options
|
|
460
630
|
|
|
461
631
|
```ts
|
|
@@ -979,11 +1149,106 @@ console.log(typeof x, x); // "bigint" 9223372036854777n
|
|
|
979
1149
|
There's still some things we haven't finished yet.
|
|
980
1150
|
|
|
981
1151
|
- Connection preloading via `--db-preconnect` Bun CLI flag
|
|
982
|
-
- MySQL support: [we're working on it](https://github.com/oven-sh/bun/pull/15274)
|
|
983
1152
|
- Column name transforms (e.g. `snake_case` to `camelCase`). This is mostly blocked on a unicode-aware implementation of changing the case in C++ using WebKit's `WTF::String`.
|
|
984
1153
|
- Column type transforms
|
|
985
1154
|
|
|
986
|
-
|
|
1155
|
+
## Database-Specific Features
|
|
1156
|
+
|
|
1157
|
+
#### Authentication Methods
|
|
1158
|
+
|
|
1159
|
+
MySQL supports multiple authentication plugins that are automatically negotiated:
|
|
1160
|
+
|
|
1161
|
+
- **`mysql_native_password`** - Traditional MySQL authentication, widely compatible
|
|
1162
|
+
- **`caching_sha2_password`** - Default in MySQL 8.0+, more secure with RSA key exchange
|
|
1163
|
+
- **`sha256_password`** - SHA-256 based authentication
|
|
1164
|
+
|
|
1165
|
+
The client automatically handles authentication plugin switching when requested by the server, including secure password exchange over non-SSL connections.
|
|
1166
|
+
|
|
1167
|
+
#### Prepared Statements & Performance
|
|
1168
|
+
|
|
1169
|
+
MySQL uses server-side prepared statements for all parameterized queries:
|
|
1170
|
+
|
|
1171
|
+
```ts
|
|
1172
|
+
// This automatically creates a prepared statement on the server
|
|
1173
|
+
const user = await mysql`SELECT * FROM users WHERE id = ${userId}`;
|
|
1174
|
+
|
|
1175
|
+
// Prepared statements are cached and reused for identical queries
|
|
1176
|
+
for (const id of userIds) {
|
|
1177
|
+
// Same prepared statement is reused
|
|
1178
|
+
await mysql`SELECT * FROM users WHERE id = ${id}`;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// Query pipelining - multiple statements sent without waiting
|
|
1182
|
+
const [users, orders, products] = await Promise.all([
|
|
1183
|
+
mysql`SELECT * FROM users WHERE active = ${true}`,
|
|
1184
|
+
mysql`SELECT * FROM orders WHERE status = ${"pending"}`,
|
|
1185
|
+
mysql`SELECT * FROM products WHERE in_stock = ${true}`,
|
|
1186
|
+
]);
|
|
1187
|
+
```
|
|
1188
|
+
|
|
1189
|
+
#### Multiple Result Sets
|
|
1190
|
+
|
|
1191
|
+
MySQL can return multiple result sets from multi-statement queries:
|
|
1192
|
+
|
|
1193
|
+
```ts
|
|
1194
|
+
const mysql = new SQL("mysql://user:pass@localhost/mydb");
|
|
1195
|
+
|
|
1196
|
+
// Multi-statement queries with simple() method
|
|
1197
|
+
const multiResults = await mysql`
|
|
1198
|
+
SELECT * FROM users WHERE id = 1;
|
|
1199
|
+
SELECT * FROM orders WHERE user_id = 1;
|
|
1200
|
+
`.simple();
|
|
1201
|
+
```
|
|
1202
|
+
|
|
1203
|
+
#### Character Sets & Collations
|
|
1204
|
+
|
|
1205
|
+
Bun.SQL automatically uses `utf8mb4` character set for MySQL connections, ensuring full Unicode support including emojis. This is the recommended character set for modern MySQL applications.
|
|
1206
|
+
|
|
1207
|
+
#### Connection Attributes
|
|
1208
|
+
|
|
1209
|
+
Bun automatically sends client information to MySQL for better monitoring:
|
|
1210
|
+
|
|
1211
|
+
```ts
|
|
1212
|
+
// These attributes are sent automatically:
|
|
1213
|
+
// _client_name: "Bun"
|
|
1214
|
+
// _client_version: <bun version>
|
|
1215
|
+
// You can see these in MySQL's performance_schema.session_connect_attrs
|
|
1216
|
+
```
|
|
1217
|
+
|
|
1218
|
+
#### Type Handling
|
|
1219
|
+
|
|
1220
|
+
MySQL types are automatically converted to JavaScript types:
|
|
1221
|
+
|
|
1222
|
+
| MySQL Type | JavaScript Type | Notes |
|
|
1223
|
+
| --------------------------------------- | ------------------------ | ---------------------------------------------------------------------------------------------------- |
|
|
1224
|
+
| INT, TINYINT, MEDIUMINT | number | Within safe integer range |
|
|
1225
|
+
| BIGINT | string, number or BigInt | If the value fits in i32/u32 size will be number otherwise string or BigInt Based on `bigint` option |
|
|
1226
|
+
| DECIMAL, NUMERIC | string | To preserve precision |
|
|
1227
|
+
| FLOAT, DOUBLE | number | |
|
|
1228
|
+
| DATE | Date | JavaScript Date object |
|
|
1229
|
+
| DATETIME, TIMESTAMP | Date | With timezone handling |
|
|
1230
|
+
| TIME | number | Total of microseconds |
|
|
1231
|
+
| YEAR | number | |
|
|
1232
|
+
| CHAR, VARCHAR, VARSTRING, STRING | string | |
|
|
1233
|
+
| TINY TEXT, MEDIUM TEXT, TEXT, LONG TEXT | string | |
|
|
1234
|
+
| TINY BLOB, MEDIUM BLOB, BLOG, LONG BLOB | string | BLOB Types are alias for TEXT types |
|
|
1235
|
+
| JSON | object/array | Automatically parsed |
|
|
1236
|
+
| BIT(1) | boolean | BIT(1) in MySQL |
|
|
1237
|
+
| GEOMETRY | string | Geometry data |
|
|
1238
|
+
|
|
1239
|
+
#### Differences from PostgreSQL
|
|
1240
|
+
|
|
1241
|
+
While the API is unified, there are some behavioral differences:
|
|
1242
|
+
|
|
1243
|
+
1. **Parameter placeholders**: MySQL uses `?` internally but Bun converts `$1, $2` style automatically
|
|
1244
|
+
2. **RETURNING clause**: MySQL doesn't support RETURNING; use `result.lastInsertRowid` or a separate SELECT
|
|
1245
|
+
3. **Array types**: MySQL doesn't have native array types like PostgreSQL
|
|
1246
|
+
|
|
1247
|
+
### MySQL-Specific Features
|
|
1248
|
+
|
|
1249
|
+
We haven't implemented `LOAD DATA INFILE` support yet
|
|
1250
|
+
|
|
1251
|
+
### PostgreSQL-Specific Features
|
|
987
1252
|
|
|
988
1253
|
We haven't implemented these yet:
|
|
989
1254
|
|
|
@@ -998,6 +1263,88 @@ We also haven't implemented some of the more uncommon features like:
|
|
|
998
1263
|
- Point & PostGIS types
|
|
999
1264
|
- All the multi-dimensional integer array types (only a couple of the types are supported)
|
|
1000
1265
|
|
|
1266
|
+
## Common Patterns & Best Practices
|
|
1267
|
+
|
|
1268
|
+
### Working with MySQL Result Sets
|
|
1269
|
+
|
|
1270
|
+
```ts
|
|
1271
|
+
// Getting insert ID after INSERT
|
|
1272
|
+
const result = await mysql`INSERT INTO users (name) VALUES (${"Alice"})`;
|
|
1273
|
+
console.log(result.lastInsertRowid); // MySQL's LAST_INSERT_ID()
|
|
1274
|
+
|
|
1275
|
+
// Handling affected rows
|
|
1276
|
+
const updated =
|
|
1277
|
+
await mysql`UPDATE users SET active = ${false} WHERE age < ${18}`;
|
|
1278
|
+
console.log(updated.affectedRows); // Number of rows updated
|
|
1279
|
+
|
|
1280
|
+
// Using MySQL-specific functions
|
|
1281
|
+
const now = await mysql`SELECT NOW() as current_time`;
|
|
1282
|
+
const uuid = await mysql`SELECT UUID() as id`;
|
|
1283
|
+
```
|
|
1284
|
+
|
|
1285
|
+
### MySQL Error Handling
|
|
1286
|
+
|
|
1287
|
+
```ts
|
|
1288
|
+
try {
|
|
1289
|
+
await mysql`INSERT INTO users (email) VALUES (${"duplicate@email.com"})`;
|
|
1290
|
+
} catch (error) {
|
|
1291
|
+
if (error.code === "ER_DUP_ENTRY") {
|
|
1292
|
+
console.log("Duplicate entry detected");
|
|
1293
|
+
} else if (error.code === "ER_ACCESS_DENIED_ERROR") {
|
|
1294
|
+
console.log("Access denied");
|
|
1295
|
+
} else if (error.code === "ER_BAD_DB_ERROR") {
|
|
1296
|
+
console.log("Database does not exist");
|
|
1297
|
+
}
|
|
1298
|
+
// MySQL error codes are compatible with mysql/mysql2 packages
|
|
1299
|
+
}
|
|
1300
|
+
```
|
|
1301
|
+
|
|
1302
|
+
### Performance Tips for MySQL
|
|
1303
|
+
|
|
1304
|
+
1. **Use connection pooling**: Set appropriate `max` pool size based on your workload
|
|
1305
|
+
2. **Enable prepared statements**: They're enabled by default and improve performance
|
|
1306
|
+
3. **Use transactions for bulk operations**: Group related queries in transactions
|
|
1307
|
+
4. **Index properly**: MySQL relies heavily on indexes for query performance
|
|
1308
|
+
5. **Use `utf8mb4` charset**: It's set by default and handles all Unicode characters
|
|
1309
|
+
|
|
1310
|
+
## Frequently Asked Questions
|
|
1311
|
+
|
|
1312
|
+
> Why is this `Bun.sql` and not `Bun.postgres`?
|
|
1313
|
+
|
|
1314
|
+
The plan was to add more database drivers in the future. Now with MySQL support added, this unified API supports PostgreSQL, MySQL, and SQLite.
|
|
1315
|
+
|
|
1316
|
+
> How do I know which database adapter is being used?
|
|
1317
|
+
|
|
1318
|
+
The adapter is automatically detected from the connection string:
|
|
1319
|
+
|
|
1320
|
+
- URLs starting with `mysql://` or `mysql2://` use MySQL
|
|
1321
|
+
- URLs matching SQLite patterns (`:memory:`, `sqlite://`, `file://`) use SQLite
|
|
1322
|
+
- Everything else defaults to PostgreSQL
|
|
1323
|
+
|
|
1324
|
+
> Are MySQL stored procedures supported?
|
|
1325
|
+
|
|
1326
|
+
Yes, stored procedures are fully supported including OUT parameters and multiple result sets:
|
|
1327
|
+
|
|
1328
|
+
```ts
|
|
1329
|
+
// Call stored procedure
|
|
1330
|
+
const results = await mysql`CALL GetUserStats(${userId}, @total_orders)`;
|
|
1331
|
+
|
|
1332
|
+
// Get OUT parameter
|
|
1333
|
+
const outParam = await mysql`SELECT @total_orders as total`;
|
|
1334
|
+
```
|
|
1335
|
+
|
|
1336
|
+
> Can I use MySQL-specific SQL syntax?
|
|
1337
|
+
|
|
1338
|
+
Yes, you can use any MySQL-specific syntax:
|
|
1339
|
+
|
|
1340
|
+
```ts
|
|
1341
|
+
// MySQL-specific syntax works fine
|
|
1342
|
+
await mysql`SET @user_id = ${userId}`;
|
|
1343
|
+
await mysql`SHOW TABLES`;
|
|
1344
|
+
await mysql`DESCRIBE users`;
|
|
1345
|
+
await mysql`EXPLAIN SELECT * FROM users WHERE id = ${id}`;
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1001
1348
|
## Why not just use an existing library?
|
|
1002
1349
|
|
|
1003
1350
|
npm packages like postgres.js, pg, and node-postgres can be used in Bun too. They're great options.
|
package/docs/cli/pm.md
CHANGED
|
@@ -213,7 +213,7 @@ To display current package version and help:
|
|
|
213
213
|
|
|
214
214
|
```bash
|
|
215
215
|
$ bun pm version
|
|
216
|
-
bun pm version v1.2.22-canary.
|
|
216
|
+
bun pm version v1.2.22-canary.20250830T140622 (ca7428e9)
|
|
217
217
|
Current package version: v1.0.0
|
|
218
218
|
|
|
219
219
|
Increment:
|
package/docs/cli/publish.md
CHANGED
|
@@ -9,7 +9,7 @@ $ bunx nuxi init my-nuxt-app
|
|
|
9
9
|
✔ Which package manager would you like to use?
|
|
10
10
|
bun
|
|
11
11
|
◐ Installing dependencies...
|
|
12
|
-
bun install v1.2.22-canary.
|
|
12
|
+
bun install v1.2.22-canary.20250830T140622 (16b4bf34)
|
|
13
13
|
+ @nuxt/devtools@0.8.2
|
|
14
14
|
+ nuxt@3.7.0
|
|
15
15
|
785 packages installed [2.67s]
|
|
@@ -15,7 +15,7 @@ This will add the package to `peerDependencies` in `package.json`.
|
|
|
15
15
|
```json-diff
|
|
16
16
|
{
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
+ "@types/bun": "^1.2.22-canary.
|
|
18
|
+
+ "@types/bun": "^1.2.22-canary.20250830T140622"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
```
|
|
@@ -27,7 +27,7 @@ Running `bun install` will install peer dependencies by default, unless marked o
|
|
|
27
27
|
```json-diff
|
|
28
28
|
{
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@types/bun": "^1.2.22-canary.
|
|
30
|
+
"@types/bun": "^1.2.22-canary.20250830T140622"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
+ "@types/bun": {
|
|
@@ -97,7 +97,7 @@ $ bun update
|
|
|
97
97
|
$ bun update @types/bun --latest
|
|
98
98
|
|
|
99
99
|
# Update a dependency to a specific version
|
|
100
|
-
$ bun update @types/bun@1.2.22-canary.
|
|
100
|
+
$ bun update @types/bun@1.2.22-canary.20250830T140622
|
|
101
101
|
|
|
102
102
|
# Update all dependencies to the latest versions
|
|
103
103
|
$ bun update --latest
|
|
@@ -21,7 +21,7 @@ Here's what the output of a typical test run looks like. In this case, there are
|
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
$ bun test
|
|
24
|
-
bun test v1.2.22-canary.
|
|
24
|
+
bun test v1.2.22-canary.20250830T140622 (9c68abdb)
|
|
25
25
|
|
|
26
26
|
test.test.js:
|
|
27
27
|
✓ add [0.87ms]
|
|
@@ -47,7 +47,7 @@ To only run certain test files, pass a positional argument to `bun test`. The ru
|
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
49
|
$ bun test test3
|
|
50
|
-
bun test v1.2.22-canary.
|
|
50
|
+
bun test v1.2.22-canary.20250830T140622 (9c68abdb)
|
|
51
51
|
|
|
52
52
|
test3.test.js:
|
|
53
53
|
✓ add [1.40ms]
|
|
@@ -85,7 +85,7 @@ Adding `-t add` will only run tests with "add" in the name. This works with test
|
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
87
|
$ bun test -t add
|
|
88
|
-
bun test v1.2.22-canary.
|
|
88
|
+
bun test v1.2.22-canary.20250830T140622 (9c68abdb)
|
|
89
89
|
|
|
90
90
|
test.test.js:
|
|
91
91
|
✓ add [1.79ms]
|
|
@@ -18,7 +18,7 @@ The first time this test is executed, Bun will evaluate the value passed into `e
|
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
20
|
$ bun test test/snap
|
|
21
|
-
bun test v1.2.22-canary.
|
|
21
|
+
bun test v1.2.22-canary.20250830T140622 (9c68abdb)
|
|
22
22
|
|
|
23
23
|
test/snap.test.ts:
|
|
24
24
|
✓ snapshot [1.48ms]
|
|
@@ -61,7 +61,7 @@ Later, when this test file is executed again, Bun will read the snapshot file an
|
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
63
|
$ bun test
|
|
64
|
-
bun test v1.2.22-canary.
|
|
64
|
+
bun test v1.2.22-canary.20250830T140622 (9c68abdb)
|
|
65
65
|
|
|
66
66
|
test/snap.test.ts:
|
|
67
67
|
✓ snapshot [1.05ms]
|
|
@@ -78,7 +78,7 @@ To update snapshots, use the `--update-snapshots` flag.
|
|
|
78
78
|
|
|
79
79
|
```sh
|
|
80
80
|
$ bun test --update-snapshots
|
|
81
|
-
bun test v1.2.22-canary.
|
|
81
|
+
bun test v1.2.22-canary.20250830T140622 (9c68abdb)
|
|
82
82
|
|
|
83
83
|
test/snap.test.ts:
|
|
84
84
|
✓ snapshot [0.86ms]
|
|
@@ -29,7 +29,7 @@ To regenerate snapshots, use the `--update-snapshots` flag.
|
|
|
29
29
|
|
|
30
30
|
```sh
|
|
31
31
|
$ bun test --update-snapshots
|
|
32
|
-
bun test v1.2.22-canary.
|
|
32
|
+
bun test v1.2.22-canary.20250830T140622 (9c68abdb)
|
|
33
33
|
|
|
34
34
|
test/snap.test.ts:
|
|
35
35
|
✓ snapshot [0.86ms]
|
package/docs/installation.md
CHANGED
|
@@ -14,7 +14,7 @@ Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1. Us
|
|
|
14
14
|
```bash#macOS/Linux_(curl)
|
|
15
15
|
$ curl -fsSL https://bun.com/install | bash # for macOS, Linux, and WSL
|
|
16
16
|
# to install a specific version
|
|
17
|
-
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.22-canary.
|
|
17
|
+
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.22-canary.20250830T140622"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
```bash#npm
|
|
@@ -189,10 +189,10 @@ Since Bun is a single binary, you can install older versions of Bun by re-runnin
|
|
|
189
189
|
|
|
190
190
|
### Installing a specific version of Bun on Linux/Mac
|
|
191
191
|
|
|
192
|
-
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.22-canary.
|
|
192
|
+
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.22-canary.20250830T140622`.
|
|
193
193
|
|
|
194
194
|
```sh
|
|
195
|
-
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.22-canary.
|
|
195
|
+
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.22-canary.20250830T140622"
|
|
196
196
|
```
|
|
197
197
|
|
|
198
198
|
### Installing a specific version of Bun on Windows
|
|
@@ -201,7 +201,7 @@ On Windows, you can install a specific version of Bun by passing the version num
|
|
|
201
201
|
|
|
202
202
|
```sh
|
|
203
203
|
# PowerShell:
|
|
204
|
-
$ iex "& {$(irm https://bun.com/install.ps1)} -Version 1.2.22-canary.
|
|
204
|
+
$ iex "& {$(irm https://bun.com/install.ps1)} -Version 1.2.22-canary.20250830T140622"
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
## Downloading Bun binaries directly
|
package/docs/runtime/debugger.md
CHANGED
|
@@ -124,11 +124,11 @@ await fetch("https://example.com", {
|
|
|
124
124
|
This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
|
|
125
125
|
|
|
126
126
|
```sh
|
|
127
|
-
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.22-canary.
|
|
127
|
+
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.22-canary.20250830T140622" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
|
|
128
128
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
129
129
|
[fetch] > content-type: application/json
|
|
130
130
|
[fetch] > Connection: keep-alive
|
|
131
|
-
[fetch] > User-Agent: Bun/1.2.22-canary.
|
|
131
|
+
[fetch] > User-Agent: Bun/1.2.22-canary.20250830T140622
|
|
132
132
|
[fetch] > Accept: */*
|
|
133
133
|
[fetch] > Host: example.com
|
|
134
134
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
|
@@ -170,7 +170,7 @@ This prints the following to the console:
|
|
|
170
170
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
171
171
|
[fetch] > content-type: application/json
|
|
172
172
|
[fetch] > Connection: keep-alive
|
|
173
|
-
[fetch] > User-Agent: Bun/1.2.22-canary.
|
|
173
|
+
[fetch] > User-Agent: Bun/1.2.22-canary.20250830T140622
|
|
174
174
|
[fetch] > Accept: */*
|
|
175
175
|
[fetch] > Host: example.com
|
|
176
176
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/test/dom.md
CHANGED
package/package.json
CHANGED