Comparing version 1.7.0 to 1.8.0
26
index.js
@@ -7,3 +7,2 @@ /*jshint browserify: true */ | ||
types = require('./types'), | ||
QB = {}, | ||
toArray, | ||
@@ -26,2 +25,27 @@ warn; | ||
function QB(obj) { | ||
if (typeof obj === 'string') { | ||
return QB.str(obj); | ||
} | ||
if (obj === null || obj === undefined) { | ||
return new types.NullLiteral(); | ||
} | ||
if (typeof obj === 'object') { | ||
if (obj instanceof Date) { | ||
return QB(JSON.stringify(obj)); | ||
} | ||
if (obj instanceof Array) { | ||
return new types.ListLiteral(obj.map(QB)); | ||
} | ||
var result = {}; | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
result[key] = QB(obj[key]); | ||
} | ||
} | ||
return new types.ObjectLiteral(result); | ||
} | ||
return types.autoCastToken(obj); | ||
} | ||
Object.keys(types._PartialStatement.prototype).forEach(function (key) { | ||
@@ -28,0 +52,0 @@ if (key === 'constructor') return; |
{ | ||
"name": "aqb", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "ArangoDB AQL query builder.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -63,2 +63,18 @@ # ArangoDB Query Builder | ||
## Auto-casting raw data | ||
By default, the query builder will attempt to interpret raw strings as identifiers or references or other kinds of expressions. This may not always be what you want, especially when handling raw untrusted data. | ||
As of version 1.8 you can now pass arbitrary data directly to the query builder itself and it will be translated to the equivalent AQL structure (e.g. strings will be strings, dates will be converted to JSON, arrays and objects will be translated recursively, and so on): | ||
```js | ||
var doc = { | ||
aString: "hello", | ||
aDate: new Date(), | ||
aNumber: 23, | ||
anArray: [1, 2, 3, "potato"] | ||
}; | ||
db._query(qb.insert(qb(doc)).into('my_collection')); | ||
``` | ||
## AQL Types | ||
@@ -65,0 +81,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63756
976
606