N1QL Node.js fluent API


Do you guys plan on having a fluent N1QL API for the Node.js SDK, like the Java SDK?



var query = N1qlQuery.fromString('SELECT * FROM default');


This link may be useful for you.

Thank you, but the “fromString” function is not a fluent API, while the Java code I used as example is.

Basically what I want (and I’ll develop it internally if it’s not in the plans of Couchbase itself) is an abstraction layer so we don’t need to keep concatenating strings everywhere.


How did this go? I am kinda asking myself the same question right now. I don’t want to go down the road of concatenating strings everywhere…

Hey @corey_perkins,

Unfortunately, while Java’s import semantics allow them to import methods globally into their scope to allow you write concise expressive queries directly in Java; until recently, Node.js did not have such an equivalence. Specifically, in Java you are able to write something like import * from couchbase.n1ql and then use e('$age'), in Node.js you would have to write something far longer and less concise: N1qlQuery.e('$age'), while alone this does not seem like a significant difference, it was our experience that using these longer names simply increased complexity on any queries you were looking to dynamically generate.

That all being said. Some recently Javascript features such as modules have made this situation far better, and there may be an opportunity to build an extension library which provides query building as Java does. If you were interested, we could put together an extension library like this together using the Java DSL as a strong base for the semantics. Let me know if you are interested and I can throw together a starting point to use in relatively short order.

Cheers, Brett