added rethink promise API

This commit is contained in:
hamza zia
2015-10-14 13:48:59 +08:00
parent b27d0d0e1c
commit 3e7df0c95a
2 changed files with 29 additions and 10 deletions
+21 -3
View File
@@ -7,9 +7,9 @@ r.connect({host:"localhost", port: 28015}, function(err, conn) {
var testDb = r.db('test')
testDb.tableCreate('users').run(conn, function(err, stuff) {
var users = testDb.table('users')
users.insert({name: "bob"}).run(conn, function() {})
users.filter(function(doc?) {
return doc("henry").eq("bob")
})
@@ -19,6 +19,24 @@ r.connect({host:"localhost", port: 28015}, function(err, conn) {
})
})
})
// 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')
users.insert({name: "bob"}).run(conn, function() {})
users.filter(function(doc?) {
return doc("henry").eq("bob")
})
.between("james", "beth")
.limit(4)
.run(conn);
})
})
})
+8 -7
View File
@@ -4,10 +4,11 @@
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// Reference: http://www.rethinkdb.com/api/#js
// TODO: Document manipulation and below
///<reference path="../bluebird/bluebird.d.ts"/>
declare module "rethinkdb" {
export function connect(host:ConnectionOptions, cb:(err:Error, conn:Connection)=>void);
export function connect(host:ConnectionOptions, cb?:(err:Error, conn:Connection)=>void):Promise<Connection>;
export function dbCreate(name:string):Operation<CreateResult>;
export function dbDrop(name:string):Operation<DropResult>;
@@ -50,7 +51,7 @@ declare module "rethinkdb" {
interface Connection {
close();
reconnect(cb:(err:Error, conn:Connection)=>void);
reconnect(cb?:(err:Error, conn:Connection)=>void):Promise<Connection>;
use(dbName:string);
addListener(event:string, cb:Function);
on(event:string, cb:Function);
@@ -139,11 +140,11 @@ declare module "rethinkdb" {
}
interface ExpressionFunction<U> {
(doc:Expression<any>):Expression<U>;
(doc:Expression<any>):Expression<U>;
}
interface JoinFunction<U> {
(left:Expression<any>, right:Expression<any>):Expression<U>;
(left:Expression<any>, right:Expression<any>):Expression<U>;
}
interface ReduceFunction<U> {
@@ -159,7 +160,7 @@ declare module "rethinkdb" {
interface UpdateOptions {
non_atomic: boolean;
durability: string; // 'soft'
return_vals: boolean; // false
return_vals: boolean; // false
}
interface WriteResult {
@@ -193,7 +194,7 @@ declare module "rethinkdb" {
}
interface Expression<T> extends Writeable, Operation<T> {
(prop:string):Expression<any>;
(prop:string):Expression<any>;
merge(query:Expression<Object>):Expression<Object>;
append(prop:string):Expression<Object>;
contains(prop:string):Expression<boolean>;
@@ -221,7 +222,7 @@ declare module "rethinkdb" {
}
interface Operation<T> {
run(conn:Connection, cb:(err:Error, result:T)=>void);
run(conn:Connection, cb?:(err:Error, result:T)=>void):Promise<T>;
}
interface Aggregator {}