The proliferation of mobile devices and the Internet of Things has created a new set of requirements for todays IT infrastructure. Scalability and the need to adapt to rapidly changing data requirements have popularized a wave of NoSQL backend datastores. Typically though, this kind of datastore has been difficult to use with mobile devices. In this talk I want to present Couchbase as a solution to many mobile NoSQL problems. It provides disconnected and connected operation, high scalability and all the flexibility that any NoSQL solution provides, and it does this without requiring the developer to write complicated synchronization code between the mobile client and the backend datastore. Couchbase and its sync gateway handles all of this for you leaving you to focus on your business logic. In addition, this power can be leveraged across Android, Windows, Linux and others. I will present a short intro on the power and scalability of document databases and then show a demo of a set of different clients all talking to the same backend and demonstrate the near realtime updates possible. Have you had trouble understanding complex datastores such as CoreData? Then this talk is for you. Its all about getting stuff done in a straightforward, performant and yes cross platform way. Stop pounding rocks together and get stuff done!
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!
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
}
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