Coder Social home page Coder Social logo

rethink-swift's Introduction

Rethink.swift

A client driver for RethinkDB in Swift.

Looking for a Mac app to easily query RethinkDB? Convert and analyze large data sets at the speed of light with Warp.

Usage

R.connect(URL(string: "rethinkdb://localhost:28016")!, user: "admin", password: "") { err, connection 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(connection) { response in
			assert(!response.isError, "Failed to create table: \(response)")

			R.db(databaseName).table(tableName).indexWait().run(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(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(connection) { response in 
						...
					}

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

Status

The driver implements the V1_0 protocol (which supports username/password authentication using SCRAM, and is available from RethinkDB 2.3.0). Alternatively, you can also use V0_4. Some commands and optional arguments may still be missing, but are usually easy to add to the code.

The driver is written for Swift 3. The last version working in Swift 2.2 can be found at the tag 'last-swift2'.

Installation

Swift Package Manager (SPM)

You can install the driver using Swift Package Manager by adding the following line to your Package.swift as a dependency:

.Package(url: "https://github.com/pixelspark/rethink-swift.git", majorVersion: 1)

To use the driver in an Xcode project, generate an Xcode project file using SPM:

swift package generate-xcodeproj

Open the Xcode project file and open the .xcconfig file located under the Config folder and add the following Objective-C build settings:

CLANG_ENABLE_MODULES = YES
CLANG_ENABLE_OBJC_ARC = YES
HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/Packages/**"

Manual

Drag Rethink.xcodeproj into your own project, then add Rethink or Rethink iOS as dependency (build targets) and link to it. You should then be able to simply 'import Rethink' from Swift code.

License

Rethink.swift. Copyright (c) 2015-2016 Pixelspark

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

FAQ

  • Can I contribute?

Feel free to send a pull request. If you want to implement a new feature, please open an issue first, especially if it's a non backward compatible one.

rethink-swift's People

Contributors

johnbona avatar pixelspark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rethink-swift's Issues

Not running in device

Hi, Rethink is perfectly working in simulator but not in the device. Issue is shown in the image attached.
screen shot 2019-01-25 at 11 54 27 am

Example code

Hi,
I'm trying to implement a realtime application with rethinkdb and your driver.
What I would like to achieve as first task Is to connect to the database and wait for changes in a table.
Actually the connection is fine but waiting for changes seems not to work.
Do you have any example app that covers the basics of the driver?
This is my code:
´´´
R.connect(URL(string: "rethinkdb://192.168.250.96:28015")!, user: "user1", password: "user1") { err, connection in
assert(err == nil, "Connection error: (err)")

        R.db("test").table("games").indexWait().run(connection) { response in
            assert(!response.isError, "Failed to wait for index: \(response)")
            R.db("test").table("games").changes().run(connection){ (response:ReResponse) in
                print ("There's a change!!")
            }
        }
        
        
        
    }

´´´
I would expect that any time I insert something in the table "There's a change!!" is printed in console , but that's not actually happening!

Thanks a lot.

add support for orderBy, without

Hi -- thanks for this library! I'm just getting started with rethink and hoping to use it in a swift project.

I added support for a few new queries -- orderBy, without, getAll with array argument. I'm probably going to need to add pluck as well.

I'm on the last 2.2 commit -- I'm not sure if you'd welcome a pull request that adds these to the 2.2 branch?

Swift on Linux support

Hi,

I've just come across your project, searching for RethinkDB drivers for Swift on Linux.

Is that in the pipe, or something I could contribute with?

  • Building Swift RethinkDB on Linux with Swift 3.0
  • Support for Swift package manager

/Tommy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.