From 9534aeb86360b8774a573cff98e3cf70679d70fa Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sun, 8 Jan 2023 23:24:55 -0500 Subject: [PATCH] Bump lru-cache dependency to ^7.14.1 Signed-off-by: Matthew Peveler --- .github/workflows/ci.yml | 2 +- index.js | 4 +-- package.json | 4 +-- test/example.js | 61 ++++++++++++++++++++++------------------ 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46e25ed..fc8032d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [6.x, 8.x, 10.x, 12.x, 14.x, 16.x, 18.x] + node-version: [12.x, 14.x, 16.x, 18.x] name: Node.js ${{ matrix.node-version }} diff --git a/index.js b/index.js index 527d723..3524ef5 100644 --- a/index.js +++ b/index.js @@ -65,8 +65,6 @@ function parse(query) { return [query]; }; -const EMPTY_LRU_FN = (key, value) => {}; - function createCompiler(config) { if (!config) config = {}; @@ -82,7 +80,7 @@ function createCompiler(config) { cache = config.cache; } if (config.cache !== false && !cache) { - cache = require('lru-cache')({ max: ncache, dispose: EMPTY_LRU_FN }); + cache = new (require('lru-cache'))({ max: ncache }); } function toArrayParams(tree, params) { diff --git a/package.json b/package.json index 4e8d8cc..1be4cde 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "placeholders" ], "engines": { - "node": ">=6.0.0" + "node": ">=12.0.0" }, "author": "Andrey Sidorov ", "files": [], @@ -27,6 +27,6 @@ "should": "^13.2.3" }, "dependencies": { - "lru-cache": "^4.1.3" + "lru-cache": "^7.14.1" } } diff --git a/test/example.js b/test/example.js index 4c2cc31..bb26332 100644 --- a/test/example.js +++ b/test/example.js @@ -5,7 +5,6 @@ const assert = require('assert'); require('should'); describe('given input query with named parameters', () => { - it('should build corresponding query with `?` placeholders and fill array of parameters from input object', () => { let query = 'Select users.json,EXISTS(Select 1 from moderators where moderators.id = :id) as is_moderator from users where users.id = :id and users.status = :status and users.complete_status = :complete_status'; @@ -33,38 +32,44 @@ describe('given input query with named parameters', () => { compile(query); }, /Named query contains placeholders, but parameters object is undefined/ - ); - }); + ); + }); - it('should replace ::name style placeholders with `??` placeholders', () => { + it('should replace ::name style placeholders with `??` placeholders', () => { + let query = 'normal placeholder :p1 and double semicolon ::p2'; + compile(query, {p1: 'test1', p2: 'test2'}) + .should.eql([ 'normal placeholder ? and double semicolon ??', [ 'test1', 'test2' ] ]); - let query = 'normal placeholder :p1 and double semicolon ::p2'; - compile(query, {p1: 'test1', p2: 'test2'}) - .should.eql([ 'normal placeholder ? and double semicolon ??', [ 'test1', 'test2' ] ]); + query = 'normal placeholder ::p1 and double semicolon :p2'; + compile(query, {p1: 'test1', p2: 'test2'}) + .should.eql([ 'normal placeholder ?? and double semicolon ?', [ 'test1', 'test2' ] ]); - query = 'normal placeholder ::p1 and double semicolon :p2'; - compile(query, {p1: 'test1', p2: 'test2'}) - .should.eql([ 'normal placeholder ?? and double semicolon ?', [ 'test1', 'test2' ] ]); + query = 'normal placeholder ::p2 and double semicolon :p1'; + compile(query, {p1: 'test1', p2: 'test2'}) + .should.eql([ 'normal placeholder ?? and double semicolon ?', [ 'test2', 'test1' ] ]); - query = 'normal placeholder ::p2 and double semicolon :p1'; - compile(query, {p1: 'test1', p2: 'test2'}) - .should.eql([ 'normal placeholder ?? and double semicolon ?', [ 'test2', 'test1' ] ]); + query = 'normal placeholder :p1 and double semicolon ::p2 test'; + compile(query, {p1: 'test1', p2: 'test2'}) + .should.eql([ 'normal placeholder ? and double semicolon ?? test', [ 'test1', 'test2' ] ]); + }); - query = 'normal placeholder :p1 and double semicolon ::p2 test'; - compile(query, {p1: 'test1', p2: 'test2'}) - .should.eql([ 'normal placeholder ? and double semicolon ?? test', [ 'test1', 'test2' ] ]); - }); + it('compiles the query the same twice', () => { + const query = 'SELECT * FROM foo WHERE id = :id'; + const expected = [ 'SELECT * FROM foo WHERE id = ?', [ 123 ] ]; + compile(query, { id: 123 }).should.eql(expected); + compile(query, { id: 123 }).should.eql(expected); }); +}); - describe('postgres-style toNumbered conversion', () => { - it('basic test', () => { - const toNumbered = require('..').toNumbered; - const query = 'SELECT usr.p_pause_stop_track(:doc_dtl_id, :plan_id, :wc_id, 20, :time_from)'; - toNumbered(query, { - doc_dtl_id: 123, - time_from: 345, - plan_id: 456, - wc_id: 678 - }).should.eql([ 'SELECT usr.p_pause_stop_track($1, $2, $3, 20, $4)', [ 123, 456, 678, 345 ]]); - }); +describe('postgres-style toNumbered conversion', () => { + it('basic test', () => { + const toNumbered = require('..').toNumbered; + const query = 'SELECT usr.p_pause_stop_track(:doc_dtl_id, :plan_id, :wc_id, 20, :time_from)'; + toNumbered(query, { + doc_dtl_id: 123, + time_from: 345, + plan_id: 456, + wc_id: 678 + }).should.eql([ 'SELECT usr.p_pause_stop_track($1, $2, $3, 20, $4)', [ 123, 456, 678, 345 ]]); }); +});