How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

22
Couchbase Lite & Xamarin How I lost 30 pounds with Couchbase Lite Mike Bluestein @mikebluestein [email protected]

Transcript of How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Page 1: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Couchbase Lite & XamarinHow I lost 30 pounds with Couchbase Lite

Mike Bluestein

@[email protected]

Page 2: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

“Mike, how did you lose all this weight?”

“The same way any normal person loses weight. I started using

Couchbase Lite to get an easy abstraction around offline data access in mobile apps, while

gaining nearly automatic syncing with the server.”

Page 3: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

What is Xamarin?

• Platform to develop native iOS and Android apps in C# or F#

Page 4: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

What is Xamarin?

• Xamarin.iOS (formerly MonoTouch)

• Xamarin.Android (formerly Mono for Android)

• Various other products and features

• Xamarin.Mac, Test Cloud, Xamarin Insights, Xamarin Forms, Xamarin Profiler, Sketches, …

Page 5: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

What is Couchbase Lite?

• Provides document based data access on iOS, Android and Windows platforms

Page 6: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

What is Couchbase Lite?

• Offline

• Indexing via MapReduce over views

• Syncing with Couchbase servers via Sync Gateway

• .NET API distributed via NuGet

Page 7: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Couchbase Lite + Xamarin

• Document based data access with offline support and syncing from cross platform, shared code

Page 8: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Couchbase Lite API

Page 9: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Manager

• Manages access to Couchbase Lite database

• Available via Manager.SharedInstance singleton

Manager.SharedInstance.GetDatabase ("mydatabase");

Page 10: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Database

• Encapsulates the Couchbase Lite database

• API to access documents (CRUD APIs)

Page 11: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Document

• Represents a Couchbase Lite document

• Allows saving and retrieving data via a Dictionary

Page 12: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

CRUD Operations

• Create

• Read

• Update

• Delete

db.CreateDocument ();

db.GetDocument (docID);

doc.PutProperties (props);

doc.Delete ();

Page 13: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Attachments

• Attachments encapsulate binary data

• Allow storage alongside document

• Represented with MIME type

• Storage is smart

Page 14: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Queries

Page 15: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Querying Approach

Create a Query Run the QueryCreate a View

Page 16: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

View

• Index documents

• MapReduce

var myView = db.GetView ("myView"); myView.SetMap ((doc, emit) => emit (…);

Page 17: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Query• Create Query from a View

• Supports async

• Return QueryEnumerator

var orderedQuery = myView.CreateQuery (); var results = await orderedQuery.RunAsync ();

Page 18: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Live Query• Created from a Query

• Listen for Changes

• Changed Event

var liveQuery = myView.CreateQuery().ToLiveQuery();liveQuery.Changed += (object sender, QueryChangeEventArgs e) => { var rows = e.Rows; // ...}; liveQuery.Start ();

Page 19: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Syncing

Page 20: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Sync Gateway• Replicates data between Couchbase Lite and

Couchbase server

• Pull and Push replication via Couchbase Lite API

• In memory server for development

Replication pull = db.CreatePullReplication (gatewayUri);Replication push = db.CreatePushReplication (gatewayUri);

// ...

pull.Start ();push.Start ();

Page 21: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Demo

Page 22: How I Lost 30 Pounds with Xamarin and Couchbase Lite: Couchbase Connect 2015

Thanks!

Mike Bluestein

@[email protected]