[pg-copy-streams] New module

This commit is contained in:
Brian Crowell
2019-02-21 22:38:59 -06:00
parent 98f15bb0f6
commit 5497bf30cb
4 changed files with 63 additions and 0 deletions

20
types/pg-copy-streams/index.d.ts vendored Normal file
View File

@@ -0,0 +1,20 @@
// Type definitions for pg-copy-streams 1.2
// Project: https://github.com/brianc/node-pg-copy-streams
// Definitions by: Brian Crowell <https://github.com/fluggo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { Submittable, Connection } from "pg";
import { Transform, TransformOptions } from "stream";
export function from(txt: string, options?: TransformOptions): CopyStreamQuery;
export function to(txt: string, options?: TransformOptions): CopyToStreamQuery;
export class CopyStreamQuery extends Transform implements Submittable {
submit(connection: Connection): void;
}
export class CopyToStreamQuery extends Transform implements Submittable {
submit(connection: Connection): void;
}

View File

@@ -0,0 +1,19 @@
import { Client } from "pg";
import { from, to } from "pg-copy-streams";
const client = new Client('fake-config-string');
const copyStream = client.query(from('copy data from stdin;'));
copyStream.write('', err => {
if (err) {
console.error(err);
return;
}
copyStream.end();
});
const readStream = client.query(to('copy data to stdout;'));
readStream.pipe(process.stdout);

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"pg-copy-streams-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }