Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

What to expect: Couchbase Lite 2.0 – Couchbase Connect 2016

1,327 views

Published on

The Mobile team is working on the first major overhaul of Couchbase Lite! We’re streamlining the API, adding new querying and conflict-resolution capabilities, and turbocharging performance. Come find out the details.

Published in: Software
  • Be the first to comment

What to expect: Couchbase Lite 2.0 – Couchbase Connect 2016

  1. 1. ©2016 Couchbase Inc. 1 The Couchbase Connect16 mobile app Take our in-app survey!
  2. 2. ©2016 Couchbase Inc. Couchbase Lite 2.0: What To Expect 2
  3. 3. ©2016 Couchbase Inc.©2016 Couchbase Inc. A Major Redesign • New API • Simpler concepts • Better native object modeling • New Implementation • Cross-platform, shared-code core • Much higher performance 3
  4. 4. ©2016 Couchbase Inc. 4 New API Pasin Suriyentrakorn Mobile Engineer
  5. 5. ©2016 Couchbase Inc.©2016 Couchbase Inc. New API Goals • Make the API easy to understand and use • Align API concept across platforms • Provide both Document and Model based API 5
  6. 6. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: No revision API • Operate on documents without any knowledge of revisions. • No revision API provided • No API to create a new document revision • No access to revision history and conflicting revisions • Conflict resolution is required. • In 1.0, winning revision is automatically picked. Conflicts can be deal later. • In 2.0, conflict resolution is explicitly done when a document is saved. • Use the default or implement your own. • Include basic resolution: mine-win, their-win, most-recent-change, etc. 6
  7. 7. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: Update documents • Simplify ways to update documents 7 let doc = db.get("employee1") try doc .set("name", "Scott Tiger") .save() let doc = database.document(withID: “employee1”)! let props: [String: Any] = [ "name": "Scott Tiger” ] try doc.putProperties(props) let rev = doc.newRevision() rev.userProperties = props try rev.save() doc.update { (rev) -> Bool in rev.userProperties = props return true } v2.0v1.0 1 2 3
  8. 8. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: Property Type Accessors • String, Number, Bool, Date, Blob, Map, Array, Subdocument, Blob • Chain-able setters 8 try doc .set("name", "Scott Tiger") .set("full-time", true) .set("start", date) .set("salary", 200000) .save() let name = doc.getString("name") let start = doc.getDate("start") let salary = doc.getInt("salary") let props: [String: Any] = [ "name": "Scott Tiger”, "full-time": true, "start": date, "salary": 20000 ] try doc.putProperties(props) let name = doc.property(forKey: "name") as? String let start = doc.property(forKey: "start") as? Date let salary = doc.property(forKey: "salary") as? Int v2.0v1.0
  9. 9. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: Subdocument • Inline sub dictionary, not relationship • Provide type accessors and change notification 9 doc .getSubdocument("address") .set("street", "123 main st.") .set("city", "Mountain View") .set("state", "CA") try doc.save() { address: { street: "123 main st.", city: "Mountain View", state: "CA" }, ... }
  10. 10. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: Blob • New Blob data type replacing the Attachment • Allow to access the attachments directly from the document’s content 10 doc.set("photo", Blob(type: "image/png", data: data)) let rev = doc.newRevision() rev.setAttachmentNamed("photo", withContentType: "image/png", content: data) v2.0v1.0 let rev = doc.currentRevision() let photo = rev?.attachmentNamed("photo") let photo = doc.getBlob("photo")
  11. 11. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: Threading Model • Same threading model across platforms • Follow couchbaes-lite-ios: No sharing database and documents across threads • Live updated objects for run-loop / looper environment • Changes committed on another thread will be updated to the same document on the other thread in the next runloop cycle. • Mutated documents will be detached from getting updated until changes are saved to the database. 11
  12. 12. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: Change notifications • Database (1.0) • Document (1.0) • Subdocument • Property 12
  13. 13. ©2016 Couchbase Inc.©2016 Couchbase Inc. Highlights: Model • Mapping document’s data to your domain specification 13 class Employee : DocumentModel { @NSManaged var name: String @NSManaged var salary: Int @NSManaged var start: Date @NSManaged var photo: Blob @NSManaged var address: Address } class Address : SubdocumentModel { @NSManaged var street: String @NSManaged var city: String @NSManaged var state: String } let employee = db.get("employee1", as: Employee.self) employee.name = "Scott Tiger" employee.salary = 200000 employee.start = date employee.photo = Blob(contentType: "image/png", data: data) let address = Address() address.street = "one street" address.city = "MV" address.state = “CA" employee.address = address try employee.save()
  14. 14. ©2016 Couchbase Inc.©2016 Couchbase Inc. Summary • Work in progress • CRUD • Model • Eventing • Query • Replication • REST 14
  15. 15. ©2016 Couchbase Inc. 15 Core Implementation Jens Alfke Mobile Architect
  16. 16. ©2016 Couchbase Inc. 16 Couchbase Lite Core (“LiteCore”)
  17. 17. ©2016 Couchbase Inc.©2016 Couchbase Inc. Couchbase Lite Core Highlights • Implemented in cross-platform C++ • Pure C API, for ease of creating bindings • High performance • New & improved query features 17 Database Queries Replicator Public API
  18. 18. ©2016 Couchbase Inc.©2016 Couchbase Inc. Database Queries Replicator C# API History Of Couchbase Lite 18 Database Queries Replicator Java API Database Queries Replicator Obj-C API
  19. 19. ©2016 Couchbase Inc. 19 Cross-Platform • Develop it once, not three times • Less testing needed; more reliable code • More time to implement new features! • Consistent behavior across platforms • Customized API layers still provide idiomatic per-platform behavior Database Queries Replicator Swift API C API Obj-C API C# API Java API REST API C++
  20. 20. ©2016 Couchbase Inc.©2016 Couchbase Inc. High Performance • Low-level optimizations • No garbage collection! • Avoids reference counting, dynamic dispatch • Even stingy with malloc and memcpy • Fleece data encoding • Yet another JSON-equivalent binary encoding • Requires no parsing or memory allocation to read • ~20x faster than JSON • Much more efficient use of underlying SQLite database • Overall, 5-10x faster than 1.x 20
  21. 21. ©2016 Couchbase Inc.©2016 Couchbase Inc. Querying • Yes, we are adding query expressions • Sorry, it’s not N1QL (yet) • But it is a query language • Expressed in C API as a sort of ‘parse tree’ • Encoded in JSON • Public API will be integrated with the platform • e.g. NSPredicate or LINQ 21
  22. 22. ©2016 Couchbase Inc.©2016 Couchbase Inc. Query Examples (syntax TBD) • {“type”: “student”, “age”: {“$gt”: 12}, “grades”: {“$any”: [“D”, “F”]}} • {“type”: “student”, “age”: {“$gt”: [1]}, “grades”: {“$any”: [“D”, “F”]}} • {“type”: “student”, “age”: {“$gt”: [1]}, “grades”: {“$elemMatch”: {“$lt”: 2.0}}} 22
  23. 23. ©2016 Couchbase Inc.©2016 Couchbase Inc. Other Query Stuff • Coming on all platforms: • Full-text search • Geo-queries 23
  24. 24. ©2016 Couchbase Inc.©2016 Couchbase Inc. C API • Intermediate-level API • Intended for use by Couchbase Lite’s language bindings (via JNI, etc.) • Lower-level than you’d probably like • (unless you love C) 24
  25. 25. ©2016 Couchbase Inc.©2016 Couchbase Inc. C API Example 25 C4Error error; C4Database *db = c4db_open(databasePath, NULL, &error); C4Document *doc = c4doc_get(db, C4STR("somedocid"), true, &error); C4Slice body = doc->selectedRev.body; my_read_body(body.buf, body.size); c4doc_free(doc); c4db_close(db, &error); c4db_free(db);
  26. 26. ©2016 Couchbase Inc.©2016 Couchbase Inc. You Can Try It Now • github.com/couchbase/couchbase-lite-core • Currently runs on: • iOS/Mac (Xcode project) • Windows (Visual Studio project) • Linux (CMake files) • Alpha quality • Doxygen docs of C API 26
  27. 27. ©2016 Couchbase Inc. 27 Coming In 2017!
  28. 28. ©2016 Couchbase Inc. Thank You! 28 Any questions?
  29. 29. ©2016 Couchbase Inc. 29 The Couchbase Connect16 mobile app Take our in-app survey!
  30. 30. ©2016 Couchbase Inc. 30 Share your opinion on Couchbase 1. Go here: http://gtnr.it/2eRxYWn 2. Create a profile 3. Provide feedback (~15 minutes)

×