planetscale/database-js

Prisma-like JSON Query Constructor

steven-tey opened this issue ยท 3 comments

Any plans to make a Prisma-like JSON query constructor? The idea is to make conditional queries easier, for example:

import { NextApiRequest, NextApiResponse } from "next";
import { pscale } from @planetscale/database

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
    const { param1, param2, param3 } = req.query as {
      param1?: string;
      param2?: string;
      param3?: string;
    };
    const response = await pscale.table.findMany({
        where: {
            ...(param1 && {
                  attr1: param1
             }),
            ...(param2 && {
                  attr2: param2
             }),
            ...(param3 && {
                  attr3: param3
             }),
        }
    })
    res.status(200).json(response);
}

Ideally this would become a connector for Prisma

This would be really useful. We're looking at how to integrate with higher-level query packages, like Prisma, where this package would execute queries after the SQL has been composed.