Skip to content

Commit 3fe1f91

Browse files
author
Thomas Hansen
committed
Fix tests and update dependencies.
1 parent 8a5600d commit 3fe1f91

File tree

4 files changed

+81
-152
lines changed

4 files changed

+81
-152
lines changed

package-lock.json

+73-144
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "mongo-query-to-postgres-jsonb",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Converts MongoDB queries to postgresql queries for jsonb fields.",
55
"main": "index.js",
66
"directories": {
77
"test": "test"
88
},
99
"dependencies": {},
1010
"devDependencies": {
11-
"chai": "^3.5.0",
12-
"mocha": "^3.2.0"
11+
"chai": "^4.2.0",
12+
"mocha": "^5.2.0"
1313
},
1414
"repository": {
1515
"type": "git",

test/filter.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,17 @@ describe('$mod', function () {
176176

177177
describe('Match a Field Without Specifying Array Index', function () {
178178
it('basic case', function() {
179-
assert.equal("EXISTS (SELECT * FROM jsonb_array_elements(data->'courses') WHERE value->>'distance'='5K')", convert('data', { 'courses.distance': '5K' }, ['courses']))
179+
assert.equal("(data->'courses'->>'distance'='5K' OR EXISTS (SELECT * FROM jsonb_array_elements(data->'courses') WHERE jsonb_typeof(data->'courses')='array' AND value->>'distance'='5K'))", convert('data', { 'courses.distance': '5K' }, ['courses']))
180180
})
181181
it('direct match', function() {
182-
assert.equal('EXISTS (SELECT * FROM jsonb_array_elements(data->\'roles\') WHERE value #>>\'{}\'=\'Admin\')', convert('data', { 'roles': 'Admin' }, ['roles']))
182+
assert.equal('(data->>\'roles\'=\'Admin\' OR EXISTS (SELECT * FROM jsonb_array_elements(data->\'roles\') WHERE jsonb_typeof(data->\'roles\')=\'array\' AND value #>>\'{}\'=\'Admin\'))', convert('data', { 'roles': 'Admin' }, ['roles']))
183183
})
184184
it('$in', function() {
185-
assert.equal("EXISTS (SELECT * FROM jsonb_array_elements(data->'roles') WHERE value #>>'{}' IN ('Test', 'Admin'))", convert('data', { 'roles': { $in: ["Test", "Admin"] } }, ['roles']))
185+
assert.equal("(data->>'roles' IN ('Test', 'Admin') OR EXISTS (SELECT * FROM jsonb_array_elements(data->'roles') WHERE jsonb_typeof(data->'roles')='array' AND value #>>'{}' IN ('Test', 'Admin')))", convert('data', { 'roles': { $in: ["Test", "Admin"] } }, ['roles']))
186186
})
187187
})
188188
describe('special cases', function () {
189189
it('should return true when passed no parameters', function() {
190190
assert.equal('TRUE', convert('data', {}))
191191
})
192-
})
192+
})

test/update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('update: ', function() {
5353
assert.equal(convertUpdate('data', { $rename: { current: 'newN' } }), 'jsonb_set(data,\'{newN}\',data->\'current\') #- \'{current}\'')
5454
})
5555
it('$pull', function() {
56-
assert.equal(convertUpdate('data', { $pull: { cities: 'LA' } }), 'array_remove(ARRAY(SELECT value FROM jsonb_array_elements(data->\'cities\')),\'"LA"\')')
56+
assert.equal(convertUpdate('data', { $pull: { cities: 'LA' } }), 'jsonb_set(data,\'{cities}\',to_jsonb(ARRAY(SELECT value FROM jsonb_array_elements(data->\'cities\') WHERE NOT value #>>\'{}\'=\'LA\')))')
5757
})
5858
it('$push', function() {
5959
assert.equal(convertUpdate('data', { $push: { cities: 'LA' } }), 'jsonb_set(data,\'{cities}\',to_jsonb(array_append(ARRAY(SELECT value FROM jsonb_array_elements(data->\'cities\')),\'"LA"\')))')

0 commit comments

Comments
 (0)