
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.