From 76000f8fa11dde2f67efdb22a87c4644ea49f9eb Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 30 Jan 2021 19:58:15 +0100 Subject: :sparkles: Util --- src/test/rethink_test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/rethink_test.ts (limited to 'src/test/rethink_test.ts') diff --git a/src/test/rethink_test.ts b/src/test/rethink_test.ts new file mode 100644 index 00000000..d1470515 --- /dev/null +++ b/src/test/rethink_test.ts @@ -0,0 +1,34 @@ +import { r } from "rethinkdb-ts"; + +async function main() { + const connection = await r.connect({ port: 28015 }); + + const db = r.db("test"); + const cursor = await db + .table("guilds") + .get(0) + .changes({ squash: true }) + .map(function (row) { + return row("old_val") + .keys() + .setUnion(row("new_val").keys()) + .concatMap(function (key) { + return r.branch( + row("old_val")(key).ne(row("new_val")(key)).default(true), + [[key, row("new_val")(key).default(null)]], + [] + ); + }) + .coerceTo("object"); + }) + .run(connection); + + console.log("each"); + cursor.each(function (err, row) { + if (err) throw err; + console.log(row); + }); + console.log("eachend"); +} + +main(); -- cgit 1.5.1