diff --git a/rethinkdb/rethinkdb-tests.ts b/rethinkdb/rethinkdb-tests.ts index 4dbd7ab638..06a37eb504 100644 --- a/rethinkdb/rethinkdb-tests.ts +++ b/rethinkdb/rethinkdb-tests.ts @@ -1,44 +1,84 @@ -/// +/// -import r = require("rethinkdb") +import * as r from "rethinkdb"; -r.connect({host:"localhost", port: 28015}, function(err, conn) { - console.log("HI", err, conn) - var testDb = r.db('test') - testDb.tableCreate('users').run(conn, function(err, stuff) { - var users = testDb.table('users') +function errorAndCursorCallback(err: Error, cursor: r.Cursor): void {} +function cursorCallback(cursor: r.Cursor): void {} - users.insert({name: "bob"}).run(conn, function() {}) +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); + + r.table("players").filter( + r.row.hasFields("games_won").not() + .or(r.row("games_won").not().eq(true)) + .and(true) + ) + .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") + return doc("henry").eq("bob"); }) + .filter(r.row("updatedAt").default(0).lt(r.now().sub(1000))) .between("james", "beth") .limit(4) .run(conn, function(err, cursor) { - cursor.toArray().then(rows => { - console.log(rows); + cursor.toArray((err, strings) => { + console.log(strings); }); - }) + }); + }); - }) -}) + r.js("'str1' + 'str2'").run(conn, function (err, value) {}); + r.uuid().run(conn, function (err, uuid) {}); + r.uuid("input value").run(conn, function (err, uuid) {}); + + r.table("games").changes().run(conn, function(err, cursor) { + cursor.each(console.log); + }); +}); // use promises instead of callbacks -r.connect({host:"localhost", port: 28015}).then(function(conn) { - console.log("HI", conn) - var testDb = r.db('test') - testDb.tableCreate('users').run(conn).then(function(stuff) { - var users = testDb.table('users') +r.connect({ host: "localhost", port: 28015 }).then(function(conn: r.Connection) { + console.log("HI", conn); - users.insert({name: "bob"}).run(conn, function() {}) + const testDb = r.db("test"); + + 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() { + }); users.filter(function(doc?) { - return doc("henry").eq("bob") + return doc("henry").eq("bob"); }) .between("james", "beth") .limit(4) - .run(conn); - - }) -}) + .run(conn) + .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 a34ef1fbce..9dd6437ca1 100644 --- a/rethinkdb/rethinkdb.d.ts +++ b/rethinkdb/rethinkdb.d.ts @@ -1,14 +1,31 @@ -// Type definitions for Rethinkdb 1.10.0 +// Type definitions for RethinkDB 2.3 // Project: http://rethinkdb.com/ -// Definitions by: Sean Hess +// Definitions by: Alex Gorbatchev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Reference: http://www.rethinkdb.com/api/#js -// TODO: Document manipulation and below -/// +// +// Reference: https://rethinkdb.com/api/javascript/ +// +// Notes: +// - Currently missing control structures and geospatial commands. Please help out! +// +// Testing: +// $ tsc --noImplicitAny --module commonjs -p rethinkdb/ +/// + +/** + * https://rethinkdb.com/api/javascript/ + */ declare module "rethinkdb" { - - export function connect(host: ConnectionOptions, cb?: (err: Error, conn: Connection) => void): Promise; + /** + * Create a new connection to the database server. + * + * See: https://rethinkdb.com/api/javascript/connect/ + */ + export function connect(opts: ConnectionOptions, cb: (err: ReqlDriverError, conn: Connection) => void): void; + export function connect(host: string, cb: (err: ReqlDriverError, conn: Connection) => void): void; + export function connect(opts: ConnectionOptions): Promise; + export function connect(host: string): Promise; export function dbCreate(name: string): Operation; export function dbDrop(name: string): Operation; @@ -24,14 +41,27 @@ 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(): Time; + export function now(): Expression