Search code examples
prisma

How to implement partial search floats in Prisma?


I'm trying to implement a search query in Prisma for a float. Right now I'm using equals, but that means you have to type the exact number. I'd like to implement something like a partial string search - i.e. if I type in '36' it would bring back '360' or '23.36'

The only options I see are greater than or less than or equals - how do you handle number searches? I would be OK even if it only had 'starts with' logic, so I could get back 36 or 362 or 3612, but I can't figure out any way to accomplish this.

Is there any way to achieve this with Prisma?


Solution

  • The only way to accomplish something like this that I could see is to use String as the type within Prisma schema and within your code consume the values by parsing them into floats again / stringifying them.

    This way you could use string operators within Prisma, so for example { floatAsString: { contains: '36' } } would find 360 and 23.36

    If you keep it as floats in the Prisma schema there are no operators to achieve this in the Prisma API.