This example shows how to implement a simple web app using SvelteKit and Prisma ORM.
Download this example:
npx try-prisma@latest --template orm/sveltekit
Then navigate to the project directory
cd sveltekit
Alternative: Clone the entire repo
Clone this repository:
git clone git@github.com:prisma/prisma-examples.git --depth=1
Install npm dependencies:
cd prisma-examples/orm/sveltekit
npm install
This example uses a local SQLite database by default. If you want to use to Prisma Postgres, follow these instructions (otherwise, skip to the next step):
-
Set up a new Prisma Postgres instance in the Prisma Data Platform Console and copy the database connection URL.
-
Update the
datasource
block to usepostgresql
as theprovider
and paste the database connection URL as the value forurl
:datasource db { provider = "postgresql" url = "prisma+postgres://accelerate.prisma-data.net/?api_key=ey...." }
Note: In production environments, we recommend that you set your connection URL via an environment variable, e.g. using a
.env
file. -
Install the Prisma Accelerate extension:
npm install @prisma/extension-accelerate
-
Add the Accelerate extension to the
PrismaClient
instance:+ import { withAccelerate } from "@prisma/extension-accelerate" + const prisma = new PrismaClient().$extends(withAccelerate())
That's it, your project is now configured to use Prisma Postgres!
Run the following command to generate the Prisma Client. This is what you will be using to interact with your database.
npx prisma generate
npm run dev
The server is now running at http://localhost:5173
If you want to try this example with another database than SQLite, refer to the Databases section in our documentation
- Check out the Prisma docs
- Share your feedback on the Prisma Discord
- Create issues and ask questions on GitHub