Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for Prisma #248

Open
mattcroat opened this issue Jan 3, 2023 · 0 comments
Open

Request for Prisma #248

mattcroat opened this issue Jan 3, 2023 · 0 comments

Comments

@mattcroat
Copy link

mattcroat commented Jan 3, 2023

What Is Prisma?

Prisma is a popular Node.js and TypeScript ORM.

How It Should Work

npx svelte-add@latest prisma

Prisma Setup

Here is the setup for Prisma that uses a SQLite database which is a great starting point and easy to swap out later.

# initialize Prisma
npx prisma init --datasource-provider-sqlite

# install Prisma client
npm i @prisma/client

This creates a prisma folder with a schema.prisma and adds an .env file with the connection string pointing to the database.

The migrate command is going to create the database from the Prisma schema and run a seed script if it's configured.

npx prisma migrate dev --name init

To query the database one also needs to export the Prisma client which is a file that can be created inside lib/database.ts.

import { PrismaClient } from '@prisma/client'

const db = new PrismaClient()

export default db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants