Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ const rows = await sql.query('SELECT * FROM posts WHERE id = $1', [postId], {
clearTimeout(timeout);
```

### `responseFormat: 'json' | 'jsonl' | 'cbor-seq'`

The `responseFormat` option selects the wire format used by SQL-over-HTTP. The
default, `json`, uses the existing `application/json` response. The experimental
`jsonl` and `cbor-seq` formats request a sequence of independently encoded
messages using the versioned `application/vnd.neon.sql.v1+json` and
`application/vnd.neon.sql.v1+cbor` media types, and buffer the complete
response before decoding it.

```typescript
const sql = neon(process.env.DATABASE_URL, {
responseFormat: 'cbor-seq',
});
```

Streaming response formats support both single queries and `transaction()`
batches.

### `types: CustomTypesConfig`

The `types` option can be passed to `neon(...)` to override the default PostgreSQL type parsers provided by `PgTypes`. This is useful if you want to define custom parsing behavior for specific PostgreSQL data types, allowing you to control how data is converted when retrieved from the database. Learn more in the [PgTypes official documentation](https://github.com/brianc/node-pg-types).
Expand Down
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npx esbuild src/index.ts \
--format=cjs \
--bundle \
--keep-names \
--alias:cbor-x=cbor-x/decode \
--inject:src/shims/shims.js \
--define:BUNDLE_EXT=\"js\" \
--target=es2020 \
Expand All @@ -30,6 +31,7 @@ npx esbuild src/index.ts \
--format=esm \
--bundle \
--keep-names \
--alias:cbor-x=cbor-x/decode \
--inject:src/shims/shims.js \
--define:BUNDLE_EXT=\"mjs\" \
--target=es2020 \
Expand Down
10 changes: 9 additions & 1 deletion index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ export declare interface HTTPQueryOptions<ArrayMode extends boolean, FullResults
* options take precedence.
*/
fetchOptions?: Record<string, any>;
/**
* Wire format requested from the SQL-over-HTTP endpoint.
*
* Default: `json`
*/
responseFormat?: HTTPResponseFormat;
/**
* JWT auth token to be passed as the Bearer token in the Authorization header.
* Can be string, or a function (sync or async) returning a string.
Expand All @@ -471,6 +477,8 @@ export declare interface HTTPQueryOptions<ArrayMode extends boolean, FullResults
disableWarningInBrowsers?: boolean;
}

export declare type HTTPResponseFormat = 'json' | 'jsonl' | 'cbor-seq';

export declare interface HTTPTransactionOptions<ArrayMode extends boolean, FullResults extends boolean> extends HTTPQueryOptions<ArrayMode, FullResults> {
/**
* Postgres transaction isolation level: see https://www.postgresql.org/docs/current/transaction-iso.html.
Expand Down Expand Up @@ -572,7 +580,7 @@ export declare interface MessageConfig {
* pass as `fetchOptions` an object which will be merged into the options
* passed to `fetch`.
*/
export declare function neon<ArrayMode extends boolean = false, FullResults extends boolean = false>(connectionString: string, { arrayMode: neonOptArrayMode, fullResults: neonOptFullResults, fetchOptions: neonOptFetchOptions, isolationLevel: neonOptIsolationLevel, readOnly: neonOptReadOnly, deferrable: neonOptDeferrable, authToken, disableWarningInBrowsers, }?: HTTPTransactionOptions<ArrayMode, FullResults>): NeonQueryFunction<ArrayMode, FullResults>;
export declare function neon<ArrayMode extends boolean = false, FullResults extends boolean = false>(connectionString: string, { arrayMode: neonOptArrayMode, fullResults: neonOptFullResults, fetchOptions: neonOptFetchOptions, responseFormat: neonOptResponseFormat, isolationLevel: neonOptIsolationLevel, readOnly: neonOptReadOnly, deferrable: neonOptDeferrable, authToken, disableWarningInBrowsers, }?: HTTPTransactionOptions<ArrayMode, FullResults>): NeonQueryFunction<ArrayMode, FullResults>;

export declare interface NeonConfig {
poolQueryViaFetch: boolean;
Expand Down
10 changes: 9 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ export declare interface HTTPQueryOptions<ArrayMode extends boolean, FullResults
* options take precedence.
*/
fetchOptions?: Record<string, any>;
/**
* Wire format requested from the SQL-over-HTTP endpoint.
*
* Default: `json`
*/
responseFormat?: HTTPResponseFormat;
/**
* JWT auth token to be passed as the Bearer token in the Authorization header.
* Can be string, or a function (sync or async) returning a string.
Expand All @@ -471,6 +477,8 @@ export declare interface HTTPQueryOptions<ArrayMode extends boolean, FullResults
disableWarningInBrowsers?: boolean;
}

export declare type HTTPResponseFormat = 'json' | 'jsonl' | 'cbor-seq';

export declare interface HTTPTransactionOptions<ArrayMode extends boolean, FullResults extends boolean> extends HTTPQueryOptions<ArrayMode, FullResults> {
/**
* Postgres transaction isolation level: see https://www.postgresql.org/docs/current/transaction-iso.html.
Expand Down Expand Up @@ -572,7 +580,7 @@ export declare interface MessageConfig {
* pass as `fetchOptions` an object which will be merged into the options
* passed to `fetch`.
*/
export declare function neon<ArrayMode extends boolean = false, FullResults extends boolean = false>(connectionString: string, { arrayMode: neonOptArrayMode, fullResults: neonOptFullResults, fetchOptions: neonOptFetchOptions, isolationLevel: neonOptIsolationLevel, readOnly: neonOptReadOnly, deferrable: neonOptDeferrable, authToken, disableWarningInBrowsers, }?: HTTPTransactionOptions<ArrayMode, FullResults>): NeonQueryFunction<ArrayMode, FullResults>;
export declare function neon<ArrayMode extends boolean = false, FullResults extends boolean = false>(connectionString: string, { arrayMode: neonOptArrayMode, fullResults: neonOptFullResults, fetchOptions: neonOptFetchOptions, responseFormat: neonOptResponseFormat, isolationLevel: neonOptIsolationLevel, readOnly: neonOptReadOnly, deferrable: neonOptDeferrable, authToken, disableWarningInBrowsers, }?: HTTPTransactionOptions<ArrayMode, FullResults>): NeonQueryFunction<ArrayMode, FullResults>;

export declare interface NeonConfig {
poolQueryViaFetch: boolean;
Expand Down
Loading
Loading