mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-30 11:14:27 +08:00
added rethink promise API
This commit is contained in:
@@ -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);
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Vendored
+8
-7
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user