Using the Prisma client

Learn how to use the Prisma client to interact with the database.

The Prisma client is defined in the packages/database/src/client.ts file, which can be imported in your application to interact with the database.

The client is imported as db:

import { db } from '@kit/database';

You can then use the client to interact with the database:

import { db } from '@kit/database';
// Find all users
const allUsers = await db.user.findMany();
// Create a new organization
const newOrganization = await db.organization.create({
data: {
id: crypto.randomUUID(),
name: 'New Organization',
slug: 'new-organization',
createdAt: new Date(),
},
});
// Find user by email
const user = await db.user.findUnique({
where: { email: 'user@example.com' },
});
// Update a user
await db.user.update({
where: { id: userId },
data: { name: 'Updated Name' },
});
// Delete a user
await db.user.delete({
where: { id: userId },
});

For more information on how to use the Prisma client, please refer to the Prisma documentation.


Next: Authentication Configuration →