Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
build
  • Loading branch information
porsager committed Oct 10, 2023
1 parent cae4d97 commit 92a8b6d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
11 changes: 5 additions & 6 deletions cf/src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ export class Query extends Promise {
}

get origin() {
return this.handler.debug
return (this.handler.debug
? this[originError].stack
: this.tagged
? originStackCache.has(this.strings)
? originStackCache.get(this.strings)
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
: ''
: this.tagged && originStackCache.has(this.strings)
? originStackCache.get(this.strings)
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
) || ''
}

static get [Symbol.species]() {
Expand Down
11 changes: 5 additions & 6 deletions cjs/src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ const Query = module.exports.Query = class Query extends Promise {
}

get origin() {
return this.handler.debug
return (this.handler.debug
? this[originError].stack
: this.tagged
? originStackCache.has(this.strings)
? originStackCache.get(this.strings)
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
: ''
: this.tagged && originStackCache.has(this.strings)
? originStackCache.get(this.strings)
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
) || ''
}

static get [Symbol.species]() {
Expand Down
28 changes: 28 additions & 0 deletions deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,34 @@ const sql = postgres({
})
```

### Cloudflare Workers support

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.

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:

```ts
// Requires Postgres.js 3.4.0 or later
import postgres from 'postgres'

interface Env {
HYPERDRIVE: Hyperdrive;
}

export default async fetch(req: Request, env: Env, ctx: ExecutionContext) {
// The Postgres.js library accepts a connection string directly
const sql = postgres(env.HYPERDRIVE.connectionString)
const results = await sql`SELECT * FROM users LIMIT 10`
return Response.json(results)
}
```

In `wrangler.toml` you will need to enable `node_compat` to allow Postgres.js to operate in the Workers environment:

```toml
node_compat = true # required for database drivers to function
```

### Auto fetching of array types

Postgres.js will automatically fetch table/array-type information when it first connects to a database.
Expand Down
11 changes: 5 additions & 6 deletions deno/src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ export class Query extends Promise {
}

get origin() {
return this.handler.debug
return (this.handler.debug
? this[originError].stack
: this.tagged
? originStackCache.has(this.strings)
? originStackCache.get(this.strings)
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
: ''
: this.tagged && originStackCache.has(this.strings)
? originStackCache.get(this.strings)
: originStackCache.set(this.strings, this[originError].stack).get(this.strings)
) || ''
}

static get [Symbol.species]() {
Expand Down
12 changes: 10 additions & 2 deletions deno/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,17 @@ type Rest<T> =
T extends TemplateStringsArray ? never : // force fallback to the tagged template function overload
T extends string ? readonly string[] :
T extends readonly any[][] ? readonly [] :
T extends readonly (object & infer R)[] ? readonly (Keys & keyof R)[] :
T extends readonly (object & infer R)[] ? (
readonly (Keys & keyof R)[] // sql(data, "prop", "prop2") syntax
|
[readonly (Keys & keyof R)[]] // sql(data, ["prop", "prop2"]) syntax
) :
T extends readonly any[] ? readonly [] :
T extends object ? readonly (Keys & keyof T)[] :
T extends object ? (
readonly (Keys & keyof T)[] // sql(data, "prop", "prop2") syntax
|
[readonly (Keys & keyof T)[]] // sql(data, ["prop", "prop2"]) syntax
) :
any

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

0 comments on commit 92a8b6d

Please sign in to comment.