rethinkdbdash
Advanced tools
Comparing version 1.11.8 to 1.12.0
@@ -121,3 +121,3 @@ var net = require('net'); | ||
if (typeof this.rejectMap[token] === "function") { | ||
this.rejectMap[token](new Error.ReqlCompileError(pb.makeAtom(response, this.query[token], response))); | ||
this.rejectMap[token](new Error.ReqlCompileError(pb.makeAtom(response), this.query[token], response)); | ||
} | ||
@@ -124,0 +124,0 @@ |
@@ -69,5 +69,31 @@ var helper = require(__dirname+"/helper.js"); | ||
function ReqlCompileError(message) { | ||
function ReqlCompileError(message, query, frames) { | ||
Error.captureStackTrace(this, ReqlCompileError); | ||
this.message = message; | ||
if ((query) && (frames)) { | ||
this.message += " in:\n"; | ||
frames = frames.backtrace.frames; | ||
if (frames) this.frames = frames.slice(0); | ||
//this.frames = JSON.stringify(frames, null, 2); | ||
var backtrace = generateBacktrace(query, 0, null, frames, {indent: 0, extra: 0}); | ||
var queryLines = backtrace.str.split('\n'); | ||
var carrotLines = backtrace.car.split('\n'); | ||
for(var i=0; i<queryLines.length; i++) { | ||
this.message += queryLines[i]+"\n"; | ||
if (carrotLines[i].match(/\^/)) { | ||
var pos = queryLines[i].match(/[^\s]/); | ||
if ((pos) && (pos.index)) { | ||
this.message += space(pos.index)+carrotLines[i].slice(pos.index)+"\n"; | ||
} | ||
else { | ||
this.message += carrotLines[i]+"\n"; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
@@ -152,5 +178,10 @@ ReqlCompileError.prototype = new Error(); | ||
COUNT: "count", | ||
SUM: "sum", | ||
AVG: "avg", | ||
MIN: "min", | ||
MAX: "max", | ||
OBJECT: "object", | ||
DISTINCT: "distinct", | ||
GROUPED_MAP_REDUCE: "groupedMapReduce", | ||
GROUPBY: "groupBy", | ||
GROUP: "group", | ||
UNGROUP: "ungroup", | ||
CONTAINS: "contains", | ||
@@ -175,2 +206,4 @@ IMPLICIT_VAR: "row", | ||
MATCH: "match", | ||
UPCASE: "upcase", | ||
DOWNCASE: "downcase", | ||
ADD: "add", | ||
@@ -552,50 +585,2 @@ SUB: "sub", | ||
return result; | ||
}, | ||
GROUPBY: function(term, index, father, frames, options) { | ||
var result = { | ||
str: "", | ||
car: "" | ||
}; | ||
var backtrace, underline, currentFrame; | ||
underline = Array.isArray(frames) && (frames.length === 0); | ||
if (Array.isArray(frames)) currentFrame = frames.shift(); | ||
if ((currentFrame != null) && (currentFrame.pos === 0)) { | ||
backtrace = generateBacktrace(term.args[0], 0, term, frames, options); | ||
} | ||
else { | ||
backtrace = generateBacktrace(term.args[0], 0, term, null, options); | ||
} | ||
result.str += backtrace.str; | ||
result.car += backtrace.car; | ||
carify(result, ".groupBy(", underline); | ||
if ((currentFrame != null) && (currentFrame.pos === 1)) { | ||
backtrace = generateBacktrace(term.args[1], 1, term, frames, {indent: options.indent, noBracket: true}); | ||
} | ||
else { | ||
backtrace = generateBacktrace(term.args[1], 1, term, null, {indent: options.indent, noBracket: true}); | ||
} | ||
result.str += backtrace.str; | ||
result.car += backtrace.car; | ||
carify(result, ", ", underline); | ||
//TODO Could parse the object to rebuild r.count/r.avg/r.sum... sub 1.12 discard these... | ||
if ((currentFrame != null) && (currentFrame.pos === 2)) { | ||
backtrace = generateBacktrace(term.args[2], 2, term, frames, options); | ||
} | ||
else { | ||
backtrace = generateBacktrace(term.args[2], 2, term, null, options); | ||
} | ||
result.str += backtrace.str; | ||
result.car += backtrace.car; | ||
carify(result, ")", underline); | ||
if (underline) result.car = result.str.replace(/./g, '^'); | ||
return result; | ||
} | ||
@@ -602,0 +587,0 @@ } |
@@ -259,12 +259,7 @@ var Promise = require("bluebird"); | ||
r.prototype.object = function() { | ||
var term = new Term(this); | ||
return term.object.apply(term, helper.toArray(arguments)); | ||
} | ||
r.prototype.count = new Term(this).expr({COUNT: true}); | ||
r.prototype.avg = function(field) { | ||
Term.prototype._arity(arguments, 1, 'r.avg', this); | ||
return new Term(this).expr({AVG: field}) | ||
}; | ||
r.prototype.sum = function(field) { | ||
Term.prototype._arity(arguments, 1, 'r.sum', this); | ||
return new Term(this).expr({SUM: field}) | ||
}; | ||
@@ -271,0 +266,0 @@ r.prototype.Error = Error; |
@@ -19,13 +19,18 @@ var helper = require(__dirname+"/helper.js"); | ||
for(var i=0; i<obj.length; i++) { | ||
obj[i] = pb.convertPseudoType(obj[i]); | ||
obj[i] = pb.convertPseudoType(obj[i], options); | ||
} | ||
} | ||
else if (helper.isPlainObject(obj)) { | ||
if (obj.$reql_type$ === "TIME") { | ||
if (obj.epoch_time != null) { | ||
obj = new Date(obj.epoch_time*1000); | ||
if ((options.timeFormat != 'raw') && (obj.$reql_type$ === "TIME")) { | ||
obj = new Date(obj.epoch_time*1000); | ||
} | ||
else if ((options.groupFormat != 'raw') && (obj.$reql_type$ === "GROUPED_DATA")) { | ||
var result = []; | ||
for(var i=0; i<obj.data.length; i++) { | ||
result.push({ | ||
group: obj.data[i][0], | ||
reduction: obj.data[i][1], | ||
}) | ||
} | ||
else { | ||
throw new Error.ReqlDriverError("Pseudo-type TIME"+obj+" is missing the field epoch_time"); | ||
} | ||
obj = result; | ||
} | ||
@@ -35,3 +40,3 @@ else{ | ||
if (obj.hasOwnProperty(key)) { | ||
obj[key] = pb.convertPseudoType(obj[key]); | ||
obj[key] = pb.convertPseudoType(obj[key], options); | ||
} | ||
@@ -84,13 +89,11 @@ } | ||
var obj = pb.makeDatum(response.response[0], options); | ||
if ((options == null) || (options.timeFormat != 'raw')) obj = pb.convertPseudoType(obj); | ||
return obj; | ||
options = options || {}; | ||
return pb.convertPseudoType(obj, options); | ||
} | ||
pb.makeSequence = function(response, options) { | ||
var result = []; | ||
options = options || {}; | ||
for(var i=0; i<response.response.length; i++) { | ||
result.push(pb.makeDatum(response.response[i], options)); | ||
} | ||
if ((options == null) || (options.timeFormat != 'raw')) result = pb.convertPseudoType(result); | ||
return result; | ||
@@ -97,0 +100,0 @@ } |
{ | ||
"name": "rethinkdbdash", | ||
"version": "1.11.8", | ||
"version": "1.12.0", | ||
"description": "A Node.js driver for RethinkDB with promises and a connection pool", | ||
@@ -10,3 +10,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "mocha --harmony-generators -t 10000" | ||
"test": "mocha --harmony-generators -t 20000" | ||
}, | ||
@@ -13,0 +13,0 @@ "repository": { |
@@ -32,3 +32,3 @@ rethinkdbdash | ||
```js | ||
var Promise = require('blubird'); | ||
var Promise = require('bluebird'); | ||
var r = require('rethinkdbdash')(); | ||
@@ -35,0 +35,0 @@ |
@@ -237,3 +237,3 @@ var config = require(__dirname+'/config.js'); | ||
catch(e) { | ||
if (e.message === "Unrecognized option `db` in `run`. Available options are useOutdated <bool>, durability <string>, noreply <bool>, timeFormat <string>, profile <bool>.") { | ||
if (e.message === "Unrecognized option `db` in `run`. Available options are useOutdated <bool>, durability <string>, noreply <bool>, timeFormat <string>, groupFormat: <string>, profile <bool>.") { | ||
done(); | ||
@@ -277,3 +277,17 @@ } | ||
It("`groupFormat` should work", function* (done) { | ||
try { | ||
result = yield r.expr([{name: "Michel", grownUp: true},{name: "Laurent", grownUp: true}, | ||
{name: "Sophie", grownUp: true},{name: "Luke", grownUp: false},{name: "Mino", grownUp: false}]).group('grownUp').run(connection, {groupFormat: "raw"}); | ||
assert.deepEqual(result, { "$reql_type$": "GROUPED_DATA", "data": [ [ false, [ { "grownUp": false, "name": "Luke" }, { "grownUp": false, "name": "Mino" } ] ], [ true, [ { "grownUp": true, "name": "Michel" }, { "grownUp": true, "name": "Laurent" }, { "grownUp": true, "name": "Sophie" } ] ] ] }) | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
It("`profile` should work", function* (done) { | ||
@@ -280,0 +294,0 @@ try{ |
@@ -41,19 +41,2 @@ var config = require(__dirname+'/config.js'); | ||
}) | ||
It("`reduce` should work -- base ", function* (done) { | ||
try { | ||
result = yield r.expr([0, 1, 2, 3, 4, 5]).reduce( function(left, right) { return left.add(right) }, 11).run(); | ||
assert(result > 25); | ||
result = yield r.expr([1]).reduce( function(left, right) { return left.add(right) }, 11).run(); | ||
assert.equal(result, 12); | ||
result = yield r.expr([]).reduce( function(left, right) { return left.add(right) }, 11).run(); | ||
assert.equal(result, 11); | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
It("`reduce` should throw if no argument has been passed", function* (done) { | ||
@@ -64,3 +47,3 @@ try { | ||
catch(e) { | ||
if (e.message === "`reduce` takes at least 1 argument, 0 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
if (e.message === "`reduce` takes 1 argument, 0 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
done() | ||
@@ -99,13 +82,12 @@ } | ||
}) | ||
It("`groupedMapReduce` should work -- no base ", function* (done) { | ||
It("`group` should work ", function* (done) { | ||
try { | ||
result = yield r.expr([{g: 0, val: 2}, {g: 0, val: 3}, {g: 1, val: 10}, {g: 1, val: 20}, {g:2, val: 3}]).groupedMapReduce( | ||
function(doc) { return doc("g") }, | ||
function(doc) { return doc("val") }, | ||
function(left, right) { return left.add(right) }).orderBy("group").run(); | ||
result = yield r.expr([{name: "Michel", grownUp: true},{name: "Laurent", grownUp: true}, | ||
{name: "Sophie", grownUp: true},{name: "Luke", grownUp: false},{name: "Mino", grownUp: false}]).group('grownUp').run(); | ||
result = yield result.toArray(); | ||
assert.deepEqual(result, [{group: 0, reduction: 5}, {group: 1, reduction: 30}, {group: 2, reduction: 3}]) | ||
result.sort(); | ||
done() | ||
assert.deepEqual(result, [ { "group": false, "reduction": [ { "grownUp": false, "name": "Luke" }, { "grownUp": false, "name": "Mino" } ] }, { "group": true, "reduction": [ { "grownUp": true, "name": "Michel" }, { "grownUp": true, "name": "Laurent" }, { "grownUp": true, "name": "Sophie" } ] } ]) | ||
done(); | ||
} | ||
@@ -116,15 +98,10 @@ catch(e) { | ||
}) | ||
It("`groupedMapReduce` should work -- base ", function* (done) { | ||
It("`groupFormat` should work -- with raw", function* (done) { | ||
try { | ||
result = yield r.expr([{g: 0, val: 2}, {g: 0, val: 3}, {g: 1, val: 10}, {g: 1, val: 20}, {g:2, val: 3}]).groupedMapReduce( | ||
function(doc) { return doc("g") }, | ||
function(doc) { return doc("val") }, | ||
function(left, right) { return left.add(right) }, 10).orderBy("group").run(); | ||
result = yield result.toArray(); | ||
assert(result[0].reduction > 5); | ||
assert(result[1].reduction > 30); | ||
assert(result[2].reduction > 3); | ||
result = yield r.expr([{name: "Michel", grownUp: true},{name: "Laurent", grownUp: true}, | ||
{name: "Sophie", grownUp: true},{name: "Luke", grownUp: false},{name: "Mino", grownUp: false}]).group('grownUp').run({groupFormat: "raw"}); | ||
done() | ||
assert.deepEqual(result, { "$reql_type$": "GROUPED_DATA", "data": [ [ false, [ { "grownUp": false, "name": "Luke" }, { "grownUp": false, "name": "Mino" } ] ], [ true, [ { "grownUp": true, "name": "Michel" }, { "grownUp": true, "name": "Laurent" }, { "grownUp": true, "name": "Sophie" } ] ] ] }) | ||
done(); | ||
} | ||
@@ -135,34 +112,55 @@ catch(e) { | ||
}) | ||
It("`groupedMapReduce` should throw if no argument has been passed", function* (done) { | ||
It("`ungroup` should work ", function* (done) { | ||
try { | ||
result = yield r.db(dbName).table(tableName).groupedMapReduce().run(); | ||
result = yield r.expr([{name: "Michel", grownUp: true},{name: "Laurent", grownUp: true}, | ||
{name: "Sophie", grownUp: true},{name: "Luke", grownUp: false},{name: "Mino", grownUp: false}]).group('grownUp').ungroup().run(); | ||
result = yield result.toArray(); | ||
result.sort(); | ||
assert.deepEqual(result, [ { "group": false, "reduction": [ { "grownUp": false, "name": "Luke" }, { "grownUp": false, "name": "Mino" } ] }, { "group": true, "reduction": [ { "grownUp": true, "name": "Michel" }, { "grownUp": true, "name": "Laurent" }, { "grownUp": true, "name": "Sophie" } ] } ]) | ||
done(); | ||
} | ||
catch(e) { | ||
if (e.message === "`groupedMapReduce` takes at least 3 arguments, 0 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
done() | ||
} | ||
else { | ||
done(e); | ||
} | ||
done(e); | ||
} | ||
}) | ||
It("`groupedMapReduce` should throw if just one argument has been passed", function* (done) { | ||
try { | ||
result = yield r.db(dbName).table(tableName).groupedMapReduce(r.row).run(); | ||
It("`contains` should work ", function* (done) { | ||
try{ | ||
result = yield r.expr([1,2,3]).contains(2).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(1, 2).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(1, 5).run(); | ||
assert.equal(result, false); | ||
result = yield r.expr([1,2,3]).contains(function(doc) { return doc.eq(1) }).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(r.row.eq(1)).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(r.row.eq(1), r.row.eq(2)).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(r.row.eq(1), r.row.eq(5)).run(); | ||
assert.equal(result, false); | ||
done(); | ||
} | ||
catch(e) { | ||
if (e.message === "`groupedMapReduce` takes at least 3 arguments, 1 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
done() | ||
} | ||
else { | ||
done(e); | ||
} | ||
done(e); | ||
} | ||
}) | ||
It("`groupedMapReduce` should throw if just two argument has been passed", function* (done) { | ||
It("`contains` should throw if called without arguments", function* (done) { | ||
try { | ||
result = yield r.db(dbName).table(tableName).groupedMapReduce(r.row, r.row).run(); | ||
result = yield r.db(dbName).table(tableName).contains().run(); | ||
} | ||
catch(e) { | ||
if (e.message === "`groupedMapReduce` takes at least 3 arguments, 2 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
if (e.message === "`contains` takes at least 1 argument, 0 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
done() | ||
@@ -176,11 +174,6 @@ } | ||
It("`groupBy` should work -- single field ", function* (done) { | ||
It("`sum` should work ", function* (done) { | ||
try{ | ||
result = yield r.expr([{g: 0, val: 2}, {g: 0, val: 3}, {g: 1, val: 10}, {g: 1, val: 20}, {g:2, val: 3}]).groupBy("g", r.count).orderBy("g").run(); | ||
result = yield result.toArray(); | ||
assert.deepEqual(result, [ | ||
{group: {g: 0}, reduction:2 }, | ||
{group: {g: 1 }, reduction: 2}, | ||
{group: {g: 2 }, reduction: 1} | ||
]); | ||
result = yield r.expr([1,2,3]).sum().run(); | ||
assert.equal(result, 6); | ||
@@ -193,30 +186,21 @@ done(); | ||
}) | ||
It("`groupBy` should work -- multiple fields ", function* (done) { | ||
try{ | ||
result = yield r.expr([{g: 0, gg: 0, val: 2}, {g: 0, gg: 0, val: 3}, {g: 1, gg: 0, val: 10}, {g: 1, gg: 1, val: 20}, {g:2, gg: 3, val: 3}]).groupBy("g", "gg", r.count).orderBy("g").run(); | ||
result = yield result.toArray(); | ||
assert.deepEqual(result, [ | ||
{"group": {"g": 0,"gg": 0},"reduction": 2}, | ||
{"group": {"g": 1,"gg": 0},"reduction": 1}, | ||
{"group": {"g": 1,"gg": 1},"reduction": 1}, | ||
{"group": {"g": 2,"gg": 3},"reduction": 1} | ||
]) | ||
done(); | ||
It("`sum` should throw if called with arguments", function* (done) { | ||
try { | ||
result = yield r.expr([1,2,3]).sum(1).run(); | ||
} | ||
catch(e) { | ||
done(e); | ||
if (e.message === "`sum` takes 0 argument, 1 provided after:\nr.expr([1, 2, 3])") { | ||
done() | ||
} | ||
else { | ||
done(e); | ||
} | ||
} | ||
}) | ||
It("`groupBy` should work -- with a field sometimes undefined ", function* (done) { | ||
It("`avg` should work ", function* (done) { | ||
try{ | ||
result = yield r.expr([{g: 0, gg: 0, optionalField: true, val: 2}, {g: 0, gg: 0, val: 3}, {g: 1, gg: 0, val: 10}, {g: 1, gg: 1, val: 20}, {g:2, gg: 3, val: 3}]).groupBy("g", "optionalField", r.count).orderBy("g").run(); | ||
result = yield result.toArray(); | ||
assert.deepEqual(result, [ | ||
{"group": {"g": 0}, "reduction": 1}, | ||
{"group": {"g": 0, "optionalField": true}, "reduction": 1}, | ||
{"group": {"g": 1}, "reduction": 2}, | ||
{"group": {"g": 2}, "reduction": 1} | ||
]) | ||
result = yield r.expr([1,2,3]).avg().run(); | ||
assert.equal(result, 2); | ||
@@ -229,20 +213,9 @@ done(); | ||
}) | ||
It("`groupBy` should work -- same field multiple times ", function* (done) { | ||
try{ | ||
result = yield r.expr([{g: 0, val: 2}, {g: 0, val: 3}, {g: 1, val: 10}, {g: 1, val: 20}, {g:2, val: 3}]).groupBy("g", "g", r.count).orderBy("g").run(); | ||
result = yield result.toArray(); | ||
assert.deepEqual(result, [{group: {g: 0}, reduction:2 }, {group: {g: 1 }, reduction: 2}, {group: {g: 2 }, reduction: 1}]); | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
It("`groupBy` should throw if no argument has been passed", function* (done) { | ||
It("`avg` should throw if called with arguments", function* (done) { | ||
try { | ||
result = yield r.db(dbName).table(tableName).groupBy().run(); | ||
result = yield r.expr([1,2,3]).avg(1).run(); | ||
} | ||
catch(e) { | ||
if (e.message === "`groupBy` takes at least 2 arguments, 0 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
if (e.message === "`avg` takes 0 argument, 1 provided after:\nr.expr([1, 2, 3])") { | ||
done() | ||
@@ -255,8 +228,21 @@ } | ||
}) | ||
It("`groupBy` should throw if no aggregator has been passed", function* (done) { | ||
It("`min` should work ", function* (done) { | ||
try{ | ||
result = yield r.expr([1,2,3]).min().run(); | ||
assert.equal(result, 1); | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
It("`min` should throw if called with arguments", function* (done) { | ||
try { | ||
result = yield r.db(dbName).table(tableName).groupBy("foo").run(); | ||
result = yield r.expr([1,2,3]).min(1).run(); | ||
} | ||
catch(e) { | ||
if (e.message === "`groupBy` takes at least 2 arguments, 1 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
if (e.message === "`min` takes 0 argument, 1 provided after:\nr.expr([1, 2, 3])") { | ||
done() | ||
@@ -270,25 +256,7 @@ } | ||
It("`contains` should work ", function* (done) { | ||
It("`max` should work ", function* (done) { | ||
try{ | ||
result = yield r.expr([1,2,3]).contains(2).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).max().run(); | ||
assert.equal(result, 3); | ||
result = yield r.expr([1,2,3]).contains(1, 2).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(1, 5).run(); | ||
assert.equal(result, false); | ||
result = yield r.expr([1,2,3]).contains(function(doc) { return doc.eq(1) }).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(r.row.eq(1)).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(r.row.eq(1), r.row.eq(2)).run(); | ||
assert.equal(result, true); | ||
result = yield r.expr([1,2,3]).contains(r.row.eq(1), r.row.eq(5)).run(); | ||
assert.equal(result, false); | ||
done(); | ||
@@ -300,8 +268,9 @@ } | ||
}) | ||
It("`contains` should throw if called without arguments", function* (done) { | ||
It("`max` should throw if called with arguments", function* (done) { | ||
try { | ||
result = yield r.db(dbName).table(tableName).contains().run(); | ||
result = yield r.expr([1,2,3]).max(1).run(); | ||
} | ||
catch(e) { | ||
if (e.message === "`contains` takes at least 1 argument, 0 provided after:\nr.db(\""+dbName+"\").table(\""+tableName+"\")") { | ||
if (e.message === "`max` takes 0 argument, 1 provided after:\nr.expr([1, 2, 3])") { | ||
done() | ||
@@ -314,1 +283,3 @@ } | ||
}) | ||
@@ -453,1 +453,14 @@ var config = require(__dirname+'/config.js'); | ||
It("`epochTime` should work", function* (done) { | ||
try { | ||
now = new Date(); | ||
result = yield r.epochTime(now.getTime()/1000).run({timeFormat: "raw"}); | ||
assert.equal(result.$reql_type$, "TIME") | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
@@ -69,3 +69,5 @@ var config = require(__dirname+'/config.js'); | ||
try { | ||
result = yield r.db(dbName).table(tableName).replace(r.row.merge({idCopyReplace: r.row("id")})).run(); | ||
result = yield r.db(dbName).table(tableName).replace(function(doc) { | ||
return doc.merge({idCopyReplace: doc("id")}) | ||
}).run(); | ||
assert.equal(result.replaced, 1); | ||
@@ -172,3 +174,21 @@ | ||
}) | ||
It("`merge` should take an anonymous function", function* (done) { | ||
try { | ||
result = yield r.expr({a: 0}).merge(function(doc) { | ||
return {b: doc("a").add(1)} | ||
}).run(); | ||
assert.deepEqual(result, {a: 0, b: 1}); | ||
result = yield r.expr({a: 0}).merge({ | ||
b: r.row("a").add(1) | ||
}).run(); | ||
assert.deepEqual(result, {a: 0, b: 1}); | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
It("`literal` should work", function* (done) { | ||
@@ -623,1 +643,13 @@ try { | ||
}) | ||
It("`object` should work", function* (done) { | ||
try { | ||
result = yield r.object("a", 1, r.expr("2"), "foo").run(); | ||
assert.deepEqual(result, {"a": 1, "2": "foo"}); | ||
done() | ||
} | ||
catch(e) { | ||
console.log(e) | ||
done(e); | ||
} | ||
}) |
@@ -103,3 +103,3 @@ var config = require(__dirname+'/config.js'); | ||
var result = yield r.db(dbName).tableCreate(tableName, {cacheSize: 1024*1024*1024, durability: "soft", primaryKey: "foo"}).run(); | ||
var result = yield r.db(dbName).tableCreate(tableName, {durability: "soft", primaryKey: "foo"}).run(); | ||
assert.deepEqual(result, {created:1}); // We can't really check other parameters... | ||
@@ -123,3 +123,3 @@ | ||
catch(e) { | ||
if (e.message === 'Unrecognized option `nonValidArg` in `tableCreate`. Available options are primaryKey <string>, durability <string>, cacheSize <nunber>, datancenter <string>.') { | ||
if (e.message === 'Unrecognized option `nonValidArg` in `tableCreate`. Available options are primaryKey <string>, durability <string>, datancenter <string>.') { | ||
done() | ||
@@ -150,3 +150,3 @@ } | ||
catch(e) { | ||
if (e.message.match(/Database name `-_-` invalid \(Use A-Za-z0-9_ only\)/)) { done(); } | ||
if (e.message.match(/Table name `-_-` invalid \(Use A-Za-z0-9_ only\)/)) { done(); } | ||
else { done(e); } | ||
@@ -153,0 +153,0 @@ } |
@@ -5,2 +5,3 @@ var config = require(__dirname+'/config.js'); | ||
var assert = require('assert'); | ||
var Promise = require('bluebird'); | ||
@@ -153,2 +154,7 @@ var uuid = util.uuid; | ||
// Yield one second -- See https://github.com/rethinkdb/rethinkdb/issues/2170 | ||
var p = new Promise(function(resolve, reject) { | ||
setTimeout(function() { resolve() }, 1000) | ||
}); | ||
yield p; | ||
result = yield r.db(dbName).table(tableName).getAll(10, {index: "field"}).run(); | ||
@@ -174,2 +180,8 @@ assert(result); | ||
// Yield one second -- See https://github.com/rethinkdb/rethinkdb/issues/2170 | ||
var p = new Promise(function(resolve, reject) { | ||
setTimeout(function() { resolve() }, 1000) | ||
}); | ||
yield p; | ||
result = yield r.db(dbName).table(tableName).getAll(11, {index: "fieldAddOne"}).run(); | ||
@@ -176,0 +188,0 @@ assert(result); |
@@ -36,1 +36,22 @@ var config = require(__dirname+'/config.js'); | ||
}) | ||
It("`upcase` should work", function* (done) { | ||
try { | ||
var result = yield r.expr("helLo").upcase().run(); | ||
assert.equal(result, "HELLO"); | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
It("`downcase` should work", function* (done) { | ||
try { | ||
var result = yield r.expr("HElLo").downcase().run(); | ||
assert.equal(result, "hello"); | ||
done(); | ||
} | ||
catch(e) { | ||
done(e); | ||
} | ||
}) | ||
@@ -12,3 +12,3 @@ var Promise = require('bluebird'); | ||
var query; | ||
query = 'r.table("test").map( function(doc) { return r.expr(1).add("eh")})' | ||
query = 'r.expr(1).do(function(v) { return r.object("a") })' | ||
@@ -15,0 +15,0 @@ Promise.coroutine(function* () { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
434076
12997
38