From 4601d7808dca83a2b13f90e41b1a892b53eab100 Mon Sep 17 00:00:00 2001 From: Alex Gorbatchev Date: Sun, 2 Oct 2016 13:12:18 -0700 Subject: [PATCH] [rethinkdb] Adds hasFields() --- rethinkdb/rethinkdb-tests.ts | 25 ++++++++++++++++++++----- rethinkdb/rethinkdb.d.ts | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/rethinkdb/rethinkdb-tests.ts b/rethinkdb/rethinkdb-tests.ts index 3397247854..edfc5cc485 100644 --- a/rethinkdb/rethinkdb-tests.ts +++ b/rethinkdb/rethinkdb-tests.ts @@ -2,17 +2,27 @@ import * as r from "rethinkdb"; -r.connect({ host: "localhost", port: 28015 }, function(err, conn) { +function errorAndCursorCallback(err: Error, cursor: r.Cursor): void {} +function cursorCallback(cursor: r.Cursor): void {} + +r.connect({ host: "localhost", port: 28015 }, function(err: Error, conn: r.Connection) { console.log("HI", err, conn); const testDb = r.db("test"); + r.table("players").hasFields("games_won").run(conn, errorAndCursorCallback); + r.table("players").hasFields({ "games_won": { "championships": true } }).run(conn, errorAndCursorCallback); + r.table("players").filter(r.row.hasFields("games_won").not()).run(conn, errorAndCursorCallback); + r.table("players").filter(r.row.hasFields({ "games_won": { "championships": true } }).not()).run(conn, errorAndCursorCallback); + testDb.tableCreate("users").run(conn, function(err, stuff) { const users = testDb.table("users"); users.insert({ name: "bob" }).run(conn, function() { }); + users.hasFields("foo_bar").run(conn, () => {}); + users.filter(function(doc?) { return doc("henry").eq("bob"); }) @@ -36,12 +46,17 @@ r.connect({ host: "localhost", port: 28015 }, function(err, conn) { }); // use promises instead of callbacks -r.connect({ host: "localhost", port: 28015 }).then(function(conn) { +r.connect({ host: "localhost", port: 28015 }).then(function(conn: r.Connection) { console.log("HI", conn); const testDb = r.db("test"); - testDb.tableCreate("users").run(conn).then(function(stuff) { + r.table("players").hasFields("games_won").run(conn).then(cursorCallback); + r.table("players").hasFields({ "games_won": { "championships": true } }).run(conn).then(cursorCallback); + r.table("players").filter(r.row.hasFields("games_won").not()).run(conn).then(cursorCallback); + r.table("players").filter(r.row.hasFields({ "games_won": { "championships": true } }).not()).run(conn).then(cursorCallback); + + testDb.tableCreate("users").run(conn).then(function() { const users = testDb.table("users"); users.insert({ name: "bob" }).run(conn, function() { @@ -53,8 +68,8 @@ r.connect({ host: "localhost", port: 28015 }).then(function(conn) { .between("james", "beth") .limit(4) .run(conn) - .then(cursor => { - cursor.toArray().then(rows => { + .then((cursor: r.Cursor) => { + cursor.toArray().then((rows: any[]) => { console.log(rows); }); }); diff --git a/rethinkdb/rethinkdb.d.ts b/rethinkdb/rethinkdb.d.ts index 782a1df5fd..4c2a9ddb96 100644 --- a/rethinkdb/rethinkdb.d.ts +++ b/rethinkdb/rethinkdb.d.ts @@ -41,7 +41,7 @@ declare module "rethinkdb" { export function sum(prop: string): Aggregator; export function avg(prop: string): Aggregator; - export function row(name: string): Expression; + export const row: Row; export function expr(stuff: any): Expression; export function now(): Expression