blog-banner

Executing SQL queries from the browser

Last edited on November 9, 2023

0 minute read

    Over the last couple weeks, you might have noticed a new tab on the cluster view of CockroachDB Cloud! We just released an open preview of our Browser SQL Shell, which allows writing queries on your database within seconds of cluster creation.

    Over the last couple weeks, you might have noticed a new tab on the cluster view of CockroachDB Cloud! We just released an open preview of our Browser SQL Shell, which allows writing queries on your database within seconds of cluster creation.

    1-cockroachdb-sql-queries-executing-in-browser

    Why we built itCopy Icon

    While I’m not going to say all SQL should be executed from the browser, working with your database should have as little friction as possible. Iterating on schemas, testing syntax, and executing queries shouldn’t require generating a user and saving a password when you’re getting started. I’m sure we’ve all had stacks of notes storing way too many autogenerated strings for our database credentials.

    With CockroachDB Cloud, you can create a multi-region serverless database in less than 30 seconds. Writing SQL queries should feel just as fast, and take advantage of the flexibility a web client has to make the experience better.

    Internally, it’s been nice to use it during schema development and validating data in clusters. These little bits of time add up! A shell helps us refocus on the parts of building an app.

    Syntax highlighting and UX with CockroachDBCopy Icon

    The SQL shell isn’t the first experience we’ve released with Syntax highlighting and SQL execution from the browser. Last year, we released our MOLT Schema Conversion Tool (SCT), which helps you iterate on DB schemas while converting it to CockroachDB. The SCT presents each statement with syntax highlighting to help reading table structures.

    Our code inputs use Codemirror 6 under the hood, with a custom theme to add a little color to the text. Codemirror 6 hit a sweet spot with performance, bundle size, plugin support, with a lot of active support some great developers. Replit did a fairly large migration over the last 2 years and did an awesome deep dive into the benefits it brings. With this, it’ll be a lot easier to add things like VIM keybindings and helpful cursor interactions down the line!

    Codemirror also has great autocomplete support. When you open the shell, we make a query to pull your table schemas and column names to make writing queries a bit quicker. Just navigate the options and click enter to speed up the typing.

    2-autocomplete-in-sql-shell-browser

    Any other neat stuff?Copy Icon

    The Browser SQL shell has some handy features to help database operations that build on the normal terminal experience. After trying a few variations we felt pretty inspired by Jupyter notebooks and terminals like Warp, which provide persistent queries that can be run in a long running view.

    3-local-sorting-cockroachdb-sql-in-browser

    While working across your DB, you can copy the query to share, navigate the history, export to CSVs, and view column types. Query results are rendered in tables to improve readability, and enables local sorting for quickly scanning through your data. Error formats will also reflect what you’d see with our terminal experience to reduce context switching between the two. Feel free to also use ?? syntax for hints when writing your queries.

    4-hints
    4.5-cockroachdb-sql-terminal-hints
    5-cockroachdb-sql-terminal-in-browser

    We’ll be iterating on the shell a fair bit over the next few months. If you have anything you’d like to see, feel free to share it with the feedback button on the page!

    FAQCopy Icon

    • What access level do I need?

      • With our new roles system, Cluster Administrators have the ability to write queries from the browser. This is required since our console uses a provisioned SQL user under the hood, so

        only

        users with SQL access are permitted.

    • Why don’t I see the SQL Shell in the console?

      • The SQL Shell is available for Cluster Administrators on Serverless and Dedicated standard clusters. Please check your permissions and cluster type within your organization.

    • Where do I find it?

      • Feel free to create any cluster in CockroachDB Cloud, and you’ll see it under the “Overview” page.

    • Is the SQL Shell general availability?

      • We’ve opted to label it as Preview as we iterate on features and get feedback from customers, but it’s available for all users with the correct permissions now!

    sql
    engineering