Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@wmfs/supercopy
Advanced tools
Takes a specifically-named directory structure of CSV files and conjures bulk insert, update and delete statements and applies them to a PostgreSQL database.
Takes a specifically-named directory structure of CSV files and conjures bulk insert, update and delete statements and applies them to a PostgreSQL database.
$ npm install supercopy --save
const pg = require('pg')
const supercopy = require('supercopy')
// Make a new Postgres client
const client = new pg.Client('postgres://postgres:postgres@localhost:5432/my_test_db')
supercopy(
{
sourceDir: '/dir/that/holds/deletes/inserts/updates/and/upserts/dirs',
headerColumnNamePkPrefix: '.',
topDownTableOrder: ['departments', 'employees'],
client: client,
schemaName: 'my_schema',
truncateTables: true,
debug: true,
multicopy: false,
directoryNames: { ... }
},
function (err) {
// Done!
}
)
options
, callback
)Property | Type | Notes |
---|---|---|
sourceDir | function | An absolute path pointing to a directory containing action folders. See the File Structure section for more details. |
headerColumnNamePkPrefix | string | When conjuring an update statement, Supercopy will need to know which columns in the CSV file constitute a primary key. It does this by expecting the first line of each file to be a header containing , delimited column names. However, column names prefixed with this value should be deemed a primary-key column. Only use in update CSV-file headers. |
topDownTableOrder | [string] | An array of strings, where each string is a table name. Table inserts will occur in this order and deletes in reverse - use to avoid integrity-constraint errors. If no schema prefix is supplied to a table name, then it's inferred from schemaName . |
client | client | Either a pg client or pool (something with a query() method) that's already connected to a PostgreSQL database. |
schemaName | string | Identifies a PostgreSQL schema where the tables that are to be affected by this copy be found. |
truncateTables | boolean | A flag to indicate whether or not to truncate tables before supercopying into them |
debug | boolean | Show debugging information on the console |
multicopy | boolean | Enables 'sourceDir' to house many typical Supercopy 'sourceDir' shaped directories. Defaults to false. |
quote | string | Override the the default quote character, ". It isn't necessary to quote fields but occasionally (especially when importing JSON fields) you need to, and this option will help. |
directoryNames | object | Overrides the default directory names - see below. |
The directory identified by the sourceDir
option should be structured in the following way:
/someDir
/inserts
table1.csv
table2.csv
/updates
table1.csv
table2.csv
/upserts
table1.csv
table2.csv
/deletes
table1.csv
OR IF USING MULTICOPY
/manyDirs
/someDir
/inserts
table1.csv
table2.csv
/someDir
/inserts
table1.csv
table2.csv
insert
, update
, upsert
(try to update, failing that insert) and delete
.directoryNames
option can be used to apply actions to directories if the names don't meet the above structure. Eg
directoryName : { 'inserts': 'new', 'deletes': 'old' }
would insert the contents of the directory named new
and remove the contents of the old
directory.schemaName
option.headerColumnNamePkPrefix
character.,
should be quoted with a "
. The csv-string package might help.Before running these tests, you'll need a test PostgreSQL database available and set a PG_CONNECTION_STRING
environment variable to point to it, for example:
PG_CONNECTION_STRING=postgres://postgres:postgres@localhost:5432/my_test_db
$ npm test
FAQs
Takes a specifically-named directory structure of CSV files and conjures bulk insert, update and delete statements and applies them to a PostgreSQL database.
We found that @wmfs/supercopy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.