native apis for querying couchbase server with n1ql: couchbase connect
TRANSCRIPT
Native APIs for Querying Couchbase Server with N1QL
Jeff Morris | Software Engineer, CouchbaseMichael Nitschinger | Software Engineer, Couchbase
©2014 Couchbase, Inc. 2
Everything shown in this talk is a preview and subject to change before we ship official N1QL integration.
Take everything with a grain of salt and give us feedback to make it even better.
Disclaimer
Introduction
©2014 Couchbase, Inc. 4
Motivation
Querying is integral to Couchbase Server
SDKs need to provide first-class querying for Views N1QL
The 2.0 SDKs provide document oriented APIs and querying needsto blend together
©2014 Couchbase, Inc. 5
N1QL Overview
N1QL (“Nickel”) is the next generation query language for Couchbase Server
Designed to be similar to SQL First-Class JSON support
Currently in Developer Preview See http://query.couchbase.com
Supports SELECT, DML, DDL SDKs focus is on SELECT for now
©2014 Couchbase, Inc. 6
N1QL Primer: Select
©2014 Couchbase, Inc. 7
N1QL Primer: Joins
8
N1QL Primer: Popular Products in Category
©2014 Couchbase, Inc.
©2014 Couchbase, Inc. 9
2.0 Querying API
Provides consistent experience across Views N1QL
Blends into Document API
Sweet spot between Consistency across SDKs Language features
N1QL Querying in .NET
©2014 Couchbase, Inc. 11
Query Generators and Executers
• Ad-hoc queries• New LINQ Provider
Mapping results and Handling Errors
• Query Mapping• Query Results
N1QL Query Support in .NET SDK 2.0
©2014 Couchbase, Inc. 12
Part of the SDK 2.0 IBucket interface
Standard un-typed, string based queries
No syntactical help
Results can be mapped to POCOs or to a dynamic type
Supports all N1QL commands, keywords, etc
Errors are handled and propagated up to the caller
The current query interface for N1QL queries in Couchbase Server
Github Url: https://github.com/couchbase/couchbase-net-client
Ad-Hoc Queries
©2014 Couchbase, Inc. 13
Ad-hoc Query Example
©2014 Couchbase, Inc. 14
The QueryResult object
©2014 Couchbase, Inc. 15
Handling Errors
©2014 Couchbase, Inc. 16
Mapping to Types
©2014 Couchbase, Inc. 17
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 Brings familiar LINQ syntax to N1QL and Couchbase Server Currently supports a minimal subset of the N1QL language (this will
soon change) Errors are un-handled Results are mapped to POCOs The “future” query interface for N1QL and Couchbase Server in .NET
Linq2Couchbase
©2014 Couchbase, Inc. 18
Basic Queries
©2014 Couchbase, Inc. 19
Basic Queries: Projections to Anonymous Types
©2014 Couchbase, Inc. 20
Basic Queries: “where” clause
©2014 Couchbase, Inc. 21
Basic Queries: limit and range queries
22
Expect a GA released with N1QL GA
Eventually a “full-featured” LINQ provider
Anything that is not supported by the LINQ provider can be done via
IBucket.Query<T>(string query)
Linq2Couchbase: Future Support
©2014 Couchbase, Inc.
.NET Demo
N1QL Querying in Java
©2014 Couchbase, Inc. 25
Java SDK API
Access types Asynchronous (Reactive) using Rx Observables Synchronous
Utilizes a JSON streaming parser and pushes chunks as they arriveWorks on a per-bucket basis
©2014 Couchbase, Inc. 26
The Result of a Query
©2014 Couchbase, Inc. 27
The Row
©2014 Couchbase, Inc. 28
Synchronous Querying
©2014 Couchbase, Inc. 29
Synchronous Querying
©2014 Couchbase, Inc. 30
Asynchronous Querying
©2014 Couchbase, Inc. 31
N1QL DSL
The SDK ships with a N1QL DSL syntax aware (based on the EBNF) strongly typed
Should be used in favor of the raw string Makes developing N1QL queries a breeze Built-in IDE autocomplete awareness
Heavily inspired by jOOQ (http://www.jooq.org/)
©2014 Couchbase, Inc. 32
IDE Support
©2014 Couchbase, Inc. 33
IDE Support
©2014 Couchbase, Inc. 34
IDE Support
©2014 Couchbase, Inc. 35
Examples
©2014 Couchbase, Inc. 36
Examples
Java Demo
QA