@databases/pg
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { isSQLError, SQLError, SQLErrorCode } from '@databases/pg-errors'; | ||
@@ -5,2 +6,3 @@ import sql, { SQLQuery, SQL } from '@databases/sql'; | ||
import DataTypeID from '@databases/pg-data-type-id'; | ||
import { Readable } from 'stream'; | ||
export { sql, SQLQuery, isSQLError, SQLError, SQLErrorCode, DataTypeID }; | ||
@@ -10,2 +12,6 @@ export interface Connection { | ||
query(query: SQLQuery): Promise<any[]>; | ||
stream(query: SQLQuery, options?: { | ||
highWaterMark?: number; | ||
batchSize?: number; | ||
}): Readable; | ||
task<T>(fn: (connection: Connection) => Promise<T>): Promise<T>; | ||
@@ -12,0 +18,0 @@ tx<T>(fn: (connection: Connection) => Promise<T>): Promise<T>; |
@@ -44,2 +44,4 @@ "use strict"; | ||
const pg_config_1 = require("@databases/pg-config"); | ||
const QueryStream = require("pg-query-stream"); | ||
const stream_1 = require("stream"); | ||
const { codeFrameColumns } = require('@babel/code-frame'); | ||
@@ -85,2 +87,15 @@ const { connectionStringEnvironmentVariable } = pg_config_1.getPgConfigSync(); | ||
} | ||
stream(query, options = {}) { | ||
if (!(query instanceof sql_1.SQLQuery)) { | ||
throw new Error('Invalid query, you must use @databases/sql to create your queries.'); | ||
} | ||
const { text, values } = query.compile(process.env.NODE_ENV !== 'production' ? { minify: false } : undefined); | ||
const qs = new QueryStream(text, values, options); | ||
const stream = new stream_1.PassThrough({ objectMode: true }); | ||
this.connection.stream(qs, results => { | ||
results.pipe(stream); | ||
results.on('error', err => stream.emit('error', err)); | ||
}).catch(err => stream.emit('error', err)); | ||
return stream; | ||
} | ||
task(fn) { | ||
@@ -87,0 +102,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "@databases/pg", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "", | ||
@@ -13,3 +13,5 @@ "main": "./lib/index.js", | ||
"@databases/sql": "^0.0.0", | ||
"pg-promise": "^8.5.4" | ||
"@types/pg-query-stream": "^1.0.2", | ||
"pg-promise": "^8.5.4", | ||
"pg-query-stream": "1.1.2" | ||
}, | ||
@@ -26,2 +28,2 @@ "scripts": {}, | ||
"bugs": "https://github.com/ForbesLindesay/atdatabases/issues" | ||
} | ||
} |
@@ -7,2 +7,4 @@ import {isSQLError, SQLError, SQLErrorCode} from '@databases/pg-errors'; | ||
import {getPgConfigSync} from '@databases/pg-config'; | ||
import QueryStream = require('pg-query-stream'); | ||
import {PassThrough, Readable} from 'stream'; | ||
const {codeFrameColumns} = require('@babel/code-frame'); | ||
@@ -17,2 +19,9 @@ | ||
query(query: SQLQuery): Promise<any[]>; | ||
stream( | ||
query: SQLQuery, | ||
options?: { | ||
highWaterMark?: number; | ||
batchSize?: number; | ||
}, | ||
): Readable; | ||
task<T>(fn: (connection: Connection) => Promise<T>): Promise<T>; | ||
@@ -88,2 +97,27 @@ tx<T>(fn: (connection: Connection) => Promise<T>): Promise<T>; | ||
} | ||
stream( | ||
query: SQLQuery, | ||
options: { | ||
highWaterMark?: number; | ||
batchSize?: number; | ||
} = {}, | ||
): Readable { | ||
if (!(query instanceof SQLQuery)) { | ||
throw new Error( | ||
'Invalid query, you must use @databases/sql to create your queries.', | ||
); | ||
} | ||
const {text, values} = query.compile( | ||
process.env.NODE_ENV !== 'production' ? {minify: false} : undefined, | ||
); | ||
const qs = new QueryStream(text, values, options); | ||
const stream = new PassThrough({objectMode: true}); | ||
this.connection | ||
.stream(qs, results => { | ||
results.pipe(stream); | ||
results.on('error', err => stream.emit('error', err)); | ||
}) | ||
.catch(err => stream.emit('error', err)); | ||
return stream; | ||
} | ||
async task<T>( | ||
@@ -90,0 +124,0 @@ fn: (connection: ConnectionImplementation) => Promise<T>, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62958
22
1297
8
5
+ Addedpg-query-stream@1.1.2
+ Added@types/pg@8.11.10(transitive)
+ Added@types/pg-query-stream@1.0.3(transitive)
+ Addedobuf@1.1.2(transitive)
+ Addedpg-cursor@1.3.0(transitive)
+ Addedpg-numeric@1.0.2(transitive)
+ Addedpg-protocol@1.7.0(transitive)
+ Addedpg-query-stream@1.1.2(transitive)
+ Addedpg-types@4.0.2(transitive)
+ Addedpostgres-array@3.0.2(transitive)
+ Addedpostgres-bytea@3.0.0(transitive)
+ Addedpostgres-date@2.1.0(transitive)
+ Addedpostgres-interval@3.0.0(transitive)
+ Addedpostgres-range@1.1.4(transitive)