Upload
couchbase
View
87
Download
5
Embed Size (px)
Citation preview
©2016 Couchbase Inc.
The Couchbase Connect16 mobile appTake our in-app survey!
©2016 Couchbase Inc.
Couchbase Lite 2.0:What To Expect
©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
©2016 Couchbase Inc.
New APIPasin Suriyentrakorn
Mobile Engineer
©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
©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.
©2016 Couchbase Inc.©2016 Couchbase Inc.
Highlights: Update documents
• Simplify ways to update documents
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 = propstry rev.save()
doc.update { (rev) -> Bool inrev.userProperties = propsreturn true
}
v2.0v1.0
1
2
3
©2016 Couchbase Inc.©2016 Couchbase Inc.
Highlights: Property Type Accessors
• String, Number, Bool, Date, Blob, Map, Array, Subdocument, Blob• Chain-able setters
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? Stringlet start = doc.property(forKey: "start") as? Datelet salary = doc.property(forKey: "salary") as? Int
v2.0v1.0
©2016 Couchbase Inc.©2016 Couchbase Inc.
Highlights: Subdocument
• Inline sub dictionary, not relationship• Provide type accessors and change notification
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" }, ...}
©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
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")
©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.
©2016 Couchbase Inc.©2016 Couchbase Inc.
Highlights: Change notifications
• Database (1.0)• Document (1.0)• Subdocument• Property
©2016 Couchbase Inc.©2016 Couchbase Inc.
Highlights: Model
• Mapping document’s data to your domain specification
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 = 200000employee.start = dateemployee.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()
©2016 Couchbase Inc.©2016 Couchbase Inc.
Summary
• Work in progress• CRUD• Model• Eventing• Query• Replication• REST
©2016 Couchbase Inc.
Core ImplementationJens Alfke
Mobile Architect
©2016 Couchbase Inc.
Couchbase Lite Core(“LiteCore”)
©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
Database
Queries Replicator
Public API
©2016 Couchbase Inc.©2016 Couchbase Inc.
Database
Queries Replicator
C# API
History Of Couchbase Lite
Database
Queries Replicator
Java API
Database
Queries Replicator
Obj-C API
©2016 Couchbase Inc.
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++
©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
©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
©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}}}
©2016 Couchbase Inc.©2016 Couchbase Inc.
Other Query Stuff
• Coming on all platforms:• Full-text search• Geo-queries
©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)
©2016 Couchbase Inc.©2016 Couchbase Inc.
C API Example
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);
©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
©2016 Couchbase Inc.
Coming In 2017!
©2016 Couchbase Inc.
Thank You!Any questions?
©2016 Couchbase Inc.
The Couchbase Connect16 mobile appTake our in-app survey!
©2016 Couchbase Inc.
Share your opinion on Couchbase
1. Go here: http://gtnr.it/2eRxYWn
2. Create a profile
3. Provide feedback (~15 minutes)