what to expect: couchbase lite 2.0

30
©2016 Couchbase Inc. The Couchbase Connect16 mobile app Take our in-app survey!

Upload: couchbase

Post on 10-Jan-2017

87 views

Category:

Software


5 download

TRANSCRIPT

Page 1: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

The Couchbase Connect16 mobile appTake our in-app survey!

Page 2: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

Couchbase Lite 2.0:What To Expect

Page 3: What to expect: Couchbase Lite 2.0

©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

Page 4: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

New APIPasin Suriyentrakorn

Mobile Engineer

Page 5: What to expect: Couchbase Lite 2.0

©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

Page 6: What to expect: Couchbase Lite 2.0

©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.

Page 7: What to expect: Couchbase Lite 2.0

©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

Page 8: What to expect: Couchbase Lite 2.0

©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

Page 9: What to expect: Couchbase Lite 2.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" }, ...}

Page 10: What to expect: Couchbase Lite 2.0

©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")

Page 11: What to expect: Couchbase Lite 2.0

©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.

Page 12: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.©2016 Couchbase Inc.

Highlights: Change notifications

• Database (1.0)• Document (1.0)• Subdocument• Property

Page 13: What to expect: Couchbase Lite 2.0

©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()

Page 14: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.©2016 Couchbase Inc.

Summary

• Work in progress• CRUD• Model• Eventing• Query• Replication• REST

Page 15: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

Core ImplementationJens Alfke

Mobile Architect

Page 16: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

Couchbase Lite Core(“LiteCore”)

Page 17: What to expect: Couchbase Lite 2.0

©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

Page 18: What to expect: Couchbase Lite 2.0

©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

Page 19: What to expect: Couchbase Lite 2.0

©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++

Page 20: What to expect: Couchbase Lite 2.0

©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

Page 21: What to expect: Couchbase Lite 2.0

©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

Page 22: What to expect: Couchbase Lite 2.0

©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}}}

Page 23: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.©2016 Couchbase Inc.

Other Query Stuff

• Coming on all platforms:• Full-text search• Geo-queries

Page 24: What to expect: Couchbase Lite 2.0

©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)

Page 25: What to expect: Couchbase Lite 2.0

©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);

Page 26: What to expect: Couchbase Lite 2.0

©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

Page 27: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

Coming In 2017!

Page 28: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

Thank You!Any questions?

Page 29: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

The Couchbase Connect16 mobile appTake our in-app survey!

Page 30: What to expect: Couchbase Lite 2.0

©2016 Couchbase Inc.

Share your opinion on Couchbase

1. Go here: http://gtnr.it/2eRxYWn

2. Create a profile

3. Provide feedback (~15 minutes)