Connecting a Database
This guide explains how to store, retrieve, and manage data in your Newly app using the built-in Liquid Backend.When You Need a Database
You need a database when:- Data should persist across app restarts
- Data should sync across devices
- Users need their own personal data
- You’re building any CRUD application
Basic Data Storage
Creating a Simple Feature
Let’s build a notes app to demonstrate database concepts:When you request data persistence, Liquid Backend automatically creates the necessary database tables and API endpoints.
Understanding the Data Model
How the AI Creates Tables
The AI analyzes your request and creates an appropriate schema:Being Explicit About Schema
For complex data, be specific:CRUD Operations
Create (Adding Data)
Read (Fetching Data)
Update (Editing Data)
Delete (Removing Data)
Relationships Between Data
One-to-Many Relationships
Fetching Related Data
Querying and Filtering
Search
Sorting
Filtering
Optimistic Updates
For better UX, update the UI before the server responds:Error Handling
Viewing Your Data
Use the Database Viewer to inspect your data:- Click the Database icon in the preview header
- Select a table from the sidebar
- Browse records and their values
- Debugging data issues
- Verifying saves work correctly
- Understanding the data structure
Best Practices
Validate Before Saving
Check data is valid before sending to server
Show Loading States
Indicate when data is being fetched or saved
Handle Errors
Always handle and display errors gracefully
Use Optimistic Updates
Update UI immediately for better responsiveness
Next Steps
Add Authentication
Secure your data with user accounts
Supabase Integration
Use Supabase for advanced features