Skip to content
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
3 changes: 3 additions & 0 deletions lib/make/makeJoinForPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
66 changes: 42 additions & 24 deletions test/bug-fix-tests/bug-fix.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
]
}
},
"current-date": {
"case1": {
"expectedResults": [
{
"Today": "$date-placeholder",
"Today2": "$date-placeholder"
}
]
}
},
"join-fn": {
"case1": {
"expectedResults": [
Expand Down Expand Up @@ -629,20 +619,6 @@
]
}
},
"current_date": {
"case1": {
"expectedResults": [
{
"id": 2,
"orderDate": "$date-placeholder"
},
{
"id": 5,
"orderDate": "$date-placeholder"
}
]
}
},
"unique": {
"case1": {
"expectedResults": [
Expand Down Expand Up @@ -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": {
Expand Down
48 changes: 32 additions & 16 deletions test/bug-fix-tests/bug-fix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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,
Expand All @@ -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 () => {
Expand Down
Loading