DataGrip from JetBrains has added NoSQL Couchbase support. It was first made available in their 2020.3 EAP (Early Access Preview)

This is a very exciting release. In this blog post, I’m going to introduce DataGrip and show you how to get started using its NoSQL capabilities with Couchbase. As of right now, this functionality is all still in EAP, but it will soon be available in the main release of DataGrip.

What is DataGrip?

JetBrains DataGrip is an IDE designed for SQL developers and database professionals. With it, you can write SQL in an intelligent query console with autocomplete, connect to multiple database servers/clusters, run queries, and much more.

It’s built on the IntelliJ IDEA platform, one of the top IDE platforms in the world. Rider, PhpStorm, PyCharm, WebStorm, and more are all built on the same excellent foundation.

DataGrip Support for Couchbase

DataGrip has been gradually adding support for NoSQL databases, along side the typical array of relational database support (PostgreSQL, SQLite, Azure SQL, etc).

Couchbase support is a natural fit for an IDE that focuses on SQL development. Despite being a “NoSQL” database, Couchbase has had its own full SQL implementation for years (called N1QL).

Other NoSQL databases like Redis, Elasticsearch, OrientDB, DynamoDB, and more may be in the cards for the future.

How does DataGrip connect to Couchbase?

JetBrains has created their own JDBC Driver for DataGrip. This JDBC driver supports N1QL with some extensions for basic bucket management. You can check out the source code for the Couchbase N1QL JDBC Driver on Github.

This driver is automatically installed and updated from within DataGrip, as you’ll see later in the “getting started” section.

(If you’re looking for ODBC/JDBC connectors for integration with tools other than DataGrip, don’t forget to check out Couchbase ODBC and JDBC Drivers from CData).

Getting Started – A Short DataGrip Tutorial

In this short tutorial, you’ll see how to get started using DataGrip to query data from Couchbase with N1QL. You’ll see:

  • How to setup Couchbase as a new datasource
  • How to execute a N1QL query
  • Some basic features like autocomplete and data extractors.

Install Couchbase locally

There are many ways to deploy Couchbase Server:

  • On-Premises (Non-Cloud) – Windows / Linux / Mac
  • VMs / containers / cloud – Docker / Kubernetes / AWS / Azure / etc
  • DBaaS – Couchbase Cloud

For local development, I prefer to install it via a Docker container. You can do the same by following this quick start: Couchbase Server CE Docker Container – Example Manual Configuration.

Any of these methods should work fine with DataGrip. Make sure that Couchbase Server is accessible from wherever you intend to run DataGrip (i.e. your laptop) and that all the necessary ports are opened.

Finally, for this tutorial, I’ll be using the travel-sample sample bucket.

Download and Install DataGrip EAP

At the current time, DataGrip with Couchbase support is EAP (Early Access Preview). The JetBrains EAP program doesn’t require you to purchase a license. EAP versions do expire.

Click “Download” next to the latest EAP build and follow DataGrip’s instructions to install. If you’ve never used DataGrip before, I recommend checking out the Quick Start Guide.

DataGrip Setup for Couchbase

After installing DataGrip, let’s connect it to Couchbase Server.

You can click File → New → Data Source → Couchbase Query, or you can click the “+” in the Database pane, then Data Source → Couchbase Query.

New Data Source in DataGrip

Configure the connection to Couchbase using the following values:

  • Name: couchbase-local
  • Host: localhost
  • Port: 11210 (More information on Couchbase port numbers, make sure that ports 8091-8096 and 11210 are all open)
  • Database User: Administrator (if you followed the guide)
  • Password: password (if you followed the guide)
  • Default bucket: travel-sample

New Data Source in DataGrip

It’s a good idea to click “Test Connection” to make sure the connection is working, the DataGrip setup is correct, all the correct ports are open, and everything is ready before proceeding.

If this is your first time connecting to Couchbase from DataGrip, you may see a prompt to download the JDBC driver. Click “Download Driver Files” to proceed.

New Data Source in DataGrip

When there are driver updates, you can also install them directly from DataGrip.

Test Drive DataGrip against a Couchbase cluster

At this point, couchbase-local should appear in the DataGrip Database pane. “travel-sample” should also appear. If it does not, try a right-click and then “Refresh”.

Couchbase in the Database window pane

As you start to explore DataGrip, remember that this is an EAP. The experience of those reading this months from now may be slightly different. Enhancements are coming soon to better help you navigate Couchbase buckets and the data in them. If you find any bugs or think of ideas for enhancements, create a DataGrip issue on JetBrains’s YouTrack site.

Now, let’s try running a N1QL query. Right click on travel-sample → New → Query Console. This will give you a workspace to start writing your N1QL (SQL for JSON). Here’s an example you can copy/paste into DataGrip:

Click the green “Execute” button to run the query.

The results will appear in the DataGrip output window in “table” format. However, Couchbase is still returning JSON data. You can click the “eye” icon above the DataGrip output window to change to “text” view to see the raw JSON.

DataGrip text view

Also notice that you can change the results view from JSON to HTML, Markdown, XML, etc.

Couchbase in the Database window pane

Autocomplete

Another great thing about DataGrip is autocomplete and autosuggestion (like IntelliSense in Visual Studio).

Let’s try typing out the query instead of copy/pasting it. Along the way, you’ll get helpful, time-saving suggestions which you can autocomplete by pressing TAB. Here’s an example animation:

DataGrip autosuggest with Couchbase N1QL

Summary

If you’re experienced with Couchbase, you know that much of what is being demonstrated here can already be done already with Couchbase’s built-in Query Workbench, cbq, and even the relatively new experimental Couchbase Shell project.

But this tutorial is just scratching the surface of what DataGrip can do. Like all JetBrains products that I’ve used, DataGrip just makes my development experience smoother.

Plus, if you’re working on a project or a team that uses multiple database technologies, you don’t have to leave DataGrip to work with them. You can do all your database work in one place.

What’s next?

Download the DataGrip EAP 2020.3 and try it out with Couchbase. Or check to see if DataGrip 2020.3 has been released. If you think you’ve found a bug, issue, or area for improvement within DataGrip, make sure to submit your issue to JetBrains. If you have a technical question about Couchbase, post it to the Couchbase Forums.

Follow DataGrip on Twitter for all the latest news.

If you’re new to Couchbase’s N1QL (SQL for JSON), you can check out an interactive web-based sandbox tutorial right now.

Also check out Couchbase Shell, which supports not only N1QL, but also key/value access, fake data generation, and more.

Finally, if you want to get started developing with Couchbase, check out the Couchbase Developer Portal.

Author

Posted by Matthew Groves

Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.

Leave a reply