Couchbase Server 4.5 and GO_CBQ
With Couchbase Server 4.5, we are providing a new enhanced commandline query execution tool called “go_cbq”. The new binary comes with capabilities for scripting support, connection management and more.
I have been using go_cbq for a while now and I love it. Most of the coding I do these days happen to be sample code with SDKs, N1QL and shell scripts these days, and having a powerful editor makes it fun. Recently, I decided to check out Visual Studio Code. It works on Mac & Windows and makes life pretty easy if you are dabbling in the same space that I am.
Editing and Executing N1QL within Visual Studio Code
Visual Studio Code is a pretty simple tool with smart editors for many languages. I am using it for GO experimentation these days but SQL editor is pretty powerful as well. With simple to customize “tasks”, it was also super simple to get the sql editor and go_cbq to work together for executing N1QL queries in Couchbase Server. I am doing this on Windows but all of the below applies to Mac as well. Here is how you can use Visual Studio Code and Couchbase Server with N1QL together to edit and execute queries.
1- Add couchbase bin directory to your PATH (c:Program FilesCouchbaseServerbin on Windows or /Applications/Couchbase Server.app/Contents/Resources/couchbase-core/bin/ if you are on Mac)
2- Start Visual Studio Code and “Open a Folder” – this becomes your working directory.
3- Edit your tasks.json file with the following JSON (tasks.json file is create under the .vscode directory under the folder you opened – create a tasks.json file if you don't see it there).
– Open a new .sql file and edit some N1QL statements – these lists the indexes and buckets in the system.
SELECT * FROM system:indexes;
SELECT * FROM system:keyspaces;
– Launch the execute task: Use CTRL-P on Windows or COMMAND-P on Mac and type “task” and a space. Select go_cbq option. and Bang! you will see the
go_cbq output in the output window.
Folks at Microsoft seems to be adding new capabilities every day so I am sure you can do better than I did with tasks customization. Here is how you can work with tasks in VS Code.
Thanks to Jeff Morris for turning me to the tool.