Socket
Socket
Sign inDemoInstall

libpg-query

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libpg-query - npm Package Compare versions

Comparing version 13.1.1 to 13.1.2

2

index.d.ts

@@ -5,1 +5,3 @@ export function parseQuery(sql: string): Promise<any>;

export function parsePlPgSQLSync(funcsSql: string): any;
export function fingerprint(sql: string): Promise<string>;
export function fingerprintSync(sql: string): string;

@@ -26,3 +26,15 @@ const PgQuery = require('./build/Release/queryparser');

return JSON.parse(PgQuery.parsePlPgSQLSync(query));
},
fingerprint(query) {
return new Promise((resolve, reject) =>{
PgQuery.fingerprintAsync(query, (err, result) => {
err ? reject(err) : resolve(result);
})
});
},
fingerprintSync(query) {
return PgQuery.fingerprintSync(query);
}
};

2

package.json
{
"name": "libpg-query",
"version": "13.1.1",
"version": "13.1.2",
"description": "The real PostgreSQL query parser",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/pyramation/libpg-query-node",

@@ -1,6 +0,6 @@

const query = require('../');
const { expect } = require('chai');
const query = require("../");
const { expect } = require("chai");
const { omit, cloneDeepWith } = require("lodash");
describe('Queries', () => {
describe("Queries", () => {
describe("Sync Parsing", () => {

@@ -10,3 +10,3 @@ it("should return a single-item parse result for common queries", () => {

const results = queries.map(query.parseQuerySync);
results.forEach(res => {
results.forEach((res) => {
expect(res.stmts).to.have.lengthOf(1);

@@ -18,7 +18,15 @@ });

// itself, but doing a bit for sanity doesn't hurt.
const selectedDatas = results.map(it => it.stmts[0].stmt.SelectStmt.targetList);
const selectedDatas = results.map(
(it) => it.stmts[0].stmt.SelectStmt.targetList
);
expect(selectedDatas[0][0].ResTarget.val.A_Const.val.Integer.ival).to.eq(1);
expect(selectedDatas[1][0].ResTarget.val.A_Const.val).to.have.property("Null");
expect(selectedDatas[2][0].ResTarget.val.A_Const.val.String.str).to.eq('');
expect(selectedDatas[0][0].ResTarget.val.A_Const.val.Integer.ival).to.eq(
1
);
expect(selectedDatas[1][0].ResTarget.val.A_Const.val).to.have.property(
"Null"
);
expect(selectedDatas[2][0].ResTarget.val.A_Const.val.String.str).to.eq(
""
);
expect(selectedDatas[3]).to.have.lengthOf(2);

@@ -33,13 +41,13 @@ });

"stmt.SelectStmt.targetList[0].ResTarget.location",
"stmt.SelectStmt.targetList[0].ResTarget.val.A_Const.location"
"stmt.SelectStmt.targetList[0].ResTarget.val.A_Const.location",
];
const removeChangedProps = (stmt) => omit(stmt, changedProps);
expect(res.stmts.map(removeChangedProps)).to.deep.eq([
...(query.parseQuerySync("select 1;").stmts.map(removeChangedProps)),
...(query.parseQuerySync("select null;").stmts.map(removeChangedProps))
...query.parseQuerySync("select 1;").stmts.map(removeChangedProps),
...query.parseQuerySync("select null;").stmts.map(removeChangedProps),
]);
});
it('should not parse a bogus query', () => {
expect(() => query.parseQuerySync('NOT A QUERY')).to.throw(Error);
it("should not parse a bogus query", () => {
expect(() => query.parseQuerySync("NOT A QUERY")).to.throw(Error);
});

@@ -50,3 +58,3 @@ });

it("should return a promise resolving to same result", async () => {
const testQuery = 'select * from john;';
const testQuery = "select * from john;";
const resPromise = query.parseQuery(testQuery);

@@ -59,15 +67,58 @@ const res = await resPromise;

it('should reject on bogus queries', async () => {
return query.parseQuery("NOT A QUERY").then(() => {
throw new Error("should have rejected");
}, (e) => {
expect(e).instanceof(Error);
expect(e.message).to.match(/NOT/);
it("should reject on bogus queries", async () => {
return query.parseQuery("NOT A QUERY").then(
() => {
throw new Error("should have rejected");
},
(e) => {
expect(e).instanceof(Error);
expect(e.message).to.match(/NOT/);
}
);
});
});
describe("Fingerprint", () => {
context("sync", () => {
it("should not fingerprint a bogus query", () => {
expect(() => query.fingerprintSync("NOT A QUERY")).to.throw(Error);
});
it("should fingerprint a query", () => {
const queries = ["select 1", "select null", "select ''", "select a, b"];
const results = queries.map(query.fingerprintSync);
results.forEach((res) => {
expect(res).to.have.lengthOf(16);
});
});
});
})
context("async", () => {
it("should not fingerprint a bogus query", () => {
return query.fingerprint("NOT A QUERY").then(
() => {
throw new Error("should have rejected");
},
(e) => {
expect(e).instanceof(Error);
expect(e.message).to.match(/NOT/);
}
);
});
it("should fingerprint a query", async () => {
const queries = ["select 1", "select null", "select ''", "select a, b"];
const results = await Promise.all(queries.map(query.fingerprint));
results.forEach((res) => {
expect(res).to.have.lengthOf(16);
});
});
});
});
});
describe('PlPgSQL (async)', () => {
it('should parse a function', async () => {
describe("PlPgSQL (async)", () => {
it("should parse a function", async () => {
const testFunction = `

@@ -74,0 +125,0 @@ CREATE FUNCTION t() RETURNS trigger AS

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc