Validating a N1QL statement using couchbase SDK or RestAPI

Hi, I am working on getting an editor in our application which will validate the N1QL statements. Is there an editor that I can use? I couldn’t find one.
Or can I use couchbase SDK or RestAPI to validate the same?

I think the simplest would be to execute ‘EXPLAIN’ for your query : Successful Request | Couchbase Docs

curl -v -u Administrator:password 'http://localhost:8093/query/service?statement=EXPLAIN%20SELECT%20*%20FROM%20my_bucket'

This post has suggestion : AST Generator for N1QL - #7 by eben

1 Like

@rahul What platform are you using for creating the editor?

We don’t have a solution for completely validating N1QL expressions, though the following two items from the web-based admin console might help:

  • The regular UI uses an Ace editor for editing the query. We created a N1QL mode for Ace, which is defined here:

That mode provides keyword coloring (and has a formatting feature), but does not check query syntax.

  • The regular UI has an experimental javascript N1QL parser which might work for you, it can be found here:
1 Like