N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

62
N1QL and SDK Support for Java, .NET and Node.js Nic | Developer Advocate, Couchbase Michael | SDK Engineer, Couchbase Martin | Developer Advocate, Couchbase

Transcript of N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

Page 1: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

N1QL and SDK Support for Java, .NET and Node.js

Nic | Developer Advocate, CouchbaseMichael | SDK Engineer, Couchbase

Martin | Developer Advocate, Couchbase

Page 2: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 2

N1QL Primer

Page 3: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 3

N1QL Primer

NoSQL...

Page 4: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 4

N1QL Primer

NoSQLbut why not a

query language

?

Page 5: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 5

N1QL Primer

querying on

relational data=

SQL

Page 6: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 6

N1QL Primer

querying on

JSON=

N1QL

Page 7: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 7

N1QL Primer

SELECT fname, children FROM tutorial

Page 8: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 8

N1QL Primer

SELECT fname, children FROM tutorial

looks like SQL?

Page 9: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 9

N1QL Primer

SELECT fname, children FROM tutorial

WHERE EVERY child IN tutorial.children

SATISFIES child.age > 10 END

Page 10: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 10

N1QL Primer

cbq-enginethe N1QL service

Page 11: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 11

N1QL Primer

cbq-enginethe N1QL service

integrated in Couchbase 4.0, port 8093

Page 12: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 12

N1QL Primer

cbqcommand line client

Page 13: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 13

N1QL Primer

responses are

JSON

Page 14: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 14

N1QL Primer{ "results": [ { "children": [ { "age": 17, "fname": "Abama", "gender": "m" }, { "age": 21, "fname": "Bebama", "gender": "m" } ], "fname": "Ian" } ]}

responses are

JSON

Page 15: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 15

N1QL Primer

responses have

MetaData

Page 16: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 16

N1QL Primer "requestID": "19bb1a64-633a-417a-833c-97a8b4c48e7e", "signature": { "Greeting": "string" }, "results": [ {"Greeting": "Hello World" "status": "success", "metrics": { "elapsedTime": "7.48ms", "executionTime": "6.8ms", "resultCount": 1, "resultSize": 49 }}

responses have

MetaData

Page 17: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 17

Usage in SDKs

Page 18: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 18

Usage in SDKs

C / C++

Page 19: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 19

Usage in SDKs

Page 20: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 20

Usage in SDKs

API at the

Bucketlevel

Page 21: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 21

Usage in SDKs

Statementin a

Querywith additional

Parameters

Page 22: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 22

Usage in SDKs

Statements can have

Placeholders

Page 23: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 23

Usage in SDKs

either

positional $1

Page 24: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 24

Usage in SDKs

or

named$param

Page 25: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 25

Usage in SDKs

Placeholder values

are passed in the query's parameters

Page 26: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 26

Usage in SDKs

Statements can be

Prepared

Page 27: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 27

Usage in SDKs

get a QueryPlanhold to it

then execute it

repeatedly

Page 28: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

N1QL + .NET SDKMartin Esmann | Developer Advocate,

Couchbase

Page 29: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 29

.NET

[1]SDKand [2]Extension

Support

Page 30: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 30

.NET [1]

[1]QueryRequest

API in the .NET SDK

Page 31: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 31

.NET [1]

AD HOC queriesVia IBucket

Page 32: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 32

.NET [1]

Support for all N1QL Features

Page 33: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 33

.NET [1]

A Wrapper around the

REST API

Page 34: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 34

.NET [1]

But adds:Type safety Intellisense Support

Fluent interface Data Mapper

Page 35: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 35

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 36: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 36

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 37: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 37

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 38: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 38

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 39: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 39

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 40: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 40

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 41: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 41

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 42: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 42

.NET [1]

var query = QueryRequest.Create(sql);var result = await ClusterHelper

.GetBucket(bucketName) .QueryAsync<dynamic>(query);if(result.Errors != null || !result.Success){ // error } else { var rows = result.Rows;}

Page 43: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 43

.NET [2]

[2] LINQProvider

Page 44: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 44

.NET [2]

Based off Re-Linq

[EF and NHibernate are too!]

Page 45: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 45

.NET [2]

E x t e n ds

The .NET SDK

Page 46: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 46

.NET [2]

Open Source[#please do contribute]

Page 47: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 47

.NET [2]

Provides a

SubsetOf the N1QL Language…

Page 48: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 48

.NET [2]

Also, Requires: Domain Model == JSON

structure

Page 49: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 49

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 50: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 50

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 51: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 51

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 52: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 52

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 53: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 53

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 54: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 54

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 55: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 55

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 56: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 56

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 57: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 57

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 58: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 58

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 59: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 59

.NET [2]using Couchbase.Linq;using Couchbase.Linq.Extensions;var bucket = ClusterHelper .GetBucket(bucketName);

var airlines = from airline in

bucket.Queryable<Airline>() where airline.Iata != null && airline.Type == "airline"

select airline;

return airlines.Take(1).ToList();

Page 60: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 60

DEMO

Page 61: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 61

Linq2Couchbase GA: Breaking Changes• New public API: IBucketContext • Similar to DbContext and DataContext but with

a more “doc centric” vibe• Bucket.Queryable<T> is no longer public

• EntityFilter, EntityFilterManager and all related classes are now DocumentFilter, DocumentFilterManager, etc.• More “doc centric” feel, better aligns with

Couchbase’s non-RDBMS roots• Dependency on ClusterHelper has been

removed.• BucketContext now takes a Cluster as an

argument.• Cluster can still be managed by ClusterHelper

as always

Page 62: N1QL and SDK Support for Java, .NET, and Node.js – Couchbase Live New York 2015

©2015 Couchbase Inc. 62

Q & A