docs

Database

We use Prisma ORM to handle the database. You can create new models from the schema.prisma file located in the app/database/schema.prisma directory. You can also export the models, for easier use, from app/database/index.ts.

In the .env file, the DB_URL variable changes according to the bank you choose, being:

Raw Queries

If you need to execute raw queries, you can use the Database handler located in app/database/database.ts. This handler provides an abstraction over Prisma’s native functions, making it easier to work with database operations.

For example, instead of doing:

const [posts, totalPosts] = await prisma.$transaction([
  prisma.post.findMany({ where: { title: { contains: "prisma" } } }),
  prisma.post.count(),
]);

You can use the Database handler like this:

const [posts, totalPosts] = await Database.transaction([
  Post.findMany({ where: { title: { contains: "prisma" } } }),
  Post.count(),
]);

This abstraction allows you to interact with your models in a more streamlined way, making your code cleaner and easier to maintain.

The Database handler provides the following methods for interacting with the database:

Each of these methods is bound to Prisma’s corresponding functions, allowing for consistent use across your application.

Summary