New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

postgres-dump-convertor

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postgres-dump-convertor

The module is able to convert a file containging multiple INSERT statements of one row to one INSERT statement with multiple rows

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Insert Multiple Rows

This script reads in a text file containing SQL INSERT INTO statements and converts them into a single multiple rows INSERT INTO statement for each table.

How it works

  • The script reads in the text file and splits its contents into an array of lines.
  • It iterates through the array of lines and checks if each line starts with the INSERT INTO keyword.
  • If a line does start with the INSERT INTO keyword, it extracts the table name from the line and adds it to an object that holds the insert statements for each table.
  • If a line does not start with the INSERT INTO keyword, it prints the line as is.
  • When all lines have been processed, the script iterates through the keys in the object and creates a single multiple rows INSERT INTO statement for each table by joining the array of insert statements for the table with commas.

Example

Input:

INSERT INTO table1 (col1, col2) VALUES (1, 'a');
INSERT INTO table1 (col1, col2) VALUES (2, 'b');
INSERT INTO table2 (col1, col2) VALUES (3, 'c');

Output:

INSERT INTO table1 (col1, col2) VALUES (1, 'a'), (2, 'b');
INSERT INTO table2 (col1, col2) VALUES (3, 'c');

Usage

To use this script, replace the test/inputFile argument in the fs.readFile function with the path to your input file and run the script using Node.js.

node script.js > test/outputFile

Note

The script and the readme page was created using chat.openai.com

FAQs

Package last updated on 17 Dec 2022

Did you know?

Socket

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.

Install

Related posts