
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
pg-binary-copy-writer
Advanced tools
A module that writes javascript types/objects/arrays to the Postgres binary copy format.
A module that writes javascript types/objects/arrays to the Postgres binary copy format.
import {
TypedRecordEncoder,
getPGBinaryHeader,
getPGBinaryFooter,
} from "pg-binary-copy-writer";
type InputType = {
a: string;
b: string;
c: number;
d: Date;
e: object;
f: Uint8Array;
g?: string | null;
h: bigint;
i: string;
j: boolean[];
};
const encoder = new TypedRecordEncoder<InputType>({
a: "text",
b: "text",
c: "float8",
d: "timestamptz",
e: "jsonb",
f: "bytea",
g: "text",
h: "int8",
i: "uuid",
j: "bool[]",
});
// Will encode an object array and add a header and footer
const output = encoder.encodeRecords(inputArray);
// Or, you can stream it like so
//Get a header and add it to the start of your stream
const PG_BINARY_HEADER = getPGBinaryHeader();
//Encode records
const binary = encoder.encodeRecord(input);
//Add the footer then close the stream
const PG_BINARY_FOOTER = getPGBinaryHeader();
A lot of databases:
Some instances of postgres support reading directly from these external stores.
So what if:
Here's an example from Snowflake:
SELECT pgBinaryHeader() as bin
UNION ALL
SELECT pgBinaryRow(*) as bin
UNION ALL
SELECT pgBinaryFooter() as bin
FROM table
Most databases allow you to configure record delimiters and field delimiters. Snowflake as an example has:
RECORD_DELIMITER = ''
FIELD_DELIMITER = ''
And Mysql has
SELECT * INTO OUTFILE 'outfile.bin'
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY ''
LINES TERMINATED BY ''
FROM table
In order to work in all JS environments, I'm limited to only using classes/methods in the ECMA standard. Hence, instead of using Buffer I use a combination of:
I can't use
FAQs
A module that writes javascript types/objects/arrays to the Postgres binary copy format.
The npm package pg-binary-copy-writer receives a total of 6 weekly downloads. As such, pg-binary-copy-writer popularity was classified as not popular.
We found that pg-binary-copy-writer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.