Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump lru-cache dependency to ^7.14.1 #19

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ function parse(query) {
return [query];
};

const EMPTY_LRU_FN = (key, value) => {};

function createCompiler(config) {
if (!config)
config = {};
Expand All @@ -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 });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dispose method is optional for 7.x at least, and given that the function being passed in was a no-op, decided to remove it. Otherwise, debated on moving the require elsewhere given the need now to do a new call, but decided to leave it as is and just wrap in parentheses as needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason require is here instead top of the file to where its used is to avoid cost of loading LRU dependency in case where you have BYO cache library. I'm OK to leave as is but probably splitting into two lines and assigning to a variable could be more readable

}

function toArrayParams(tree, params) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"placeholders"
],
"engines": {
"node": ">=6.0.0"
"node": ">=12.0.0"
},
"author": "Andrey Sidorov <[email protected]>",
"files": [],
Expand All @@ -27,6 +27,6 @@
"should": "^13.2.3"
},
"dependencies": {
"lru-cache": "^4.1.3"
"lru-cache": "^7.14.1"
}
}
61 changes: 33 additions & 28 deletions test/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 ]]);
});
});