Add a database with search to an app

Ask the AI builder for a reading list with a database, full-text search and an operation that lets visitors add a book, then check what visitors can read and download the data.

Goal: an app with its own database (Studio Data), search and a form that visitors can use. Time: about thirty minutes. Plan: Studio. Before you start: you have built a first app. See Build your first app.

1. Ask for the database

Create a new note in App and send this to the AI builder:

Build a reading list app. Store books in the app's database with title, author, a short note and the date added. Seed it with five books. Add full-text search over title, author and note, and a search box that finds words in any of them. Add an operation add_book so visitors can add a book with a form. Show the list newest first.

Watch the tasks. The builder creates the tables, loads the rows, defines the operation and builds the page. A destructive change to existing data would ask for your approval first; this one only adds.

2. Try it

  1. Type a word from one of the notes in the search box. The list narrows to books that contain it.

  2. Add a book with the form. It is saved through the add_book operation and appears in the list.

Visitors cannot run any other change. If you open the code view, you can see how the page reads data:

const books = await smn.db.all('SELECT title, author FROM books ORDER BY added DESC LIMIT 50');
await smn.db.run('add_book', { title, author, note });

3. Check what visitors can read

Open the configuration (Configuration) and find App data.

App data in the configuration panel.

Switch off any table you do not want visitors to read.

4. Change your mind safely

Ask: "Add a field for the genre and show it in the list." The builder changes the database and the page. If it must drop or rewrite data, you will be asked to approve.

5. Share the data with another app (optional)

Turn on Share this app's data with my other apps. Your other apps and the AI builder can now read this app's data, read-only. See App data.

6. Download your data

Under Export, choose Download database (.sqlite) to download the database as a SQLite file. You can open it with any SQLite tool.

Result

An app with a real database, search, a safe way for visitors to add data and a copy you can keep.

Next steps

Related pages