Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@databases/pg

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@databases/pg - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

lib/__tests__/stream.test.d.ts

6

lib/index.d.ts

@@ -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* () {

8

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc