Your SlideShare is downloading. ×
0

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Developing couchbase part iii advanced app dev

2,046

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,046
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • 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
  • Transcript

    • 1. Developing with Couchbase Part III: Using the Client Libraries John Zablocki Developer Advocate @codevoyeur 1
    • 2. 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" ]}
    • 3. Agenda● Documents, Objects and Schemas● View Review● .NET Client API● Demo: TapMap● Q&A
    • 4. 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
    • 5. View ReviewDocuments, Objects View Review .NET View API and Schemas Demo: Q&A TapMap
    • 6. Remember when we said that Couchbase documents were schema-less? 6
    • 7. Well, it’s not quite that simple… 7
    • 8. 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
    • 9. Where did it come from? 9
    • 10. 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
    • 11. Your object model often becomes your schema, but how? 11
    • 12. 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
    • 13. 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
    • 14. View ReviewDocuments, Objects View Review .NET View API and Schemas Demo: Qestions TapMap
    • 15. These Couchbase guys really like their beer… 15
    • 16. Yeah, we do… 16
    • 17. It’s a much more interestingdata source than Northwind, no? 17
    • 18. 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
    • 19. 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
    • 20. .NET View APIDocuments, Objects View Review .NET View API and Schemas Demo: Qestions TapMap
    • 21. 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
    • 22. 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
    • 23. 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
    • 24. 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
    • 25. Finding a strong ale…The viewfunction (doc) { if (doc.type == "beer" && doc.style &&doc.abv) { emit([doc.style, doc.abv], null); }} 25
    • 26. 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
    • 27. 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
    • 28. Finding breweries by provinceThe map functionfunction (doc) { if (doc.type == "brewery" && doc.province) { emit(doc.province, doc.name); }} 28
    • 29. 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"}]
    • 30. 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“]}]
    • 31. 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}
    • 32. 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);}
    • 33. Demo: TapMapDocuments, Objects View Review .NET View API and Schemas Demo: Qestions TapMap
    • 34. TapMap
    • 35. 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
    • 36. Q&ADocuments, Objects View Review .NET View API and Schemas Demo: Q&A TapMap

    ×