couchbase live europe 2015: .net data access strategies for couchbase and language integrated query
TRANSCRIPT
![Page 1: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/1.jpg)
.NET Data Access Strategies for Couchbase and Language Integrated QueryUsing Couchbase with .NET
Martin Esmann Developer Advocate
twitter: [email protected]
![Page 2: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/2.jpg)
2
Who’s to blame?
![Page 3: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/3.jpg)
3
Goal!
Learn how to access data in Couchbase Server with the .NET SDK
With the main focus on N1QL
I’m assuming you know a bit about N1QL already
![Page 4: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/4.jpg)
4
Agenda
• Couchbase – Quick Overview
• Couchbase .NET SDK 2.X
• Basic Data Access Operations
• Views (…)
• N1QL – SQL like query for Couchbase
• Linq2Couchbase
• Best practices – Application Architecture and Abstractions
• What’s coming next (async, await, observable, reactive)
![Page 5: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/5.jpg)
5
Disclaimer
Details presented in this presentation may change based on customer feedback and other factors by the time the final version of the product is released.
![Page 6: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/6.jpg)
Couchbase – Quick Overview
6
![Page 7: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/7.jpg)
7
Couchbase – Quick Overview
A document store and key-value store
Lightning fast: built-in caching
Query with map-reduce and N1QL
Scales massively
Key benefit: it’s simple and fast.
Challenges (before N1QL):
Data query requires more work
![Page 8: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/8.jpg)
8
Views vs N1QL
Views are sill very relevant an in many cases the recommended approach to data query.
Compared to Views, N1QL is even more flexible in terms of search capability, but with this flexibility there is a potential tradeoff for performance (automatic indexes).
In short, Views definitely have there place and so does N1QL it just depends on you specific needs.
![Page 9: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/9.jpg)
Current demo setup
9
![Page 10: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/10.jpg)
10
Developer Environment Setup - Overview
Application ServerCouchbase Cluster
(3 nodes, 8GB, 4 cores)
Demo PC with Visual Studio(Code runs from here)
Windows Azure Cloud
Virtual Network(private)
![Page 11: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/11.jpg)
11
Demo Setup - Overview
Couchbase Node(1 node, 8GB, 4 cores)
Demo PC with Visual Studio(Code runs from here)
Windows Azure Cloud
N1QL DP 4(Separate download)
Virtual Network(private)
![Page 12: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/12.jpg)
Couchbase .NET SDK
12
![Page 13: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/13.jpg)
13
.NET SDK overview
Main purpose of any SDK is to make life easier for developers!
• Cluster
• Bucket
• ClientConfiguration
• ClusterHelper*
![Page 14: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/14.jpg)
14
Cluster Object
• Maintains references to all open buckets
• Should be a singleton (in most applications)
• Maintains the current state of the Couchbase Cluster or Server
• Publishes config updates
• Factory for: ClusterManager
![Page 15: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/15.jpg)
15
Bucket class
• “Super API” for all other APIs
• Memcached (K/V)
• Views
• N1QL
• Subscriber for config changes
• Serialization/Deserialization
• Transcoding
![Page 16: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/16.jpg)
16
ClientConfiguration Class
• Configures bootstrapping, connection pooling and general client behavior
• Maps (“adapts”) to config file
• Allows for programmatic configuration of client
• Contains useful defaults - e.g. http:localhost:8091
• Bucket level overrides Cluster level configuration
![Page 17: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/17.jpg)
17
ClusterHelper
• Makes it “easy” to use the Cluster/Bucket
• Cluster is a singleton
• Buckets are multitons
• It will make your life easier, use it
![Page 18: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/18.jpg)
19
The IResult Interface
• As a rule the Bucket class doesn’t “throw” exceptions
• IResult is the primary interface for return values of all APIs:
• IViewResult
• IOperationResult and IentityResult
• IQueryResult
• The interface defines
• Message
• Exception
• Success
• Other info defined in more specialized interfaces
![Page 19: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/19.jpg)
21
.NET SDK Query options
• Key/value
• Views (we will not cover views in this talk)
• N1QL (pronounced nickel)
• SQL like query language for Couchbase
• “SQL for Documents”
![Page 20: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/20.jpg)
DemoQuerying data with the .NET SDK and N1QL
![Page 21: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/21.jpg)
Linq2CouchbaseThe best from N1QL and LINQ
23
![Page 22: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/22.jpg)
24
LINQ support for N1QL
Linq2Couchbase is a LINQ provider that wraps a subset of the available N1QL queries to LINQ
• An extension of the Couchbase .NET SDK 2.0
• Open Source Apache 2.0 License (Pull requests kindly accepted!)
• Github url: https://github.com/couchbaselabs/Linq2Couchbase
• Currently supports a minimal subset of the N1QL language (this will soon change)
• Errors are un-handled
• Results are mapped to POCOs
![Page 23: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/23.jpg)
DemoN1QL with LINQ
![Page 24: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/24.jpg)
Best practices – Application Architecture and Abstractions
Software design principles, maintainability and testable code strategies.
“craftsmanship”
26
![Page 25: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/25.jpg)
27
Design decisions
• N1QL in the UI layer?
• Queries in the UI Layer?
• Hard vs. Loose coupling to Couchbase SDK?
• Testability?
• Maintainability?
• Separation of concerns…
![Page 26: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/26.jpg)
28
The Repository Pattern
“Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.”
- Martin Fowler
• Creates an abstraction between BL and DAL
• Makes it possible to write persistence store, agnostic apps
• Enabler for TDD
• In general, provides a common language and structure
accessing data
• If you don’t like the Repository, try DTO/DAO pattern or some
other data access pattern…or not!
![Page 27: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/27.jpg)
DemoRepository pattern
29
![Page 28: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/28.jpg)
Couchbase .NET SDK version NEXTKnowledge about tomorrow can greatly help us plan
today!
30
![Page 29: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/29.jpg)
31
The Ubiquitous Repository
“Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.”
- Martin Fowler
• Creates an abstraction between BL and DAL
• Makes it possible to write persistence store, agnostic apps
• Enabler for TDD
• In general, provides a common language and structure
accessing data
• If you don’t like the Repository, try DTO/DAO pattern or some
other data access pattern…or not!
![Page 30: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/30.jpg)
32
.NET SDK - Version Next
• async/await support
• Observable support
- Excepted ETA is April
• LINQ to N1QL support in SDK
- High priority, but no specific release date yet.
![Page 31: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/31.jpg)
Summary
33
![Page 32: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/32.jpg)
34
Resources
• .NET SDK
https://github.com/couchbase/couchbase-net-client
• Linq2Couchbase
https://github.com/couchbaselabs/Linq2Couchbase
• N1QL installer
http://www.couchbase.com/nosql-databases/downloads
• Azure Setup guide
http://
blog.couchbase.com/hosting-couchbase-server-in-windows-azure-part-
1
![Page 33: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/33.jpg)
35
Key take-aways
• Couchbase supports advanced data query with N1QL
• LINQ support in the workings
• async/await + Observable support just around the corner!
• N1QL will be part of Couchbase Installer for GA (Sherlock).
Contributions are highly appreciated especially around
LINQ support for N1QL!
![Page 34: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/34.jpg)
Forums
forums.couchbase.com
36
![Page 35: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/35.jpg)
Questions?
37
![Page 36: Couchbase Live Europe 2015: .NET Data Access Strategies for Couchbase and Language Integrated Query](https://reader036.vdocument.in/reader036/viewer/2022062420/55d58cffbb61eb1f218b463e/html5/thumbnails/36.jpg)
Thanks for listening!Martin Esmann
Developer Advocate @ CouchbaseTwitter: martinesmann
38