This template helps you get started with Prisma Postgres on IDX.
Follow these instructions once this project was opened in IDX.
First, you need to create your Prisma Postgres instance:
- Log in to Prisma Data Platform.
- In a workspace of your choice, click the New project button.
- Type a name for your project in the Name field, e.g. hello-ppg.
- In the Prisma Postgres section, click the Get started button.
- In the Region dropdown, select the region that's closest to your current location, e.g. US East (N. Virginia).
- Click the Create project button.
Once the database is ready, copy the DATABASE_URL environment variable and set it in .idx/dev.nix.
Now, click the Rebuild Environment button for the environment variables to take effect.
Next, you need to create the tables in your database. You can do this by creating and executing a schema migration with the following command of the Prisma CLI:
npx prisma migrate dev --name init
This will map the User and Post models that are defined in your Prisma schema to your database. You can also review the SQL migration that was executed and created the tables in the newly created prisma/migrations directory.
The src/queries.ts script contains a number of CRUD queries that will write and read data in your database. You can execute it by running the following command in your terminal:
npm run queries
Once the script has completed, you can inspect the logs in your terminal or use Prisma Studio to explore what records have been created in the database:
npx prisma studio
The src/caching.ts script contains a sample query that uses Stale-While-Revalidate (SWR) and Time-To-Live (TTL) to cache a database query using Prisma Accelerate. You can execute it as follows:
npm run caching
Take note of the time that it took to execute the query, e.g.:
The query took 2009.2467149999998ms.
Now, run the script again:
npm run caching
You'll notice that the time the query took will be a lot shorter this time, e.g.:
The query took 300.5655280000001ms.
- Check out the Prisma docs
- Share your feedback on the Prisma Discord
- Create issues and ask questions on GitHub