N1QL Node.js fluent API

Hello,

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

N1qlQuery.simple(select("*").from(i("beer-sample")).limit(10))

Thanks!

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

http://developer.couchbase.com/documentation/server/4.1/sdks/node-2.0/n1ql-queries.html

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.

2 Likes

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