You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

postgres-semicolons

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postgres-semicolons

Split Postgres SQL queries on semicolons

0.1.2
latest
Source
npmnpm
Version published
Weekly downloads
4.6K
-3.82%
Maintainers
1
Weekly downloads
 
Created
Source

semicolons

This package exists to take a string containing multiple Postgres SQL statements, separated by semicolons, and split it into its constituent statements.

This isn't trivial, because semicolons may occur in double-quoted identifiers, ordinary strings, 'escape' strings, continuation strings, dollar-quoted strings, single-line comments, and (nestable) multi-line comments, and in all these cases they do not separate statements.

Sticky RegExps are used liberally.

Installation

npm install postgres-semicolons

Usage

The exported functions have comprehensive TSDoc comments in index.ts.

An example:

import * as semicolons from 'postgres-semicolons';

const sql = `BEGIN; /*/* SELECT 1; */ SELECT 2; */; SELECT ';'';'; SELECT $x$;$x$; -- COMMIT;`;
const standardConformingStrings = true; 
const splits = semicolons.parseSplits(sql, standardConformingStrings);
const queries = semicolons.nonEmptyStatements(sql, splits.positions);

console.log(queries);  // -> [ 'BEGIN', "SELECT ';'';'", 'SELECT $x$;$x$' ]

License

The code is MIT licensed.

FAQs

Package last updated on 29 Jan 2024

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