Skip to content

Instantly share code, notes, and snippets.

@lucianboboc
Created December 27, 2016 17:17
Show Gist options
  • Save lucianboboc/24a95fbc7234dbada8b80b1df23ffe2a to your computer and use it in GitHub Desktop.
Save lucianboboc/24a95fbc7234dbada8b80b1df23ffe2a to your computer and use it in GitHub Desktop.
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