Skip to content

Commit 92a8b6d

Browse files
committed
build
build
1 parent cae4d97 commit 92a8b6d

File tree

5 files changed

+53
-20
lines changed

5 files changed

+53
-20
lines changed

cf/src/query.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ export class Query extends Promise {
3737
}
3838

3939
get origin() {
40-
return this.handler.debug
40+
return (this.handler.debug
4141
? this[originError].stack
42-
: this.tagged
43-
? originStackCache.has(this.strings)
44-
? originStackCache.get(this.strings)
45-
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
46-
: ''
42+
: this.tagged && originStackCache.has(this.strings)
43+
? originStackCache.get(this.strings)
44+
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
45+
) || ''
4746
}
4847

4948
static get [Symbol.species]() {

cjs/src/query.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ const Query = module.exports.Query = class Query extends Promise {
3737
}
3838

3939
get origin() {
40-
return this.handler.debug
40+
return (this.handler.debug
4141
? this[originError].stack
42-
: this.tagged
43-
? originStackCache.has(this.strings)
44-
? originStackCache.get(this.strings)
45-
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
46-
: ''
42+
: this.tagged && originStackCache.has(this.strings)
43+
? originStackCache.get(this.strings)
44+
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
45+
) || ''
4746
}
4847

4948
static get [Symbol.species]() {

deno/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,34 @@ const sql = postgres({
10561056
})
10571057
```
10581058

1059+
### Cloudflare Workers support
1060+
1061+
Postgres.js has built-in support for the [TCP socket API](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/) in Cloudflare Workers, which is [on-track](https://github.com/wintercg/proposal-sockets-api) to be standardized and adopted in Node.js and other JavaScript runtimes, such as Deno.
1062+
1063+
You can use Postgres.js directly in a Worker, or to benefit from connection pooling and query caching, via the [Hyperdrive](https://developers.cloudflare.com/hyperdrive/learning/connect-to-postgres/#driver-examples) service available to Workers by passing the Hyperdrive `connectionString` when creating a new `postgres` client as follows:
1064+
1065+
```ts
1066+
// Requires Postgres.js 3.4.0 or later
1067+
import postgres from 'postgres'
1068+
1069+
interface Env {
1070+
HYPERDRIVE: Hyperdrive;
1071+
}
1072+
1073+
export default async fetch(req: Request, env: Env, ctx: ExecutionContext) {
1074+
// The Postgres.js library accepts a connection string directly
1075+
const sql = postgres(env.HYPERDRIVE.connectionString)
1076+
const results = await sql`SELECT * FROM users LIMIT 10`
1077+
return Response.json(results)
1078+
}
1079+
```
1080+
1081+
In `wrangler.toml` you will need to enable `node_compat` to allow Postgres.js to operate in the Workers environment:
1082+
1083+
```toml
1084+
node_compat = true # required for database drivers to function
1085+
```
1086+
10591087
### Auto fetching of array types
10601088

10611089
Postgres.js will automatically fetch table/array-type information when it first connects to a database.

deno/src/query.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ export class Query extends Promise {
3737
}
3838

3939
get origin() {
40-
return this.handler.debug
40+
return (this.handler.debug
4141
? this[originError].stack
42-
: this.tagged
43-
? originStackCache.has(this.strings)
44-
? originStackCache.get(this.strings)
45-
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
46-
: ''
42+
: this.tagged && originStackCache.has(this.strings)
43+
? originStackCache.get(this.strings)
44+
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
45+
) || ''
4746
}
4847

4948
static get [Symbol.species]() {

deno/types/index.d.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,17 @@ type Rest<T> =
179179
T extends TemplateStringsArray ? never : // force fallback to the tagged template function overload
180180
T extends string ? readonly string[] :
181181
T extends readonly any[][] ? readonly [] :
182-
T extends readonly (object & infer R)[] ? readonly (Keys & keyof R)[] :
182+
T extends readonly (object & infer R)[] ? (
183+
readonly (Keys & keyof R)[] // sql(data, "prop", "prop2") syntax
184+
|
185+
[readonly (Keys & keyof R)[]] // sql(data, ["prop", "prop2"]) syntax
186+
) :
183187
T extends readonly any[] ? readonly [] :
184-
T extends object ? readonly (Keys & keyof T)[] :
188+
T extends object ? (
189+
readonly (Keys & keyof T)[] // sql(data, "prop", "prop2") syntax
190+
|
191+
[readonly (Keys & keyof T)[]] // sql(data, ["prop", "prop2"]) syntax
192+
) :
185193
any
186194

187195
type Return<T, K extends readonly any[]> =

0 commit comments

Comments
 (0)