arangolize
Advanced tools
Comparing version
@@ -96,3 +96,19 @@ "use strict"; | ||
} else { | ||
query(` return MERGE(instance, { @includeAs: DOCUMENT(instance[@includeAs]) }) \n), \n`); | ||
query(`let doc = MERGE(instance, { @includeAs: DOCUMENT(instance[@includeAs]) })`); | ||
if (include.where) { | ||
Object.keys(include.where).map((key, index) => { | ||
const variable = `${key}${index}`; | ||
const value = `${variable}value`; | ||
bindVars({ | ||
[variable]: key | ||
}); | ||
bindVars({ | ||
[value]: include.where[key] | ||
}); | ||
query(`\n filter doc.@includeAs.@${variable} == @${value}`); | ||
}); | ||
} | ||
query(`\n return doc)\n`); | ||
} | ||
@@ -149,16 +165,3 @@ } | ||
query` return instance ) \n`; // ends data = (...) | ||
query` return { | ||
data: ( | ||
for instance in data | ||
limit @skip, @limit | ||
`; | ||
if (attributes && !include) { | ||
bindVars({ | ||
attributes: attributes | ||
}); | ||
query` return KEEP(instance, @attributes) \n ), \n`; | ||
} else if (attributes && include) { | ||
if (attributes && include) { | ||
query`let atts = KEEP(instance, @attributes)`; | ||
@@ -169,8 +172,13 @@ | ||
_this.handleInclude(); | ||
} else { | ||
query` return instance ), \n`; | ||
} | ||
query` meta: { count: LENGTH(data) }`; | ||
query` \n }`; | ||
query` return { | ||
data: ( | ||
for instance in data | ||
limit @skip, @limit | ||
return instance | ||
), | ||
meta: { count: LENGTH(data) } | ||
} | ||
`; | ||
return { | ||
@@ -177,0 +185,0 @@ query: _this._query, |
42
index.js
@@ -76,3 +76,15 @@ import { autobind } from 'core-decorators' | ||
} else { | ||
query(` return MERGE(instance, { @includeAs: DOCUMENT(instance[@includeAs]) }) \n), \n`) | ||
query(`let doc = MERGE(instance, { @includeAs: DOCUMENT(instance[@includeAs]) })`) | ||
if (include.where) { | ||
Object.keys(include.where).map((key, index) => { | ||
const variable = `${key}${index}` | ||
const value = `${variable}value` | ||
bindVars({[variable]: key}) | ||
bindVars({[value]: include.where[key]}) | ||
query(`\n filter doc.@includeAs.@${variable} == @${value}`) | ||
}) | ||
} | ||
query(`\n return doc)\n`) | ||
} | ||
@@ -82,3 +94,3 @@ } | ||
async build () { | ||
let { where, attributes, sort, include } = this.props | ||
let { where, attributes, sort, include} = this.props | ||
const { query, bindVars } = this | ||
@@ -110,13 +122,3 @@ | ||
query` return instance ) \n` // ends data = (...) | ||
query` return { | ||
data: ( | ||
for instance in data | ||
limit @skip, @limit | ||
` | ||
if (attributes && !include) { | ||
bindVars({ attributes: attributes }) | ||
query` return KEEP(instance, @attributes) \n ), \n` | ||
} else if (attributes && include) { | ||
if (attributes && include) { | ||
query`let atts = KEEP(instance, @attributes)` | ||
@@ -126,10 +128,14 @@ this.handleInclude() | ||
this.handleInclude() | ||
} else { | ||
query` return instance ), \n` | ||
} | ||
query` meta: { count: LENGTH(data) }` | ||
query` return { | ||
data: ( | ||
for instance in data | ||
limit @skip, @limit | ||
return instance | ||
), | ||
meta: { count: LENGTH(data) } | ||
} | ||
` | ||
query` \n }` | ||
return { query: this._query, bindVars: this._bindVars } | ||
@@ -136,0 +142,0 @@ } |
@@ -17,1 +17,16 @@ import test from 'tape' | ||
}) | ||
/**/ | ||
test('should return query and bindVars', async (t) => { | ||
const { bindVars, query } = await arangolize({ | ||
collection: 'test', | ||
include: { | ||
as: 'user', | ||
where: { name: 'Noah', createdAt: "2017-09-05T12:05:30.166Z" } | ||
} | ||
}) | ||
t.ok(bindVars, 'should have bindVars') | ||
t.ok(query, 'should have query') | ||
t.end() | ||
}) |
{ | ||
"name": "arangolize", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"description": "Sequelize-like query-builder for ArangoDB", | ||
@@ -11,3 +11,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"prepublish": "./node_modules/.bin/babel index.js -d ./dist --ignore node_modules/ --ignore dist/" | ||
"prepublish": "./node_modules/.bin/babel index.js -d ./dist --ignore node_modules/ --ignore dist/", | ||
"test": "./node_modules/.bin/tape -r @babel/register index.test.js" | ||
}, | ||
@@ -19,4 +20,10 @@ "devDependencies": { | ||
"@babel/preset-env": "^7.0.0-beta.37", | ||
"@babel/preset-stage-0": "^7.0.0-beta.37" | ||
"@babel/preset-stage-0": "^7.0.0-beta.37", | ||
"@babel/register": "^7.0.0-beta.39", | ||
"tape": "^4.8.0" | ||
}, | ||
"dependencies": { | ||
"@babel/register": "^7.0.0-beta.39", | ||
"core-decorators": "^0.20.0" | ||
} | ||
} |
90890
675.64%7
16.67%324
9.09%2
Infinity%7
40%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added