diff --git a/lib/make/makeJoinForPipeline.js b/lib/make/makeJoinForPipeline.js index 2d04a66..f53630a 100644 --- a/lib/make/makeJoinForPipeline.js +++ b/lib/make/makeJoinForPipeline.js @@ -118,6 +118,9 @@ function makeJoinPart(join, previousJoin, aliases, pipeline, context, ast) { const replacePaths = []; $json.walk(joinQuery, (val, path) => { if ($check.string(val) && val.startsWith('$$')) { + if (val === '$$NOW') { + return; + } const varName = val.substring(2).replace(/[.-]/g, '_'); if (join.as) { inputVars[varName] = `$${val.substring(2)}`; diff --git a/package.json b/package.json index 4b8aaeb..f6e88a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/noql", - "version": "4.1.19", + "version": "4.1.20", "description": "Convert SQL statements to mongo queries or aggregates", "main": "index.js", "files": [ diff --git a/test/bug-fix-tests/bug-fix.json b/test/bug-fix-tests/bug-fix.json index 04b96cb..a6565bd 100644 --- a/test/bug-fix-tests/bug-fix.json +++ b/test/bug-fix-tests/bug-fix.json @@ -18,16 +18,6 @@ ] } }, - "current-date": { - "case1": { - "expectedResults": [ - { - "Today": "$date-placeholder", - "Today2": "$date-placeholder" - } - ] - } - }, "join-fn": { "case1": { "expectedResults": [ @@ -629,20 +619,6 @@ ] } }, - "current_date": { - "case1": { - "expectedResults": [ - { - "id": 2, - "orderDate": "$date-placeholder" - }, - { - "id": 5, - "orderDate": "$date-placeholder" - } - ] - } - }, "unique": { "case1": { "expectedResults": [ @@ -845,6 +821,48 @@ } ] } + }, + "current-date": { + "case1": { + "expectedResults": [ + { + "Today": "$date-placeholder", + "Today2": "$date-placeholder" + } + ] + }, + "case2": { + "expectedResults": [ + { + "id": 2, + "orderDate": "$date-placeholder" + }, + { + "id": 5, + "orderDate": "$date-placeholder" + } + ] + }, + "case3": { + "expectedResults": [ + { + "id": 1, + "orderDate": null + }, + { + "id": 2, + "orderDate": "$date-placeholder" + }, + { + "id": 3, + "orderDate": null + }, + { + "id": 4, + "orderDate": null + } + ] + } } }, "scratchpad": { diff --git a/test/bug-fix-tests/bug-fix.test.js b/test/bug-fix-tests/bug-fix.test.js index 22ce7b4..29e9a7a 100644 --- a/test/bug-fix-tests/bug-fix.test.js +++ b/test/bug-fix-tests/bug-fix.test.js @@ -58,21 +58,6 @@ describe('bug-fixes', function () { }); }); }); - describe('currentDate', async () => { - it('should work with or without parentheses', async () => { - const queryString = ` - SELECT CURRENT_DATE() as Today, - current_date as Today2, - unset(_id) - FROM function-test-data - LIMIT 1`; - await queryResultTester({ - queryString: queryString, - casePath: 'bugfix.current-date.case1', - ignoreDateValues: true, - }); - }); - }); describe('join function', () => { it('should be able to join strings together with a symbol in a standard select', async () => { const queryString = ` @@ -751,6 +736,20 @@ describe('bug-fixes', function () { }); }); describe('Current_Date', () => { + it('should work with or without parentheses', async () => { + const queryString = ` + SELECT CURRENT_DATE() as Today, + current_date as Today2, + unset(_id) + FROM function-test-data + LIMIT 1`; + await queryResultTester({ + queryString: queryString, + casePath: 'bugfix.current-date.case1', + ignoreDateValues: true, + mode, + }); + }); it('should allow you to compare dates', async () => { const queryString = ` SELECT id, @@ -761,11 +760,28 @@ describe('bug-fixes', function () { `; await queryResultTester({ queryString: queryString, - casePath: 'bugfix.current_date.case1', + casePath: 'bugfix.current-date.case2', mode, ignoreDateValues: true, }); }); + it('should allow you to use current_date in the on clause', async () => { + const queryString = ` + SELECT o.id, + o.orderDate + FROM orders o + INNER JOIN inventory i on o.item = i.sku + AND o.orderDate <= CURRENT_DATE() + `; + await queryResultTester({ + queryString: queryString, + casePath: 'bugfix.current-date.case3', + mode, + ignoreDateValues: true, + unsetId: true, + outputPipeline: false, + }); + }); }); describe('unique', () => { it.skip('should get unique values', async () => {