• Share
  • Email
  • Embed
  • Like
  • Private Content
Developing couchbase part iii   advanced app dev
 

Developing couchbase part iii advanced app dev

on

  • 2,009 views

 

Statistics

Views

Total Views
2,009
Views on SlideShare
2,009
Embed Views
0

Actions

Likes
0
Downloads
11
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI
  • make JS code screenshot of admin UI or show admin UI

Developing couchbase part iii   advanced app dev Developing couchbase part iii advanced app dev Presentation Transcript

  • Developing with Couchbase Part III: Using the Client Libraries John Zablocki Developer Advocate @codevoyeur 1
  • About Me{ " _id" : "John Zablocki”, "Title" : "Developer Advocate", "Company" : "Couchbase", "Books" : [ { "Title" : "Orchard CMS", "Publisher" : "OReilly" } ], "Twitter" : "@CodeVoyeur", "Email" : "john@couchbase.com", "Meetup" : "Beantown ALT.NET“, "Code" : [ "https://github.com/jzablocki", http://bitbucket.com/johnzablockis ], "Blogs" : [ "http://dllhel.net", "http://blog.couchbase.com" ]}
  • Agenda● Documents, Objects and Schemas● View Review● .NET Client API● Demo: TapMap● Q&A
  • PreambleAll examples are in C# using the Couchbase .NET Client Library 1.2 (Developer Preview)Download at couchbase.com/develop/net/nextHeres how to connect to Couchbase Server:var config = new CouchbaseClientConfiguration();config.Urls.Add(new Uri(http://192.168.1.2:/8091/pools/default));config.Urls.Add(new Uri(http://192.168.1.3:/8091/pools/default));config.Bucket = “protected”;config.BucketPassword = “s3cr3t”;var client = new CouchbaseClient(config); 4
  • View ReviewDocuments, Objects View Review .NET View API and Schemas Demo: Q&A TapMap
  • Remember when we said that Couchbase documents were schema-less? 6
  • Well, it’s not quite that simple… 7
  • Recall those beer documents…{ "_id": "beer_abbey_ale", "type": "beer", "name": "Abbey Ale", "brewery": "brewery_Brewery_Ommegang", "abv": 7.1, "style": "Ale" A sc} hem a 8
  • Where did it come from? 9
  • A C# Class public class Beer { public string Id { get; set; } a m A sche public string Name { get; set; } public double ABV { get; set; } public override string Type { get { return "beer"; } } } 10
  • Your object model often becomes your schema, but how? 11
  • A C# Class [Serializable] public class Beer { [JsonProperty(PropertyName = "_id")] g public string Id { get; set; } am appin As chem [JsonProperty("name")] public string Name { get; set; } [JsonProperty("abv")] public double ABV { get; set; } [JsonProperty(“type")] public override string Type { get { return "beer"; } } } 12
  • Storing your model in C# var key = “beer_Three_Philosophers”; var getResult = client.GetWithCas(key); var beer = getResult.Result; ation beer.Name = “Three Philosophers”; e mafic Sch var json = JsonConvert.Serialize(beer); var casResult = client.Cas(StoreMode.Set, key, json, getResult.Cas); ! var message = casResult.Result Yum ? “Success” : “Failure”; Console.WriteLine(message); 13
  • View ReviewDocuments, Objects View Review .NET View API and Schemas Demo: Qestions TapMap
  • These Couchbase guys really like their beer… 15
  • Yeah, we do… 16
  • It’s a much more interestingdata source than Northwind, no? 17
  • Beer Documents e key iqu{ Un "_id": "beer_abbey_ale", "_rev": "1-00003e56befe4b4f0000005600000112", e typ "$flags": 0, ent eer "$expiration": 0, Do cum eb som "type": "beer", A we "name": "Abbey Ale", "brewery": "brewery_brewery_ommegang", "abv": 7.1} 18
  • Let’s create an index on beer name…_design/beers/_view/by_name// map functionfunction (doc) { if (doc.type == "beer“ && beer.name) { emit(doc.name, null); }}The results…[{"id":"beer_abbey_ale","key":"Abbey Ale","value":null},{"id":"beer_american_ale","key":"American Ale","value":null},{"id":"beer_harpoon_ipa","key":"Harpoon IPA","value":null},{"id":"beer_long_trail_ale","key":"Long Trail Ale","value":null},{"id":"beer_old_yankee_ale","key":"Old Yankee Ale","value":null},{"id":"beer_three_philosophers","key":"Three Philosophers","value":null}] 19
  • .NET View APIDocuments, Objects View Review .NET View API and Schemas Demo: Qestions TapMap
  • Calling the view from .NET c me do navia .NET sign iew De Vvar view = client.GetView("beers", key ent cum"by_name"); Doforeach(var item in view) { var beer =client.Get<Beer>(item.ItemId); Console.WriteLine(beer.Name);} 21
  • Finding a beer by name…_design/beers/_view/by_name?key=“Abbey Ale”via .NET h m atc ct Exavar view = client.GetView("beers", "by_name") .Key(“Abbey Ale”) .FirstOrDefault();var beer = client.Get<Beer>(item.ItemId); 22
  • Finding a range of beers by name…_design/beers/_view/by_name?startkey=“A”&endkey=“D”var view = client.GetView("beers", "by_name") .StartKey(“A”).EndKey(“D”);foreach(var item in view) { var beer = client.Get<Beer>(item.ItemId); Console.WriteLine(beer.Name);} 23
  • Limiting and skipping beers…_design/beers/_view/by_name?limit=10&skip=2var view = client.GetView("beers", "by_name") .Limit(5).Skip(5);foreach(var item in view) { var beer = client.Get<Beer>(item.ItemId); Console.WriteLine(beer.Name);} 24
  • Finding a strong ale…The viewfunction (doc) { if (doc.type == "beer" && doc.style &&doc.abv) { emit([doc.style, doc.abv], null); }} 25
  • Finding a strong ale…C# Examplevar view = client.GetView("beers","by_style_and_abv") .StartKey(new object[] { “Ale”, 6.0 }) .EndKey(new object[] { “Ale”, 10 });foreach(var item in view) { var beer = client.Get<Beer>(item.ItemId); Console.WriteLine(beer.Name);} 26
  • Finding breweries by provinceThe brewery document{ "_id": "brewery_cottrell_brewing", "_rev": "1-00003e56c0e830c80000005900000112", "$flags": 0, "$expiration": 0, "type": "brewery", "name": "Cottrell Brewing", "city": "Pawcatuck", "province": "Connecticut"} 27
  • Finding breweries by provinceThe map functionfunction (doc) { if (doc.type == "brewery" && doc.province) { emit(doc.province, doc.name); }} 28
  • Map/Reduce – Map Results• The conceptual output of the map function is [{"key":"Connecticut", "value":"Cottrell Brewing"}, {"key":"Connecticut","value":"Thomas Hooker Brewing Co."},{"key":"Massachusetts","value":"Harpoon Brewing Company"}, {"key":"New York","value":"Brewery Ommegang"},{"key":"Vermont","value":"Long Trail Brewing Company"}]
  • Map/Reduce – Reduce Function• A reduce function to count breweries by province – Or simply use the build in _count function function (keys, values) { return values.length;}• The conceptual input to the reduce function is:[{"keys":["Connecticut", "Connecticut"], "values": ["Cottrell Brewing", "Thomas Hooker Brewing Co."]}, {"keys":["Massachusetts"],"values":["Harpoon Brewing Co."]}, {"keys":["New York"],"values":["Brewery Ommegang"]},{"keys":["Vermont"],"values":["Long Trail Brewing Company“]}]
  • Map/Reduce – Reduce Results • The conceptual result of the reduce is {"key":"Connecticut","value":2}, {"key":"Massachusetts","value":1}, {"key":"New York","value":1}, {"key":"Vermont","value":1}
  • Map/Reduce .NET Code_design/beers/_view/by_name?limit=10&skip=2var view = client.GetView(“breweries", "by_province") .Group(true);foreach(var item in view) { Console.WriteLine(item.ItemId);}
  • Demo: TapMapDocuments, Objects View Review .NET View API and Schemas Demo: Qestions TapMap
  • TapMap
  • TapMap Info• Written in C#, with ASP.NET MVC 4• Code available at: http://github.com/couchbaselabs/TapMap• Demonstrates common web app behaviors using Couchbase Server 2.0 – Find a user in the database by username and password – When creating a new user, verify a username and email are unique – Filter a select list data source from the value of another – Show data items on a map• Demonstrates using a client library with common architectural patterns – Working with a Repository of T – Creating a domain models • Document mapping • Model inheritance • Model composition – Managing the client resources
  • Q&ADocuments, Objects View Review .NET View API and Schemas Demo: Q&A TapMap