SlideShare a Scribd company logo
1 of 45
Download to read offline
Writing Mobile
Applications with
Couchbase
CodeStock 2016
July 2016
Who is this guy?
ā€¢ Mike Hagedorn
ā€¢ Language Polyglot
ā€¢ Knoxville, TN
ā€¢ @mwhagedorn
ā€¢ http://spkr8.com/s/16930
The Plan
ā€¢ Relational Datastores
ā€¢ NoSQL Datastores
ā€¢ Couchbase Components
ā€¢ How To Get Started
ā€¢ Demo
ā€“ J.K. Rowling
ā€œThere's always room for a story that can
transport people to another place.ā€
April 1970
April 1970
what year JFK/Rice Sept 1962
April 1970
Oxygen Tanks
Houston, weā€™ve had a problem
65 28 5
ā€“ Madeleine Lā€™Engle
ā€œNothing important is completely explicable.ā€
Data Stores
Relational Data Stores
also created in 1970, E.F. Codd IBM
Relational Example
Why NoSQL?
Changing face of IT Demands
next 20 yrs 40-50% more data, 95% of
that will be non structured

BMW/cars as nodes
Couchbase History
Couchbase Terms
ā€¢ Node
ā€¢ Cluster
ā€¢ Bucket
ā€¢ Document
ā€¢ View
Couchbase Components
Mobile embedded local db with sync

Gw internet facing component

Server: Ent grade nosql db
Couchbase Server
Couchbase Lite
Couchbase Lite is an embedded JSON database
that can work standalone, in a P2P network, or as a
remote endpoint for Couchbase Server.

Embedded

All IO is local

Syncs are transparent in background

Disconnected operation

NO PUSH

NO Network
CBL
Device 1
CBL
Device 2
CB
Server
Cluster 1
with
GW!
Sync Gateway
CBL
Device 1
CBL
Device 2
CB
Server
Cluster 1
Data
Needed
Here!
?
Remote Data Center
SGW
Couchbase Model
ā€¢ An object oriented wrapper on top of
CBLDocument
ā€¢ Somewhat like NSManagedObject
ā€¢ IOS/OSX only
Couchbase Views
views process the unstructured data to
produce an index

live queries
Couchbase Challenges
ā€¢ Complicated Queries are Hard
ā€¢ Views!
ā€¢ Lack of a standard Query Language
show a view javascript
Couchbase Challenges
ā€¢ Complicated Queries are Hard
ā€¢ Views!
ā€¢ Lack of a standard Query Language
show a view javascript
N1QL
possible to use from the
Getting Started
ā€¢ DL Couchbase Lite Framework
ā€¢ Add CouchbaseLite.framework to your project
ā€¢ There is no step 3
Initialization
//AppDelegate
CBLManager *manager = [CBLManager sharedInstance];
NSError *error;
self.database = [manager databaseNamed:kDBName error: &error];
if (error) {
NSLog(@"error getting database %@",error);
exit(-1);
}
Database
Rockets
Name Weight Diameter Cd
alpha 29 25 0.75
hawk 35 30 0.8
a collection of records
Document
{
"coefficientFriction": 0.75,
"diameter": 25,
"name": "alpha110",
"type": "rocket",
"weight": 23
}
# Bb6YvfoCH7NIgsVDtgjE7O
Unique ID

May contain binary attachments

typeless, convention:type
Database View
//RootController or CBModel
//Define a view that only returns documents of type ā€˜kRocketDocTypeā€™
CBLView* view = [db viewNamed: @"rockets"];
if (!view.mapBlock) {
// Register the map function, the first time we access the view:
[view setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString:kRocketDocType])
emit(doc[@"name"], nil);
}) reduceBlock: nil version: @"1"];
}
function (doc,meta) {
if(doc.type == ā€œrocketā€){
emit(doc.name,null);
}
}
Map/Reduce

Called on every document

Optional Reduce

not replicated to server
Using Views in your UI
// Create a query showing rockets:
CBLLiveQuery* query = [[[database viewNamed:@"rockets"] query]
asLiveQuery];
// Plug the query into the CBLUITableSource, which will use it to drive
the table.
// (The CBLUITableSource uses KVO to observe the query's .rows
self.dataSource.query = query;ā€Ø
self.dataSource.labelProperty = @"name";
// Assumes something like this in your controller
@property (nonatomic) IBOutlet UITableView* tableView;
@property (nonatomic) IBOutlet CBLUITableSource* dataSource;
Using Views in your UI
// Create a query showing rockets:
CBLLiveQuery* query = [[[database viewNamed:@"rockets"] query]
asLiveQuery];
// Plug the query into the CBLUITableSource, which will use it to drive
the table.
// (The CBLUITableSource uses KVO to observe the query's .rows
self.dataSource.query = query;ā€Ø
self.dataSource.labelProperty = @"name";
// Assumes something like this in your controller
@property (nonatomic) IBOutlet UITableView* tableView;
@property (nonatomic) IBOutlet CBLUITableSource* dataSource;
Using Views in your UI
// Create a query showing rockets:
CBLLiveQuery* query = [[[database viewNamed:@"rockets"] query]
asLiveQuery];
// Plug the query into the CBLUITableSource, which will use it to drive
the table.
// (The CBLUITableSource uses KVO to observe the query's .rows
self.dataSource.query = query;ā€Ø
self.dataSource.labelProperty = @"name";
// Assumes something like this in your controller
@property (nonatomic) IBOutlet UITableView* tableView;
@property (nonatomic) IBOutlet CBLUITableSource* dataSource;
Customizing Table Cells
- (void)couchTableSource:(CBLUITableSource*)source
willUseCell:(UITableViewCell*)cell
forRow:(CBLQueryRow*)row
// Set the cell background and font:
// Configure the cell contents. Map function (above) copies the doc
properties into its value, so we can read them without having to load the
document.
NSDictionary* rowValue = row.value;ā€Ø
BOOL checked = [rowValue[@"check"] boolValue];
if (checked) {
cell.textLabel.textColor = [UIColor grayColor];
cell.imageView.image = [UIImage imageNamed:@"checked"];
} else {
cell.textLabel.textColor = [UIColor blackColor];
cell.imageView.image = [UIImage imageNamed: @"unchecked"];
}
// cell.textLabel.text is already set, thanks to setting up labelProperty
}
Selecting A Row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
NSLog(@"didSelectRowAtIndexPath");
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
CBLQueryRow *row = [self.dataSource rowAtIndex:indexPath.row];
ASDRocket* rocket = [ASDRocket modelForDocument: row.document];
// Do something with rocketā€¦
}
Selecting A Row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
NSLog(@"didSelectRowAtIndexPath");
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
CBLQueryRow *row = [self.dataSource rowAtIndex:indexPath.row];
ASDRocket* rocket = [ASDRocket modelForDocument: row.document];
// Do something with rocketā€¦
}
Adding Items
- (IBAction) insertNewObject: (id)sender {
ASDRocket* rocket = [ASDRocket modelForNewDocumentInDatabase:self.database];
rocket.name=name;
rocket.weight = 23.0;
NSError* error;
if (![rocket save: &error]) {
return nil;
}
NSLog(@"Rocket Created");
}
Adding Items
- (IBAction) insertNewObject: (id)sender {
ASDRocket* rocket = [ASDRocket modelForNewDocumentInDatabase:self.database];
rocket.name=name;
rocket.weight = 23.0;
NSError* error;
if (![rocket save: &error]) {
return nil;
}
NSLog(@"Rocket Created");
}
Deleting Items
-(void) tableView:(UITableView*)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete){
CBLQueryRow *row = [self.dataSource rowAtIndex:indexPath.row];
ASDRocket* rocket = [ASDRocket modelForDocument: row.document];
NSError* error;
if (![rocket deleteDocument: &error]){
NSLog(@"Unable to delete Rocket");
return;
}
[self.tableView reloadData];
}
}
Replications
CBLReplication *pull;
CBLReplication *push;
h;
pull = [_database createPullReplication:_remoteURL];
pull.continuous = YES;
pull.network = @"WiFi";
push = [_database createPushReplication:_remoteURL];
push.continuous = YES;
pull.network = @"WiFi";
[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(replicationProgress:)
name:kCBLReplicationChangeNotification
push];
[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(replicationProgress:)
name:kCBLReplicationChangeNotification
pull];
CBLModel
ā€¢ Maps Objects to documents
@interface ASDRocket : CBLModel
+ (NSString*) docType;
@property (strong) NSString *name;
@property (assign) double diameter;
@property (assign) double weight;
@property (assign) double coefficientFriction;
/** Returns a query for all the rockets in a database. */
+ (CBLQuery*) queryRocketsInDatabase: (CBLDatabase*)db;
/** Returns a query for all the rockets with name in a database */
+ (CBLQuery*) findInDatabase:(CBLDatabase*)db byName:(NSString *)name;
@end
CBLModel
ā€¢ No types in documents
ā€¢ convention is to use type ļ¬eld
ā€¢ Map functions can pick out docs with the right type
if (doc.type == ā€œrocketā€){
emit(doc.created, doc.text)
};
Summaryweā€™ve seen

why no sql matters, and is needed

shown how couch base can enable
diļ¬ƒcult distributed computing

next a demoā€¦.
So What Happened
5 yrs earlier

28V components spec to also 65

Missed the memo
Demo
ā€¢ https://github.com/mwhagedorn/
couchbase_ios_rockettown
ā€¢ https://github.com/mwhagedorn/
couchbase_osx_rockettown
ā€¢ Two platforms synching to one database
Questions?
ā€¢ @mwhagedorn
ā€¢ http://spkr8.com/s/16930
ā€¢ https://github.com/mwhagedorn/
couchbase_ios_rockettown
ā€¢ https://github.com/mwhagedorn/
couchbase_osx_rockettown

More Related Content

Viewers also liked

When Everyone Talks At Once, But Leaders Still Know What To Do
When Everyone Talks At Once, But Leaders Still Know What To DoWhen Everyone Talks At Once, But Leaders Still Know What To Do
When Everyone Talks At Once, But Leaders Still Know What To Do9Lenses
Ā 
Taming the video monster
Taming the video monsterTaming the video monster
Taming the video monsterLimelight Networks
Ā 
Where the most popular Youtube stars are today
Where the most popular Youtube stars are todayWhere the most popular Youtube stars are today
Where the most popular Youtube stars are todaySimply Zesty Ltd
Ā 
Branch Banking in the 21st Century by Capital Banking Solutions
Branch Banking in the 21st Century by Capital Banking SolutionsBranch Banking in the 21st Century by Capital Banking Solutions
Branch Banking in the 21st Century by Capital Banking SolutionsCapital Banking Solutions
Ā 
Nsauditor Web Proxy Scanner
Nsauditor Web Proxy  ScannerNsauditor Web Proxy  Scanner
Nsauditor Web Proxy ScannerNsasoft
Ā 

Viewers also liked (9)

When Everyone Talks At Once, But Leaders Still Know What To Do
When Everyone Talks At Once, But Leaders Still Know What To DoWhen Everyone Talks At Once, But Leaders Still Know What To Do
When Everyone Talks At Once, But Leaders Still Know What To Do
Ā 
Taming the video monster
Taming the video monsterTaming the video monster
Taming the video monster
Ā 
Where the most popular Youtube stars are today
Where the most popular Youtube stars are todayWhere the most popular Youtube stars are today
Where the most popular Youtube stars are today
Ā 
Impel elemech-company
Impel elemech-companyImpel elemech-company
Impel elemech-company
Ā 
Presenting John Loder
Presenting John LoderPresenting John Loder
Presenting John Loder
Ā 
Branch Banking in the 21st Century by Capital Banking Solutions
Branch Banking in the 21st Century by Capital Banking SolutionsBranch Banking in the 21st Century by Capital Banking Solutions
Branch Banking in the 21st Century by Capital Banking Solutions
Ā 
CRM on Demand India ,
CRM on Demand India , CRM on Demand India ,
CRM on Demand India ,
Ā 
Nsauditor Web Proxy Scanner
Nsauditor Web Proxy  ScannerNsauditor Web Proxy  Scanner
Nsauditor Web Proxy Scanner
Ā 
Step Up Business Intelligence
Step Up Business Intelligence Step Up Business Intelligence
Step Up Business Intelligence
Ā 

More from Mike Hagedorn

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesMike Hagedorn
Ā 
Couchbase Talk
Couchbase TalkCouchbase Talk
Couchbase TalkMike Hagedorn
Ā 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of ThingsMike Hagedorn
Ā 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With FogMike Hagedorn
Ā 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyMike Hagedorn
Ā 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsMike Hagedorn
Ā 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odysseyMike Hagedorn
Ā 

More from Mike Hagedorn (7)

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New Roles
Ā 
Couchbase Talk
Couchbase TalkCouchbase Talk
Couchbase Talk
Ā 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of Things
Ā 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With Fog
Ā 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
Ā 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.js
Ā 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odyssey
Ā 

Recently uploaded

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
Ā 
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļøCALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļøanilsa9823
Ā 
CALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
Ā 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
Ā 
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
Ā 
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Steffen Staab
Ā 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
Ā 
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøcall girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøDelhi Call girls
Ā 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
Ā 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
Ā 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
Ā 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...OnePlan Solutions
Ā 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
Ā 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
Ā 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
Ā 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
Ā 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
Ā 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
Ā 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
Ā 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
Ā 

Recently uploaded (20)

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Ā 
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļøCALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļø
Ā 
CALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON āž„8923113531 šŸ”Call Girls Badshah Nagar Lucknow best Female service
Ā 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
Ā 
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
Ā 
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Ā 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
Ā 
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøcall girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Vaishali (Ghaziabad) šŸ” >ą¼’8448380779 šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
Ā 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
Ā 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Ā 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
Ā 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Ā 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
Ā 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
Ā 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
Ā 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
Ā 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
Ā 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
Ā 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
Ā 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Ā 

Creating Killer Mobile Applications with IOS and Couchbase

  • 2. Who is this guy? ā€¢ Mike Hagedorn ā€¢ Language Polyglot ā€¢ Knoxville, TN ā€¢ @mwhagedorn ā€¢ http://spkr8.com/s/16930
  • 3. The Plan ā€¢ Relational Datastores ā€¢ NoSQL Datastores ā€¢ Couchbase Components ā€¢ How To Get Started ā€¢ Demo
  • 4. ā€“ J.K. Rowling ā€œThere's always room for a story that can transport people to another place.ā€
  • 6. April 1970 what year JFK/Rice Sept 1962
  • 8. Oxygen Tanks Houston, weā€™ve had a problem 65 28 5
  • 9. ā€“ Madeleine Lā€™Engle ā€œNothing important is completely explicable.ā€
  • 11. Relational Data Stores also created in 1970, E.F. Codd IBM
  • 13. Why NoSQL? Changing face of IT Demands next 20 yrs 40-50% more data, 95% of that will be non structured BMW/cars as nodes
  • 15. Couchbase Terms ā€¢ Node ā€¢ Cluster ā€¢ Bucket ā€¢ Document ā€¢ View
  • 16. Couchbase Components Mobile embedded local db with sync Gw internet facing component Server: Ent grade nosql db
  • 18. Couchbase Lite Couchbase Lite is an embedded JSON database that can work standalone, in a P2P network, or as a remote endpoint for Couchbase Server. Embedded All IO is local Syncs are transparent in background Disconnected operation NO PUSH NO Network CBL Device 1 CBL Device 2 CB Server Cluster 1 with GW!
  • 19. Sync Gateway CBL Device 1 CBL Device 2 CB Server Cluster 1 Data Needed Here! ? Remote Data Center SGW
  • 20. Couchbase Model ā€¢ An object oriented wrapper on top of CBLDocument ā€¢ Somewhat like NSManagedObject ā€¢ IOS/OSX only
  • 21. Couchbase Views views process the unstructured data to produce an index live queries
  • 22. Couchbase Challenges ā€¢ Complicated Queries are Hard ā€¢ Views! ā€¢ Lack of a standard Query Language show a view javascript
  • 23. Couchbase Challenges ā€¢ Complicated Queries are Hard ā€¢ Views! ā€¢ Lack of a standard Query Language show a view javascript
  • 25. Getting Started ā€¢ DL Couchbase Lite Framework ā€¢ Add CouchbaseLite.framework to your project ā€¢ There is no step 3
  • 26. Initialization //AppDelegate CBLManager *manager = [CBLManager sharedInstance]; NSError *error; self.database = [manager databaseNamed:kDBName error: &error]; if (error) { NSLog(@"error getting database %@",error); exit(-1); }
  • 27. Database Rockets Name Weight Diameter Cd alpha 29 25 0.75 hawk 35 30 0.8 a collection of records
  • 28. Document { "coefficientFriction": 0.75, "diameter": 25, "name": "alpha110", "type": "rocket", "weight": 23 } # Bb6YvfoCH7NIgsVDtgjE7O Unique ID May contain binary attachments typeless, convention:type
  • 29. Database View //RootController or CBModel //Define a view that only returns documents of type ā€˜kRocketDocTypeā€™ CBLView* view = [db viewNamed: @"rockets"]; if (!view.mapBlock) { // Register the map function, the first time we access the view: [view setMapBlock: MAPBLOCK({ if ([doc[@"type"] isEqualToString:kRocketDocType]) emit(doc[@"name"], nil); }) reduceBlock: nil version: @"1"]; } function (doc,meta) { if(doc.type == ā€œrocketā€){ emit(doc.name,null); } } Map/Reduce Called on every document Optional Reduce not replicated to server
  • 30. Using Views in your UI // Create a query showing rockets: CBLLiveQuery* query = [[[database viewNamed:@"rockets"] query] asLiveQuery]; // Plug the query into the CBLUITableSource, which will use it to drive the table. // (The CBLUITableSource uses KVO to observe the query's .rows self.dataSource.query = query;ā€Ø self.dataSource.labelProperty = @"name"; // Assumes something like this in your controller @property (nonatomic) IBOutlet UITableView* tableView; @property (nonatomic) IBOutlet CBLUITableSource* dataSource;
  • 31. Using Views in your UI // Create a query showing rockets: CBLLiveQuery* query = [[[database viewNamed:@"rockets"] query] asLiveQuery]; // Plug the query into the CBLUITableSource, which will use it to drive the table. // (The CBLUITableSource uses KVO to observe the query's .rows self.dataSource.query = query;ā€Ø self.dataSource.labelProperty = @"name"; // Assumes something like this in your controller @property (nonatomic) IBOutlet UITableView* tableView; @property (nonatomic) IBOutlet CBLUITableSource* dataSource;
  • 32. Using Views in your UI // Create a query showing rockets: CBLLiveQuery* query = [[[database viewNamed:@"rockets"] query] asLiveQuery]; // Plug the query into the CBLUITableSource, which will use it to drive the table. // (The CBLUITableSource uses KVO to observe the query's .rows self.dataSource.query = query;ā€Ø self.dataSource.labelProperty = @"name"; // Assumes something like this in your controller @property (nonatomic) IBOutlet UITableView* tableView; @property (nonatomic) IBOutlet CBLUITableSource* dataSource;
  • 33. Customizing Table Cells - (void)couchTableSource:(CBLUITableSource*)source willUseCell:(UITableViewCell*)cell forRow:(CBLQueryRow*)row // Set the cell background and font: // Configure the cell contents. Map function (above) copies the doc properties into its value, so we can read them without having to load the document. NSDictionary* rowValue = row.value;ā€Ø BOOL checked = [rowValue[@"check"] boolValue]; if (checked) { cell.textLabel.textColor = [UIColor grayColor]; cell.imageView.image = [UIImage imageNamed:@"checked"]; } else { cell.textLabel.textColor = [UIColor blackColor]; cell.imageView.image = [UIImage imageNamed: @"unchecked"]; } // cell.textLabel.text is already set, thanks to setting up labelProperty }
  • 34. Selecting A Row - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"didSelectRowAtIndexPath"); NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; CBLQueryRow *row = [self.dataSource rowAtIndex:indexPath.row]; ASDRocket* rocket = [ASDRocket modelForDocument: row.document]; // Do something with rocketā€¦ }
  • 35. Selecting A Row - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"didSelectRowAtIndexPath"); NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; CBLQueryRow *row = [self.dataSource rowAtIndex:indexPath.row]; ASDRocket* rocket = [ASDRocket modelForDocument: row.document]; // Do something with rocketā€¦ }
  • 36. Adding Items - (IBAction) insertNewObject: (id)sender { ASDRocket* rocket = [ASDRocket modelForNewDocumentInDatabase:self.database]; rocket.name=name; rocket.weight = 23.0; NSError* error; if (![rocket save: &error]) { return nil; } NSLog(@"Rocket Created"); }
  • 37. Adding Items - (IBAction) insertNewObject: (id)sender { ASDRocket* rocket = [ASDRocket modelForNewDocumentInDatabase:self.database]; rocket.name=name; rocket.weight = 23.0; NSError* error; if (![rocket save: &error]) { return nil; } NSLog(@"Rocket Created"); }
  • 38. Deleting Items -(void) tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete){ CBLQueryRow *row = [self.dataSource rowAtIndex:indexPath.row]; ASDRocket* rocket = [ASDRocket modelForDocument: row.document]; NSError* error; if (![rocket deleteDocument: &error]){ NSLog(@"Unable to delete Rocket"); return; } [self.tableView reloadData]; } }
  • 39. Replications CBLReplication *pull; CBLReplication *push; h; pull = [_database createPullReplication:_remoteURL]; pull.continuous = YES; pull.network = @"WiFi"; push = [_database createPushReplication:_remoteURL]; push.continuous = YES; pull.network = @"WiFi"; [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(replicationProgress:) name:kCBLReplicationChangeNotification push]; [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(replicationProgress:) name:kCBLReplicationChangeNotification pull];
  • 40. CBLModel ā€¢ Maps Objects to documents @interface ASDRocket : CBLModel + (NSString*) docType; @property (strong) NSString *name; @property (assign) double diameter; @property (assign) double weight; @property (assign) double coefficientFriction; /** Returns a query for all the rockets in a database. */ + (CBLQuery*) queryRocketsInDatabase: (CBLDatabase*)db; /** Returns a query for all the rockets with name in a database */ + (CBLQuery*) findInDatabase:(CBLDatabase*)db byName:(NSString *)name; @end
  • 41. CBLModel ā€¢ No types in documents ā€¢ convention is to use type ļ¬eld ā€¢ Map functions can pick out docs with the right type if (doc.type == ā€œrocketā€){ emit(doc.created, doc.text) };
  • 42. Summaryweā€™ve seen why no sql matters, and is needed shown how couch base can enable diļ¬ƒcult distributed computing next a demoā€¦.
  • 43. So What Happened 5 yrs earlier 28V components spec to also 65 Missed the memo
  • 45. Questions? ā€¢ @mwhagedorn ā€¢ http://spkr8.com/s/16930 ā€¢ https://github.com/mwhagedorn/ couchbase_ios_rockettown ā€¢ https://github.com/mwhagedorn/ couchbase_osx_rockettown