/// <reference path="rethinkdb.d.ts" />

import r = require("rethinkdb");

r.connect({ host: "localhost", port: 28015 }, function(err, conn) {
    console.log("HI", err, conn);

    const testDb = r.db("test");

    testDb.tableCreate("users").run(conn, function(err, stuff) {
        const 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, function(err, cursor) {
          cursor.toArray().then(rows => {
            console.log(rows);
          });
        });
    });
});

// use promises instead of callbacks
r.connect({ host: "localhost", port: 28015 }).then(function(conn) {
    console.log("HI", conn);

    const testDb = r.db("test");

    testDb.tableCreate("users").run(conn).then(function(stuff) {
        const 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);
    });
});

/// <reference path="rethinkdb.d.ts" />

import r = require("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')

        users.insert({name: "bob"}).run(conn, function() {})

        users.filter(function(doc?) {
            return doc("henry").eq("bob")
        })
        .between("james", "beth")
        .limit(4)
        .run(conn, function(err, cursor) {
          cursor.toArray().then(rows => {
            console.log(rows);
          });
        })

    })
})

// 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);

    })
})

--- 
+++ 
@@ -1,17 +1,20 @@
 /// <reference path="rethinkdb.d.ts" />
 
-import r = require("rethinkdb")
+import r = require("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')
+r.connect({ host: "localhost", port: 28015 }, function(err, conn) {
+    console.log("HI", err, conn);
 
-        users.insert({name: "bob"}).run(conn, function() {})
+    const testDb = r.db("test");
+
+    testDb.tableCreate("users").run(conn, function(err, stuff) {
+        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)
@@ -19,26 +22,27 @@
           cursor.toArray().then(rows => {
             console.log(rows);
           });
-        })
-
-    })
-})
+        });
+    });
+});
 
 // 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) {
+    console.log("HI", conn);
 
-        users.insert({name: "bob"}).run(conn, function() {})
+    const testDb = r.db("test");
+
+    testDb.tableCreate("users").run(conn).then(function(stuff) {
+        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);
-
-    })
-})
+    });
+});
[rethinkdb] Clean up the listing issues in the test
