Skip to content

Access to raw sql functions using Prisma APIs. #5761

Description

@Perry-Olsson

Problem

Having to use raw sql query when I would like to make use of a native database function.

Suggested solution

In my case I'm using Postgresql and would love to be able to use the extract function to retrieve information from a timestamp.

SELECT * FROM "Appointment" WHERE extract(month from timestamp) = 2;

I've done this with Mikro-orm in a prior project and a similar implementation with Prisma could look something like this:

prisma.appointment.findMany({ where: { "extract(month from timestamp)": 2 } as any });

Alternatives

My primary frustration with having to use a raw query is that the results of the query aren't mapped as they would be with a query using the API.

So an alternative could be an option to have raw queries also map the results of the query.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions