Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

N1QL and SDK Support for Java, .NET, and Node.js: Couchbase Connect 2015

1,395 views

Published on

You’ve heard of the hot new query language called N1QL, but do you know what support is available in the official Couchbase SDKs? If not, the session is for you! In this session you will learn how to use N1QL in the SDKs. We’ll also cover the fluent DSL for Java, the Linq Provider for .NET based languages, as well as full-stack JavaScript development using the Node.js client.

Published in: Software
  • Be the first to comment

N1QL and SDK Support for Java, .NET, and Node.js: Couchbase Connect 2015

  1. 1. N1QL AND SDK SUPPORT FOR JAVA, .NET AND NODE.JS Simon Baslé, Jeff Morris and Todd Greenstein Couchbase
  2. 2. N1QL Primer
  3. 3. ©2015 Couchbase Inc. 3 N1QL Primer 3 NoSQL ...
  4. 4. ©2015 Couchbase Inc. 4 N1QL Primer 4 NoSQL but why not a query language ?
  5. 5. ©2015 Couchbase Inc. 5 N1QL Primer 5 querying on relational data = SQL
  6. 6. ©2015 Couchbase Inc. 6 N1QL Primer 6 querying on JSON = N1QL
  7. 7. ©2015 Couchbase Inc. 7 N1QL Primer 7 SELECT fname, children FROM tutorial
  8. 8. ©2015 Couchbase Inc. 8 N1QL Primer 8 SELECT fname, children FROM tutorial looks like SQL?
  9. 9. ©2015 Couchbase Inc. 9 N1QL Primer 9 SELECT fname, children FROM tutorial WHERE EVERY child IN tutorial.children SATISFIES child.age > 10 END
  10. 10. ©2015 Couchbase Inc. 10 N1QL Primer 10 cbq-engine the N1QL service
  11. 11. ©2015 Couchbase Inc. 11 N1QL Primer 11 cbq-engine the N1QL service integrated in Couchbase 4.0, port 8093
  12. 12. ©2015 Couchbase Inc. 12 N1QL Primer 12 cbq command line client
  13. 13. ©2015 Couchbase Inc. 13 N1QL Primer 13 responses are JSON
  14. 14. ©2015 Couchbase Inc. 14 N1QL Primer 14 { "results": [ { "children": [ { "age": 17, "fname": "Abama", "gender": "m" }, { "age": 21, "fname": "Bebama", "gender": "m" } responses are JSON
  15. 15. ©2015 Couchbase Inc. 15 N1QL Primer 15 responses have MetaData
  16. 16. ©2015 Couchbase Inc. 16 N1QL Primer 16 "requestID": "19bb1a64-633 "signature": { "Greeting": "string" }, "results": [ {"Greeting": "He "status": "success", "metrics": { "elapsedTime": "7.48ms" "executionTime": "6.8ms "resultCount": 1, "resultSize": 49 } } responses have MetaData
  17. 17. Usage in the SDKs
  18. 18. ©2015 Couchbase Inc. 18 Usage in the SDKs 18 C / C++
  19. 19. ©2015 Couchbase Inc. 19 Usage in the SDKs 19
  20. 20. ©2015 Couchbase Inc. 20 Usage in the SDKs 20 API at the Bucket level
  21. 21. ©2015 Couchbase Inc. 21 Usage in the SDKs 21 Statement in a Query with additional Parameters
  22. 22. ©2015 Couchbase Inc. 22 Usage in the SDKs 22 Statements can have Placeholders
  23. 23. ©2015 Couchbase Inc. 23 Usage in the SDKs 23 either positional $1
  24. 24. ©2015 Couchbase Inc. 24 Usage in the SDKs 24 or named $param
  25. 25. ©2015 Couchbase Inc. 25 Usage in the SDKs 25 Placeholder values are passed in the query's parameters
  26. 26. ©2015 Couchbase Inc. 26 Usage in the SDKs 26 Statements can be Prepared
  27. 27. ©2015 Couchbase Inc. 27 Usage in the SDKs 27 get a QueryPlan hold to it then executeit repeatedly
  28. 28. NodeJS N1QL in OttomanNodeJS ODM for Couchbase
  29. 29. ©2015 Couchbase Inc. 29 NodeJS 29 Class:N1qlQuery Running N1QL Queries using the Node Client
  30. 30. ©2015 Couchbase Inc. 30 NodeJS 30 // InstantiateThe Query API var couchbase = require('couchbase'); var myCluster = new couchbase.Cluster(‘localhost:8091”); var myBucket = myCluster.openBucket(‘travel-sample’); var myQuery = couchbase.N1qlQuery;
  31. 31. ©2015 Couchbase Inc. 31 NodeJS 31 function query(sql,done){ var queryToRun = myQuery.fromString(sql) .consistency(myQuery.Consistency.REQUEST_PLUS); myBucket.query(queryToRun,function(err,result){ if (err) { console.log("ERR:",err); done(err,null); return; } done(null,result); return; }); }
  32. 32. ©2015 Couchbase Inc. 32 NodeJS 32 function query(sql,done){ var queryToRun = myQuery.fromString(sql) .consistency(myQuery.Consistency.REQUEST_PLUS); myBucket.query(queryToRun,function(err,result){ if (err) { console.log("ERR:",err); done(err,null); return; } done(null,result); return; }); }
  33. 33. ©2015 Couchbase Inc. 33 NodeJS 33 function query(sql,done){ var queryToRun = myQuery.fromString(sql) .consistency(myQuery.Consistency.REQUEST_PLUS); myBucket.query(queryToRun,function(err,result){ if (err) { console.log("ERR:",err); done(err,null); return; } done(null,result); return; }); }
  34. 34. ©2015 Couchbase Inc. 34 NodeJS 34 function query(sql,done){ var queryToRun = myQuery.fromString(sql) .consistency(myQuery.Consistency.REQUEST_PLUS); myBucket.query(queryToRun,function(err,result){ if (err) { console.log("ERR:",err); done(err,null); return; } done(null,result); return; }); }
  35. 35. ©2015 Couchbase Inc. 35 NodeJS 35 function query(sql,done){ var queryToRun = myQuery.fromString(sql) .consistency(myQuery.Consistency.REQUEST_PLUS); myBucket.query(queryToRun,function(err,result){ if (err) { console.log("ERR:",err); done(err,null); return; } done(null,result); return; }); }
  36. 36. ©2015 Couchbase Inc. 36 NodeJS 36 function query(sql,done){ var queryToRun = myQuery.fromString(sql) .consistency(myQuery.Consistency.REQUEST_PLUS); myBucket.query(queryToRun,function(err,result){ if (err) { console.log("ERR:",err); done(err,null); return; } done(null,result); return; }); }
  37. 37. ©2015 Couchbase Inc. 37 NodeJS 37 function query(sql,done){ var queryToRun = myQuery.fromString(sql) .consistency(myQuery.Consistency.REQUEST_PLUS); myBucket.query(queryToRun,function(err,result){ if (err) { console.log("ERR:",err); done(err,null); return; } done(null,result); return; }); }
  38. 38. Demo
  39. 39. Java N1QL in
  40. 40. ©2015 Couchbase Inc. 40 Java 40 Statement or QueryPlan
  41. 41. ©2015 Couchbase Inc. 41 Java 41 [+ QueryParams ]
  42. 42. ©2015 Couchbase Inc. 42 Java 42 [+ JsonArray ] for placeholder values
  43. 43. ©2015 Couchbase Inc. 43 Java 43 Query =
  44. 44. ©2015 Couchbase Inc. 44 Java 44 Query .simple(...)
  45. 45. ©2015 Couchbase Inc. 45 Java 45 Query .parametrized(...)
  46. 46. ©2015 Couchbase Inc. 46 Java 46 Query .prepared(...)
  47. 47. ©2015 Couchbase Inc. 47 Java 47 the QueryResult
  48. 48. ©2015 Couchbase Inc. 48 Java 48 the QueryResult parseSuccess() finalSuccess()
  49. 49. ©2015 Couchbase Inc. 49 Java 49 the QueryResult allRows() errors() info()
  50. 50. ©2015 Couchbase Inc. 50 Java 50 the QueryResult requestId() clientContextId() signature()
  51. 51. ©2015 Couchbase Inc. 51 Java 51 the QueryResult can be an AsyncQueryResult
  52. 52. ©2015 Couchbase Inc. 52 Java 52 the DSL building SELECT statements with code
  53. 53. ©2015 Couchbase Inc. 53 Java 53 import static Select.select; import static Expression.*;
  54. 54. ©2015 Couchbase Inc. 54 Java 54 SELECT * FROM `bucket` WHERE token > 100
  55. 55. ©2015 Couchbase Inc. 55 Java 55 select("*") .from(i("bucket")) .where(x("token").gt(100))
  56. 56. ©2015 Couchbase Inc. 56 Java 56 select("*") .from(i("bucket")) .where(x("token").gt(100))
  57. 57. ©2015 Couchbase Inc. 57 Java 57 select("*") .from(i("bucket")) .where(x("token").gt(100))
  58. 58. ©2015 Couchbase Inc. 58 Java 58 select("*") .from(i("bucket")) .where(x("token").gt(100))
  59. 59. ©2015 Couchbase Inc. 59 Java 59 select("*") .from(i("bucket")) .where(x("token").gt(100))
  60. 60. ©2015 Couchbase Inc. 60 Java 60 select("*") .from(i("bucket")) .where(x("token").gt(100))
  61. 61. ©2015 Couchbase Inc. 61 Java 61 select("*") .from(i("bucket")) .where(x("token").gt(100))
  62. 62. Demo
  63. 63. .Net N1QL in
  64. 64. ©2015 Couchbase Inc. 64 .NET 64 [1]SDKand [2]Extension Support
  65. 65. ©2015 Couchbase Inc. 65 .NET [1] 65 [1]QueryRequest API in the .NET SDK
  66. 66. ©2015 Couchbase Inc. 66 .NET [1] 66 AD HOC queries Via IBucket
  67. 67. ©2015 Couchbase Inc. 67 .NET [1] 67 Support for all N1QL Features
  68. 68. ©2015 Couchbase Inc. 68 .NET [1] 68 A Wrapper around the REST API
  69. 69. ©2015 Couchbase Inc. 69 .NET [1] 69 But adds: Type safety Intellisense Support Fluent interface Data Mapper
  70. 70. ©2015 Couchbase Inc. 70 .NET [2] 70 [2] LINQ Provider
  71. 71. ©2015 Couchbase Inc. 71 .NET [2] 71 Based off Re-Linq[EF and NHibernate are too!]
  72. 72. ©2015 Couchbase Inc. 72 .NET [2] 72 E x t e n d s The .NET SDK
  73. 73. ©2015 Couchbase Inc. 73 .NET [2] 73 Open Source [do contribute]
  74. 74. ©2015 Couchbase Inc. 74 .NET [2] 74 Provides a Subset Of the N1QL Language… [currently, but that will change]
  75. 75. ©2015 Couchbase Inc. 75 .NET [2] 75 Also, Requires: Domain Model == JSON structure
  76. 76. Demo
  77. 77. Q&A
  78. 78. Thank you.

×