Created
December 27, 2016 17:17
-
-
Save lucianboboc/24a95fbc7234dbada8b80b1df23ffe2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let connectionProperties = ConnectionProperties(host: "localhost", port: 5984, secured: false) | |
let client = CouchDBClient(connectionProperties: connectionProperties) | |
let database = client.database("test") | |
func test() { | |
let dict = ["key":"value"] | |
let json = JSON(dict) | |
database.create(json) { id, revision, doc, error in | |
if let id = id { | |
database.retrieve(id) { doc, error in | |
if let doc = doc { | |
let id = doc["_id"].stringValue | |
let rev = doc["_rev"].stringValue | |
var newDocument = doc | |
newDocument["key"] = "updated value" | |
database.update(id, rev: rev, document: newDocument) { rev, doc, error in | |
print("update callback") | |
if let rev = rev { | |
print(rev) | |
} else { | |
print(error!) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
test() | |
// update callback is never called after the database.update call... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment