DEV Community

Julia for Light Cloud

Posted on Originally published at blog.light-cloud.com on

Browse and Edit Your Data Without a SQL Client: the Data Explorer

Browse and Edit Your Data Without a SQL Client: the Data Explorer

To browse and edit a PostgreSQL database on Light Cloud without a SQL client, open the database in the console and click the Data tab. It lists every table. Click a table to see its rows, click a row to edit it, and use Insert row , Columns and New to add rows, columns and tables.

This is part 2 of the database series. It uses the bookshop-db database and sample data from part 1.

What you will do

In the bookshop database, you will:

  • change the stock of one book,
  • add a new book,
  • add an isbn column to books,
  • create a reviews table and add reviews,
  • delete a row safely.

Before you start

  • The bookshop-db database with the sample data, from part 1.
  • A Light Cloud account on the Lite plan or higher.

Nothing to install: everything happens in the browser.

Step 1: Open a table

  1. In the Light Cloud console, click bookshop-db in the sidebar.
  2. Open the Data tab.
  3. Click books in the table list.

The table shows 50 rows per page. Click a column name to sort by it. Nothing you do while browsing changes the data.

Step 2: Edit a row

The Dispossessed is back in stock. Click its row. The Edit row window shows every column with its type, and whether it may be empty (not null means it may not):

  1. Change in_stock from 0 to 6.
  2. Click Save changes.

The Edit row window for The Dispossessed, with in_stock changed to 6 and the Save changes button highlighted

Only the fields you changed are saved, so you cannot overwrite a column you did not touch. The console confirms with Row updated.

Step 3: Insert a row

Click Insert row above the table and fill in a new book:

Field Value
id leave empty
title Mort
author_id 2
year 1987
price 8.99
in_stock 10

The Insert row window with id showing default, title Mort, author_id 2, year 1987, price 8.99, in_stock 10, and the Insert button highlighted

Click Insert. Empty fields get the column's default, so PostgreSQL picks the next id, 10. author_id 2 is Terry Pratchett in the authors table.

Step 4: Add a column

The shop wants to store ISBNs. Click Columns above the table, then Add column :

  1. Name it isbn.
  2. Choose the type text.
  3. Leave NULL ticked, so existing books may have no ISBN yet.
  4. Click the green tick.

The Manage columns window for books with a new column isbn of type text, NULL ticked, and the confirm tick highlighted

Changes in this window apply at once. The pencil next to a column renames it, and the bin drops it. Click Done. Every book now has an isbn column showing NULL, which means empty.

Step 5: Create a table

Readers want to leave reviews. Click New next to Tables and fill in the New table window:

  1. Table name : reviews.
  2. The first column is already there: id, type serial , PK ticked. serial numbers new rows automatically, and PK makes id the primary key.
  3. Second column: book_id, type integer , NULL not ticked.
  4. Click Add column. Third column: rating, type integer , NULL not ticked.
  5. Click Add column. Fourth column: body, type text , NULL ticked.

The New table window with table name reviews and the columns id serial PK, book_id integer, rating integer and body text with NULL ticked, and the Create table button highlighted

Click Create table. reviews appears in the table list, empty. Add two reviews with Insert row , leaving id empty each time:

  • book_id 10, rating 5, body Funny, kind and about Death.
  • book_id 1, rating 1, body test

Keep a primary key on every table you create here: the data explorer can only edit rows of tables that have one.

Step 6: Delete a row safely

The second review was a test. Tick its checkbox, then click Delete selected :

The reviews table with the test row ticked, 1 selected, and the Delete selected button highlighted

The console asks first, and says how many rows will go:

The Delete 1 row confirmation saying the selected rows will be permanently deleted and the action cannot be undone, with the Delete row button highlighted

Check the number, then click Delete row. To delete a single row, you can also open it and click Delete row... in the Edit row window.

Deleting cannot be undone, and neither can dropping a column or a table. Before a big cleanup, download a backup from the Backup tab; part 4 shows how.

Check the result

Open books again and click id to sort. The Dispossessed has 6 in stock, Mort is book 10, and every book has an empty isbn:

The books table sorted by id, showing 10 rows including Mort, and the new isbn column with NULL in every row

The same changes are visible to anything that connects to the database, such as psql or your app.

Troubleshooting

Clicking a row does nothing

The table has no primary key, so the explorer cannot tell rows apart; the header above the rows says read-only - no primary key. Add a primary key with SQL, or edit such tables with SQL.

Could not save the row

The window shows the database's reason. The most common: a not null field left empty, or text in a number field.

Could not add the column

Adding a column that may not be empty fails on a table that already has rows, because the existing rows would have no value. Leave NULL ticked, fill in the values, and tighten the rule later with SQL.

Top comments (0)