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

Post on 26-Jul-2015

249 views 4 download

Tags:

Transcript of 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

@mikebluesteinmike.bluestein@thinkaheadsoftware.com

“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.”

What is Xamarin?

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

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, …

What is Couchbase Lite?

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

What is Couchbase Lite?

• Offline

• Indexing via MapReduce over views

• Syncing with Couchbase servers via Sync Gateway

• .NET API distributed via NuGet

Couchbase Lite + Xamarin

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

Couchbase Lite API

Manager

• Manages access to Couchbase Lite database

• Available via Manager.SharedInstance singleton

Manager.SharedInstance.GetDatabase ("mydatabase");

Database

• Encapsulates the Couchbase Lite database

• API to access documents (CRUD APIs)

Document

• Represents a Couchbase Lite document

• Allows saving and retrieving data via a Dictionary

CRUD Operations

• Create

• Read

• Update

• Delete

db.CreateDocument ();

db.GetDocument (docID);

doc.PutProperties (props);

doc.Delete ();

Attachments

• Attachments encapsulate binary data

• Allow storage alongside document

• Represented with MIME type

• Storage is smart

Queries

Querying Approach

Create a Query Run the QueryCreate a View

View

• Index documents

• MapReduce

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

Query• Create Query from a View

• Supports async

• Return QueryEnumerator

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

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

Syncing

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

Demo

Thanks!

Mike Bluestein

@mikebluesteinmike.bluestein@thinkaheadsoftware.com