Database
Get started | Expo Starter
Overview
Expo Starter uses Drizzle ORM for managing database schemas.
Why choose Drizzle ORM? Unlike other ORMs that abstract SQL and require learning both SQL and their API, Drizzle embraces SQL directly. This means you can use your existing SQL knowledge with minimal learning curve and fully leverage SQL’s capabilities. Drizzle is also dialect-specific, slim and serverless-ready.
Expo Starter v1 only supports PostgreSQL database, but we are working on adding support for other databases. Reach out to us if you need early access for other databases.
Database structure
The project includes a straightforward database schema to help you get started. It features the following tables:
Update schema workflow
When making changes to your database schema, such as adding a new table or modifying a column, you must update the schema in your codebase and then apply those changes to your database. Below is a step-by-step guide on how to do this, along with examples.
Example Schema Update
Let’s say you want to add a new column bio
to an existing users table.
- Update the Schema in Code: Modify your Drizzle ORM schema definition in your project:
- Generate a Migration Script: To apply this schema change to your database, you need to create a migration script.
This will create a script in your migrations directory (e.g., packages/db/migrations/0000_abnormal_wolverine.sql
):
- Run the Migration Script: To apply the migration to your database, run the following script:
Here's an enhanced version of the documentation with added details and examples:
Using the updated schema
Reading the User Bio
Here’s how you might fetch and display a user's bio:
Updating the User Bio
To update a user's bio, you would do something like this:
Drizzle Studio
Expo Starter Kit comes with bundled Drizzle Studio database browser and lets you launch it locally with one command :
Open browser and navigate to https://local.drizzle.studio/ to access the Drizzle Studio.
For more details how to use Drizzle ORM, refer to the official documentation.