Use database client
Learn how to use the database client in supastarter.
In general you can use the database client in all parts of your application (that are server-side) directly, but we recommend to keep all usage of the database client in the database
package in the queries
folder and exposing specific query/mutation functions instead.
Prisma
The database client is an export of the Prisma client from the @prisma/client
package. It is automatically generated by Prisma based on the schema and is exposed as the db
object from the database
package in the monorepo.
This guide covers the basic operations of the database client, such as querying, creating, updating, and deleting records. To learn more about the Prisma client, check out the official documentation.
Querying records
To query records from the database, you can use the findMany
method on the Prisma client. This method accepts an object with optional where
, orderBy
, skip
, and take
fields to filter, order, and paginate the results.
Here is an example of querying all users from the database:
Creating records
To create a new record in the database, you can use the create
method on the Prisma client.
Updating records
To update an existing record in the database, you can use the update
method on the Prisma client.
Deleting records
To delete a record from the database, you can use the delete
method on the Prisma client.
Drizzle
The database client is an export of the Drizzle client from the drizzle-orm
package. It is automatically generated by Drizzle based on the schema and is exposed as the db
object from the database
package in the monorepo.
Querying records
To query records from the database, you can use the findMany
method on the Drizzle client. This method accepts an object with optional where
, orderBy
, skip
, and take
fields to filter, order, and paginate the results.
Here is an example of querying all users from the database:
Creating records
To create a new record in the database, you can use the insert
method on the Drizzle client.
Updating records
To update an existing record in the database, you can use the update
method on the Drizzle client.