Query your databases, change them safely, find missing indexes

Connect to the databases your code points at in one click, read and query them beside the code, change a row only inside a transaction you commit, and find the indexes your queries are missing.

3 min read · Video walkthrough

Before you start

  • A database the folder points at, or its address: PostgreSQL, MySQL, MariaDB, SQL Server, CockroachDB, SQLite or Redis.
  • For a database off this Mac, TLS it can verify.
  • A model only for the SQL ninja and Find missing indexes. Connecting, browsing, querying and writing need none.
The corner shop’s SQLite file: a table read at once, a lookup with 42 bound to its ?, the folder’s schema, an UPDATE refused while the connection is read-only, then run in a transaction, rolled back, run again and committed. Every statement really ran.

Connect#

  1. Open Database.

    Click Database on the bar at the right edge. It has two tabs: Connect for live databases and Schema for the tables your SQL files describe.

  2. Pick what the folder points at.

    WTFCode reads where your code says its databases are and offers each as a card: .env URLs and POSTGRES_*, PG*, MYSQL_* and DB_* variables, Compose services, Spring’s spring.datasource, SQLite files, databases running in your local Docker, and the usual ports on this Mac. Connect <name> connects in one click; a password it found stays on your Mac and is never shown to the page.

  3. Or paste an address.

    A connection URL fills the form:

    postgres://app@localhost:5432/shop
    mysql://app@db.internal:3306/shop
    jdbc:sqlserver://localhost:1433;databaseName=shop
    ./data/shop.db

    A failed test names the step that failed: the address, TLS, the sign-in, the database or the file.

Browse and query#

Tables are listed with their columns and keys, folded into families by name. Click one and its rows open at once; a table’s detail shows its columns, indexes, the keys that point in and out, and the engine’s row estimate.

  1. Write a statement.

    Table and column names complete as you type. ⌘↵ runs it. Rows arrive a page at a time, and the run is drawn as connect, run and fetch at their real widths.

  2. Bind values.

    Write ? where a value goes and fill it in under the editor, as your code would:

    SELECT id, status FROM orders WHERE id = ?   -- value: 42
  3. Read big values whole.

    A JSON value opens whole and indented; a large one says its length.

One statement runs at a time. Cancel the running SQL statement in the command palette stops it in the server.

Change data, inside a transaction#

Every connection starts read-only: a read runs in a read-only transaction, and an UPDATE, INSERT or DELETE is refused before it reaches the database, with a note saying how to allow it.

  1. Allow writes.

    Edit the connection and turn on Allow writes. Do it per connection: your local database, not production.

  2. Run the change.

    It runs in a transaction that stays open, says how many rows it changed, and waits. Other reads here use their own connection, so they don’t see the change yet.

  3. Commit or roll back.

    Commit keeps it; Roll back undoes it. A change left waiting is rolled back by itself after five minutes, and a connection holds one waiting change at a time.

Ask in plain words#

Type a question under the editor, “paid orders this week per customer”, and the SQL ninja writes the statement: it reads the tables the question names, checks its plan with the database, and puts the SQL in the editor for you to run. On a connection that allows writes you can ask for a change, which still waits for your Commit.

The ninja sees table and column names and types only. Peek at values lets it read a column’s values and a few rows, to get filters right; turn it off and no row reaches the model.

Find missing indexes#

  1. Start the review.

    On a connected database, click Find missing indexes. An agent searches your code for the queries that reach this database and checks each against the indexes it has. The toolbar shows what it’s doing and how long it has taken; Stop index review ends it.

  2. Read what it found.

    View index review lists each candidate with the line of code it came from, the query, and the index to add:

    -- src/orderLookup.ts:1
    CREATE INDEX "idx_orders_customer_id" ON "orders" ("customer_id")
  3. Measure, add, verify.

    Check the baseline plan, add the index with your own migration (Open index SQL in editor gives you the statement), then Verify index runs the same query on the same connection and shows the plan using it.

Schema from your SQL files#

The Schema tab draws the tables your migrations and SQL files declare, and the references between them, without connecting to anything. Pick a table to show it alone with what it joins, ⌘-click to pick several, or play the schema as a scene, parents first.

What stays on your Mac#

Next steps#

  • Cloud: the databases, queues and buckets in your cloud accounts.
  • Docker: the containers your local databases run in.
  • Inline chat: ask about the query in your code where it is.

Something unclear or out of date? Tell us; a person on the team reads every note.

Search every guide: features, settings, keys and troubleshooting.

Try