Rethink.swift – A Swift driver for RethinkDB

RethinkDB is the first open-source, scalable JSON database built from the ground up for the realtime web. Rethink.swift is a work-in-progress framework that allows interfacing with RethinkDB from the Swift programming language.

Connecting and querying RethinkDB from Swift is straightforward and is frictionless because of all the syntactic sugar Swift provides you with:

self.connection = R.connect(NSURL(string: "rethinkdb://localhost:28016")!) { err in
    assert(err == nil, "Connection error: \(err)")

    // Connected!
    R.dbCreate(databaseName).run(connection) { response in
        assert(!response.isError, "Failed to create database: \(response)")

        R.db(databaseName).tableCreate(tableName).run(self.connection) { response in
            assert(!response.isError, "Failed to create table: \(response)")

            R.db(databaseName).table(tableName).indexWait().run(self.connection) { response in
                assert(!response.isError, "Failed to wait for index: \(response)")

                // Insert 1000 documents
                var docs: [ReDocument] = []
                for i in 0..<1000 {
                    docs.append(["foo": "bar", "id": i])
                }

                R.db(databaseName).table(tableName).insert(docs).run(self.connection) { response in
                    assert(!response.isError, "Failed to insert data: \(response)")

                    R.db(databaseName).table(tableName).filter({ r in return r["foo"].eq(R.expr("bar")) }).run(self.connection) { response in 
                        ...
                    }

                    R.db(databaseName).table(tableName).count().run(self.connection) { response in
                        ...
                    }
                }
            }
        }
    }
}

Get the source: github.com/pixelspark/rethink-swift

Learn more about RethinkDB: rethinkdb.com