Developing	
  with	
  
Couchbase	
  Mobile	
  
	
  David	
  Maier	
  
May	
  the	
  27th	
  ‘14	
  
Agenda	
  
About Couchbase	

Further Examples	

Questions?	

Introduction to Couchbase Mobile	

Demo
About	
  Couchbase	
  
Fastest growing NoSQL database company
 4x growth in 2013;Widely recognized as industry leader	

Worldwide operations with  150 employees
75 in engineering; more than doubling every year	

Support offices in US (multiple), UK, India, Japan, China (soon) 	

	

Leader in scalability  high performance	

Easily  reliable scale your app; Get consistent low latency  high throughput	

Only NoSQL vendor with mobile database + sync 	

Recognized as most innovative NoSQL vendor	

	

Provide KV  document database for web  mobile apps	

Flexible, schemaless JSON data model; 100% open source	

Mission critical deployments at large enterprises 
internet companies	

 400 customers; 10,000 paid production nodes deployed; worldwide customer base	

Couchbase, Inc. Confidential
Market	
  Adop9on	
  
 400 customers;  10,000 production nodes
deployed	

Internet
Companies	

 Enterprises
Overview	
  
Couchbase offers a full range of
Data Management solutions	

High
Availability
Cache	

Key
Value	

Docum
ent	

Mobile
device	

SSN: 400 658 9993	

Pass: ******	

Pass: ******
Couchbase	
  Server	
  Is	
  The	
  Complete	
  
Solu9on	
  
One click scalability and no
app changes.	

Sub millisecond latency with high
throughput for reads and writes.	

Maintenance, upgrades and
cluster resizing all online
without application downtime	

JSON document model with no
fixed schema.	

✔	

✔	

✔	

✔	

Consistent High
Performance	

Flexible
Data Model	

Easy
Scalability	

Always On
24x7x365
Introduc9on	
  to	
  Couchbase	
  Mobile	
  
The	
  Next	
  Wave	
  of	
  Mobile	
  Apps	
  
…will	
  be	
  ALWAYS	
  available	
  
Data	
  
Data	
  
JSON	
  Anywhere	
  	
  
Couchbase	
  Server	
  
•  JSON	
  on	
  the	
  wire	
  
­  No	
  need	
  for	
  data	
  
transforma;on	
  
•  JSON	
  in	
  the	
  cloud	
  
­  Flexible	
  data	
  model	
  
­  High	
  performance	
  
­  Easy	
  scalability	
  
ServerSync GatewayLite
JS N	

JS N	

JS N	

•  JSON	
  on	
  the	
  device	
  
­  Developers	
  
increasingly	
  prefer	
  
NoSQL	
  database	
  
Architecture	
  
	
  
	
  
SERVER	
  3	
  	
  
	
  
SERVER	
  1	
   	
  
	
  
SERVER	
  2	
  
Couchbase	
  Server	
  
	
  
	
  
Channel	

Sync	
  Gateway	
  
Channel	

	
  
	
  
Channel	

Sync	
  Gateway	
  
Channel	

Couchbase	
  Lite	
  for	
  iOS	
  and	
  Android	
  
On Premise	

 In the cloud
Couchbase	
  Lite	
  
The	
  only	
  NoSQL	
  Database	
  for	
  Mobile	
  Devices	
  
•  Features	
  
­  Ultra-­‐lightweight,	
  secure	
  JSON	
  
database	
  	
  
­  Na;ve	
  support	
  for	
  iOS,	
  Android	
  
and	
  REST/HTML5	
  
­  Full	
  document,	
  index	
  and	
  
querying	
  and	
  sync	
  capabili;es	
  
­  Powerful	
  conflict	
  resolu;on	
  
Lite
Couchbase	
  
Lite	
  	
  
Android	
  
Couchbase	
  
Lite	
  	
  
iOS	
  
Couchbase	
  Lite	
  
Full	
  Feature	
  List	
  
Features	
   Benefits	
  
Na9ve	
  APIs	
  	
   Manage	
  your	
  mobile	
  database	
  using	
  APIs	
  op;mized	
  specifically	
  
for	
  iOS	
  and	
  Android	
  
REST	
  APIs	
   REST	
  APIs	
  provide	
  an	
  alterna;ve	
  access	
  method	
  based	
  on	
  your	
  
development	
  needs	
  
JSON	
  support	
  	
   Use	
  a	
  flexible	
  data	
  model	
  designed	
  for	
  mobile	
  object-­‐oriented	
  
apps.	
  Adapt	
  to	
  your	
  applica;on	
  needs	
  with	
  immediacy	
  and	
  
li[le	
  impact	
  
Easy	
  sync	
  with	
  Couchbase	
  Sync	
  Gateway	
   Get	
  sync-­‐ready	
  in	
  less	
  than	
  a	
  few	
  lines	
  of	
  code.	
  Focus	
  on	
  
applica;on	
  development,	
  not	
  syncing	
  
Peer	
  to	
  peer	
  support	
  via	
  REST	
  APIs	
  
	
  	
  
Communicate	
  with	
  nearby	
  devices,	
  even	
  offline,	
  with	
  our	
  REST	
  
API-­‐enabled	
  P2P	
  support	
  
Data	
  rou9ng	
  via	
  channels	
  	
   Get	
  users	
  only	
  the	
  data	
  they	
  need	
  for	
  a	
  focused,	
  relevant	
  app	
  
experience	
  
Changes	
  Feed	
  	
  
	
  	
  
Provides	
  developers	
  visibility	
  and	
  no;fica;on	
  into	
  data	
  
changes	
  	
  
Indexing	
  and	
  querying	
  for	
  JSON	
   Use	
  powerful	
  secondary	
  indexes	
  to	
  query	
  your	
  data	
  on	
  the	
  
device	
  
Authen9ca9on	
  plug-­‐ins	
   Use	
  popular	
  exis;ng	
  third-­‐party	
  authen;ca;on	
  services	
  like	
  
Facebook	
  and	
  Mozilla	
  Persona	
  instead	
  of	
  wri;ng	
  your	
  own	
  
ATachment	
  support	
  on	
  device	
  and	
  in	
  the	
  cloud	
   Manage	
  binary	
  data,	
  like	
  photos	
  and	
  large	
  files,	
  separately	
  
from	
  your	
  JSON	
  documents	
  for	
  op;onal,	
  speedier	
  sync	
  
What	
  you	
  get	
  
Lite
Couchbase	
  
Lite	
  	
  
Android	
  
Couchbase	
  
Lite	
  	
  
iOS	
  
­  Enable	
  new	
  class	
  of	
  rich	
  data	
  
intensive	
  local	
  applica;ons	
  	
  
­  Rapid	
  development	
  using	
  
na;ve	
  JSON	
  data	
  
­  Highly	
  responsive	
  interac;ve	
  
applica;ons	
  
­  Always	
  available	
  -­‐	
  	
  online	
  or	
  
offline	
  
Couchbase	
  Sync	
  Gateway	
  
Easy,	
  Reliable	
  Data	
  Sync	
  to	
  the	
  Cloud	
  
•  Features	
  
•  Dynamic	
  sync	
  capabili;es	
  via	
  
Sync	
  Func;on	
  APIs	
  
•  Easy	
  Administra;on	
  
•  Seamless	
  scaleout	
  
•  Benefits	
  
­  10x	
  reduc;on	
  in	
  development	
  
;me	
  
­  Scales	
  to	
  support	
  millions	
  of	
  
users	
  
Sync Gateway
Collaborate	
  using	
  Channels	
  
•  For	
  each	
  document,	
  you	
  specify	
  a	
  set	
  of	
  
channels	
  it	
  belongs	
  to	
  	
  
­  E.G	
  doc.channels	
  :	
  [	
  “food”,	
  “sports”	
  ]	
  
•  For	
  each	
  user	
  or	
  device,	
  you	
  control	
  which	
  
channels	
  they	
  can	
  access	
  
•  Replicate	
  only	
  a	
  subset	
  of	
  documents	
  down	
  to	
  
the	
  device	
  
­  User-­‐defined	
  filter	
  func;ons	
  	
  
­  Simply	
  lets	
  you	
  know	
  whether	
  a	
  document	
  should	
  be	
  replicated	
  
•  And	
  you	
  can	
  authen9cate	
  users	
  	
  
	
  
Sync Gateway!
Data!Data!
Sync Gateway!
Data!
Data!
Data!
Sync Gateway!
Data!
Data!Data!
Sync Gateway!
Data!Data!
Sync Gateway!
Data!
Data!
Data!Data!
Sync Gateway!Data!
Data!Data!
What	
  you	
  get	
  
Easy	
  Sync	
  
•  Effortlessly	
  sync	
  local	
  data	
  with	
  a	
  
database	
  in	
  the	
  cloud	
  for	
  updates,	
  
replica;on	
  or	
  collabora;ve	
  
sharing.	
  
•  In	
  addi;on,	
  scale	
  your	
  data	
  ;er	
  
horizontally	
  and	
  reliably	
  as	
  your	
  
data	
  and	
  sync	
  needs	
  grow.	
  	
  
JSON
JSON
JSON
JSONJSON
	
  	
  	
  	
  	
  JSON	
  Anywhere	
  
	
  
	
  
•  Flexible	
  JSON	
  on	
  device	
  lets	
  you	
  
work	
  with	
  local	
  data	
  	
  modify	
  your	
  
data	
  structure	
  on	
  the	
  fly	
  without	
  
impac;ng	
  your	
  back-­‐end.	
  
•  Your	
  users	
  can	
  count	
  on	
  having	
  an	
  
amazing	
  app	
  experience	
  with	
  a	
  fast	
  
and	
  unbreakable	
  local	
  database	
  	
  	
  
Integra9ons	
  
Couchbase	
  Lite	
  Plug-­‐in	
  for	
  PhoneGap	
  
•  Support	
  for	
  HTML5	
  developers	
  
•  Develop	
  once	
  in	
  JavaScript	
  and	
  deploy	
  
on	
  iOS	
  	
  Android	
  
•  Available	
  on	
  GitHub,	
  Cordova	
  Plugin	
  
Registry,	
  and	
  coming	
  soon	
  to	
  
build.phonegap.com	
  
	
  
h[ps://github.com/couchbaselabs/Couchbase-­‐Lite-­‐PhoneGap-­‐Plugin	
  
h[p://plugins.cordova.io/#/com.couchbase.lite.phonegap	
  
Integra9ons	
  
Couchbase	
  Lite	
  for	
  Xamarin	
  
•  Partnered	
  to	
  support	
  C#	
  community	
  
•  Available	
  on	
  Developer	
  Center	
  
•  Includes	
  sample	
  applica;on	
  to	
  help	
  
developers	
  get	
  started	
  today	
  
h[p://components.xamarin.com/view/couchbase-­‐lite/	
  
Get	
  Started	
  
mobile.couchbase.com	
  
Sample	
  App	
  
hTps://github.com/couchbaselabs/TodoLite-­‐iOS	
  
Addi9onal	
  Resources	
  
Webinar	
  Series:	
  www.couchbase.com/webinars	
  
­  Developing	
  with	
  Couchbase	
  Lite	
  iOS	
  
­  Developing	
  with	
  Couchbase	
  Lite	
  Android	
  
­  Couchbase	
  Lite	
  Under	
  the	
  Hood	
  
	
  
Community	
  Forum	
  
hTps://groups.google.com/forum/#!forum/mobile-­‐couchbase	
  
Demo	
  
Demo	
  App	
  Overview	
  
•  Task	
  Model	
  
­  User	
  Id	
  
­  Crea;on	
  Time	
  
­  Title	
  
•  Task	
  Service	
  
­  Add	
  Task	
  
­  Get	
  Task	
  
­  Get	
  Tasklist	
  
•  Replica9on	
  
­  Bidirec;onal	
  Setup	
  
­  Con;nuous	
  
­  Change	
  Listener	
  for	
  
Monitoring	
  
	
  
•  Handle	
  Data	
  Changes	
  
­  Database	
  Change	
  Listener	
  
­  Valida;on	
  
•  Layout	
  
­  EditText	
  for	
  the	
  Task	
  Title	
  
­  GridView	
  for	
  the	
  Tasklist	
  
­  Bu[on	
  to	
  add	
  a	
  Task	
  
	
  
Demo	
  App	
  Overview	
  
•  Sync	
  Gateway	
  
­  Configura;on	
  
­  Guest	
  Access	
  
­  Sync	
  Func;on	
  
	
  
•  Couchbase	
  Server	
  
­  Bucket	
  Setup	
  
­  Stored	
  Sync	
  Info	
  
Further	
  Examples	
  
Couchbase	
  Lite	
  Views	
  
com.couchbase.lite.View	
  viewItemsByDate	
  
=	
  database.getView(String.format(%s/
%s,	
  designDocName,	
  byDateViewName));	
  
	
  
viewItemsByDate.setMap(new	
  Mapper()	
  {	
  
	
  	
  	
  	
  @Override	
  
	
  	
  	
  	
  public	
  void	
  map(MapString,	
  Object	
  
document,	
  Emi[er	
  emi[er)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  Object	
  createdAt	
  =	
  
document.get(created_at);	
  
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (createdAt	
  !=	
  null)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  emi[er.emit(createdAt.toString(),	
  
document);	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  }	
  
},	
  1.0);	
  
com.couchbase.lite.View	
  view	
  =	
  database.getView(byDate);	
  
Query	
  query	
  =	
  view.createQuery();	
  
query.setLimit(10);	
  
query.setDescending(true);	
  
	
  
try	
  {	
  
	
  	
  	
  	
  QueryEnumerator	
  rowEnum	
  =	
  query.run();	
  
	
  	
  	
  	
  for	
  (IteratorQueryRow	
  it	
  =	
  rowEnum;	
  it.hasNext();)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  QueryRow	
  row	
  =	
  it.next();	
  
	
  	
  	
  	
  	
  	
  	
  	
  Log.d(Document	
  ID:,	
  row.getDocumentId());	
  
	
  
	
  	
  	
  	
  }	
  
}	
  catch	
  (CouchbaseLiteExcep;on	
  e)	
  {	
  
	
  	
  	
  	
  e.printStackTrace();	
  
}	
  
	
  
	
  
Crea9ng	
  Views	
   Querying	
  Views	
  
Filtered	
  Replica9ons	
  
database.setFilter(sharedItems,	
  new	
  
Replica;onFilter()	
  {	
  
	
  	
  	
  	
  @Override	
  
	
  	
  	
  	
  public	
  boolean	
  filter(SavedRevision	
  
revision,	
  MapString,	
  Object	
  params)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  ((Boolean)	
  
revision.getProper;es().get(shared)).
booleanValue();	
  
	
  	
  	
  	
  }	
  
});	
  
push.setFilter	
  =	
  sharedItems;	
  
	
  
	
  
	
  
Crea9ng	
  a	
  Push	
  Filter	
  Func9on	
   Adding	
  the	
  Filter	
  by	
  Name	
  
Sync	
  Gateway	
  Authen9ca9on	
  	
  
String	
  url	
  =	
  
“h[ps://
frank:s33kr1t@sync.example.com/
database/”;	
  
private	
  void	
  addFacebookAuthoriza;on(Replica;on	
  
replica;on)	
  {	
  
	
  	
  	
  	
  //	
  start	
  Facebook	
  Login	
  
	
  	
  	
  	
  Session.openAc;veSession(this,	
  true,	
  new	
  
Session.StatusCallback()	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  //	
  callback	
  when	
  session	
  changes	
  state	
  
	
  	
  	
  	
  	
  	
  	
  	
  @Override	
  
	
  	
  	
  	
  	
  	
  	
  	
  public	
  void	
  call(Session	
  session,	
  SessionState	
  state,	
  
Excep;on	
  excep;on)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  if	
  (excep;on	
  !=	
  null	
  ||	
  !session.isOpened())	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //	
  make	
  request	
  to	
  the	
  Facebook	
  /me	
  API	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Request.executeMeRequestAsync(session,	
  new	
  
Request.GraphUserCallback()	
  {	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
Basic	
   Facebook	
  
Sync	
  Gateway	
  Authen9ca9on	
  	
  
	
  //	
  callback	
  azer	
  Facebook	
  Graph	
  API	
  response	
  with	
  
user	
  object	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  @Override	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  public	
  void	
  onCompleted(GraphUser	
  user,	
  
Response	
  response)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  if	
  (user	
  !=	
  null)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  String	
  email	
  =	
  (String)	
  
user.getProperty(email);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  FacebookAuthorizer	
  authorizer	
  =	
  new	
  
FacebookAuthorizer(email);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
authorizer.registerAccessToken(session.getAccessToken
(),	
  email,	
  replica;on.getRemoteUrl());	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  replica;on.setAuthorizer(authorizer);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  });	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  });	
  
}	
  
	
  
	
  
	
  
	
  
Facebook	
  (cont.)	
  
Sync	
  Func9on	
  Examples	
  	
  
//Default	
  
func;on	
  (doc)	
  {	
  
	
  	
  channel(doc.channels);	
  
}	
  
	
  
//Valida9on	
  
func;on	
  (doc)	
  {	
  
	
  	
  throw	
  ({forbidden	
  :	
  read	
  only!})	
  
}	
  
	
  
	
  
	
  
//Channel	
  mapping	
  
func;on	
  (doc,	
  oldDoc)	
  {	
  
	
  	
  if	
  (doc.published)	
  {	
  
	
  	
  	
  	
  channel	
  (public);	
  
	
  	
  }	
  	
  
}	
  
//Access	
  Control	
  
func;on	
  (doc,	
  oldDoc)	
  {	
  
	
  	
  access	
  (doc.members,	
  doc.channel_name);	
  
	
  	
  channel	
  (doc.channel_name)	
  
}	
  
	
  
Ques9ons?	
  
Thank	
  you!	
  
mobile.couchbase.com	
  

Couchbase Mobile on Android

  • 1.
    Developing  with   Couchbase  Mobile    David  Maier   May  the  27th  ‘14  
  • 2.
    Agenda   About Couchbase FurtherExamples Questions? Introduction to Couchbase Mobile Demo
  • 3.
  • 4.
    Fastest growing NoSQLdatabase company 4x growth in 2013;Widely recognized as industry leader Worldwide operations with 150 employees 75 in engineering; more than doubling every year Support offices in US (multiple), UK, India, Japan, China (soon) Leader in scalability high performance Easily reliable scale your app; Get consistent low latency high throughput Only NoSQL vendor with mobile database + sync Recognized as most innovative NoSQL vendor Provide KV document database for web mobile apps Flexible, schemaless JSON data model; 100% open source Mission critical deployments at large enterprises internet companies 400 customers; 10,000 paid production nodes deployed; worldwide customer base Couchbase, Inc. Confidential
  • 5.
    Market  Adop9on   400 customers; 10,000 production nodes deployed Internet Companies Enterprises
  • 6.
    Overview   Couchbase offersa full range of Data Management solutions High Availability Cache Key Value Docum ent Mobile device SSN: 400 658 9993 Pass: ****** Pass: ******
  • 7.
    Couchbase  Server  Is  The  Complete   Solu9on   One click scalability and no app changes. Sub millisecond latency with high throughput for reads and writes. Maintenance, upgrades and cluster resizing all online without application downtime JSON document model with no fixed schema. ✔ ✔ ✔ ✔ Consistent High Performance Flexible Data Model Easy Scalability Always On 24x7x365
  • 8.
  • 9.
    The  Next  Wave  of  Mobile  Apps   …will  be  ALWAYS  available   Data   Data  
  • 10.
    JSON  Anywhere     Couchbase  Server   •  JSON  on  the  wire   ­  No  need  for  data   transforma;on   •  JSON  in  the  cloud   ­  Flexible  data  model   ­  High  performance   ­  Easy  scalability   ServerSync GatewayLite JS N JS N JS N •  JSON  on  the  device   ­  Developers   increasingly  prefer   NoSQL  database  
  • 11.
    Architecture       SERVER  3       SERVER  1       SERVER  2   Couchbase  Server       Channel Sync  Gateway   Channel     Channel Sync  Gateway   Channel Couchbase  Lite  for  iOS  and  Android   On Premise In the cloud
  • 12.
    Couchbase  Lite   The  only  NoSQL  Database  for  Mobile  Devices   •  Features   ­  Ultra-­‐lightweight,  secure  JSON   database     ­  Na;ve  support  for  iOS,  Android   and  REST/HTML5   ­  Full  document,  index  and   querying  and  sync  capabili;es   ­  Powerful  conflict  resolu;on   Lite Couchbase   Lite     Android   Couchbase   Lite     iOS  
  • 13.
    Couchbase  Lite   Full  Feature  List   Features   Benefits   Na9ve  APIs     Manage  your  mobile  database  using  APIs  op;mized  specifically   for  iOS  and  Android   REST  APIs   REST  APIs  provide  an  alterna;ve  access  method  based  on  your   development  needs   JSON  support     Use  a  flexible  data  model  designed  for  mobile  object-­‐oriented   apps.  Adapt  to  your  applica;on  needs  with  immediacy  and   li[le  impact   Easy  sync  with  Couchbase  Sync  Gateway   Get  sync-­‐ready  in  less  than  a  few  lines  of  code.  Focus  on   applica;on  development,  not  syncing   Peer  to  peer  support  via  REST  APIs       Communicate  with  nearby  devices,  even  offline,  with  our  REST   API-­‐enabled  P2P  support   Data  rou9ng  via  channels     Get  users  only  the  data  they  need  for  a  focused,  relevant  app   experience   Changes  Feed         Provides  developers  visibility  and  no;fica;on  into  data   changes     Indexing  and  querying  for  JSON   Use  powerful  secondary  indexes  to  query  your  data  on  the   device   Authen9ca9on  plug-­‐ins   Use  popular  exis;ng  third-­‐party  authen;ca;on  services  like   Facebook  and  Mozilla  Persona  instead  of  wri;ng  your  own   ATachment  support  on  device  and  in  the  cloud   Manage  binary  data,  like  photos  and  large  files,  separately   from  your  JSON  documents  for  op;onal,  speedier  sync  
  • 14.
    What  you  get   Lite Couchbase   Lite     Android   Couchbase   Lite     iOS   ­  Enable  new  class  of  rich  data   intensive  local  applica;ons     ­  Rapid  development  using   na;ve  JSON  data   ­  Highly  responsive  interac;ve   applica;ons   ­  Always  available  -­‐    online  or   offline  
  • 15.
    Couchbase  Sync  Gateway   Easy,  Reliable  Data  Sync  to  the  Cloud   •  Features   •  Dynamic  sync  capabili;es  via   Sync  Func;on  APIs   •  Easy  Administra;on   •  Seamless  scaleout   •  Benefits   ­  10x  reduc;on  in  development   ;me   ­  Scales  to  support  millions  of   users   Sync Gateway
  • 16.
    Collaborate  using  Channels   •  For  each  document,  you  specify  a  set  of   channels  it  belongs  to     ­  E.G  doc.channels  :  [  “food”,  “sports”  ]   •  For  each  user  or  device,  you  control  which   channels  they  can  access   •  Replicate  only  a  subset  of  documents  down  to   the  device   ­  User-­‐defined  filter  func;ons     ­  Simply  lets  you  know  whether  a  document  should  be  replicated   •  And  you  can  authen9cate  users      
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
    What  you  get   Easy  Sync   •  Effortlessly  sync  local  data  with  a   database  in  the  cloud  for  updates,   replica;on  or  collabora;ve   sharing.   •  In  addi;on,  scale  your  data  ;er   horizontally  and  reliably  as  your   data  and  sync  needs  grow.     JSON JSON JSON JSONJSON          JSON  Anywhere       •  Flexible  JSON  on  device  lets  you   work  with  local  data    modify  your   data  structure  on  the  fly  without   impac;ng  your  back-­‐end.   •  Your  users  can  count  on  having  an   amazing  app  experience  with  a  fast   and  unbreakable  local  database      
  • 24.
    Integra9ons   Couchbase  Lite  Plug-­‐in  for  PhoneGap   •  Support  for  HTML5  developers   •  Develop  once  in  JavaScript  and  deploy   on  iOS    Android   •  Available  on  GitHub,  Cordova  Plugin   Registry,  and  coming  soon  to   build.phonegap.com     h[ps://github.com/couchbaselabs/Couchbase-­‐Lite-­‐PhoneGap-­‐Plugin   h[p://plugins.cordova.io/#/com.couchbase.lite.phonegap  
  • 25.
    Integra9ons   Couchbase  Lite  for  Xamarin   •  Partnered  to  support  C#  community   •  Available  on  Developer  Center   •  Includes  sample  applica;on  to  help   developers  get  started  today   h[p://components.xamarin.com/view/couchbase-­‐lite/  
  • 26.
    Get  Started   mobile.couchbase.com   Sample  App   hTps://github.com/couchbaselabs/TodoLite-­‐iOS  
  • 27.
    Addi9onal  Resources   Webinar  Series:  www.couchbase.com/webinars   ­  Developing  with  Couchbase  Lite  iOS   ­  Developing  with  Couchbase  Lite  Android   ­  Couchbase  Lite  Under  the  Hood     Community  Forum   hTps://groups.google.com/forum/#!forum/mobile-­‐couchbase  
  • 28.
  • 29.
    Demo  App  Overview   •  Task  Model   ­  User  Id   ­  Crea;on  Time   ­  Title   •  Task  Service   ­  Add  Task   ­  Get  Task   ­  Get  Tasklist   •  Replica9on   ­  Bidirec;onal  Setup   ­  Con;nuous   ­  Change  Listener  for   Monitoring     •  Handle  Data  Changes   ­  Database  Change  Listener   ­  Valida;on   •  Layout   ­  EditText  for  the  Task  Title   ­  GridView  for  the  Tasklist   ­  Bu[on  to  add  a  Task    
  • 30.
    Demo  App  Overview   •  Sync  Gateway   ­  Configura;on   ­  Guest  Access   ­  Sync  Func;on     •  Couchbase  Server   ­  Bucket  Setup   ­  Stored  Sync  Info  
  • 31.
  • 32.
    Couchbase  Lite  Views   com.couchbase.lite.View  viewItemsByDate   =  database.getView(String.format(%s/ %s,  designDocName,  byDateViewName));     viewItemsByDate.setMap(new  Mapper()  {          @Override          public  void  map(MapString,  Object   document,  Emi[er  emi[er)  {                  Object  createdAt  =   document.get(created_at);                  if  (createdAt  !=  null)  {                          emi[er.emit(createdAt.toString(),   document);                  }          }   },  1.0);   com.couchbase.lite.View  view  =  database.getView(byDate);   Query  query  =  view.createQuery();   query.setLimit(10);   query.setDescending(true);     try  {          QueryEnumerator  rowEnum  =  query.run();          for  (IteratorQueryRow  it  =  rowEnum;  it.hasNext();)  {                  QueryRow  row  =  it.next();                  Log.d(Document  ID:,  row.getDocumentId());            }   }  catch  (CouchbaseLiteExcep;on  e)  {          e.printStackTrace();   }       Crea9ng  Views   Querying  Views  
  • 33.
    Filtered  Replica9ons   database.setFilter(sharedItems,  new   Replica;onFilter()  {          @Override          public  boolean  filter(SavedRevision   revision,  MapString,  Object  params)  {                  return  ((Boolean)   revision.getProper;es().get(shared)). booleanValue();          }   });   push.setFilter  =  sharedItems;         Crea9ng  a  Push  Filter  Func9on   Adding  the  Filter  by  Name  
  • 34.
    Sync  Gateway  Authen9ca9on     String  url  =   “h[ps:// frank:s33kr1t@sync.example.com/ database/”;   private  void  addFacebookAuthoriza;on(Replica;on   replica;on)  {          //  start  Facebook  Login          Session.openAc;veSession(this,  true,  new   Session.StatusCallback()  {                  //  callback  when  session  changes  state                  @Override                  public  void  call(Session  session,  SessionState  state,   Excep;on  excep;on)  {                          if  (excep;on  !=  null  ||  !session.isOpened())    {                                  return;                          }                          //  make  request  to  the  Facebook  /me  API                          Request.executeMeRequestAsync(session,  new   Request.GraphUserCallback()  {                                 Basic   Facebook  
  • 35.
    Sync  Gateway  Authen9ca9on      //  callback  azer  Facebook  Graph  API  response  with   user  object                                  @Override                                  public  void  onCompleted(GraphUser  user,   Response  response)  {                                          if  (user  !=  null)  {                                                  String  email  =  (String)   user.getProperty(email);                                                  FacebookAuthorizer  authorizer  =  new   FacebookAuthorizer(email);                                                   authorizer.registerAccessToken(session.getAccessToken (),  email,  replica;on.getRemoteUrl());                                                  replica;on.setAuthorizer(authorizer);                                          }                                  }                          });                  }          });   }           Facebook  (cont.)  
  • 36.
    Sync  Func9on  Examples     //Default   func;on  (doc)  {      channel(doc.channels);   }     //Valida9on   func;on  (doc)  {      throw  ({forbidden  :  read  only!})   }         //Channel  mapping   func;on  (doc,  oldDoc)  {      if  (doc.published)  {          channel  (public);      }     }   //Access  Control   func;on  (doc,  oldDoc)  {      access  (doc.members,  doc.channel_name);      channel  (doc.channel_name)   }    
  • 37.
  • 38.