Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma-like JSON Query Constructor #50

Closed
steven-tey opened this issue Aug 20, 2022 · 3 comments
Closed

Prisma-like JSON Query Constructor #50

steven-tey opened this issue Aug 20, 2022 · 3 comments

Comments

@steven-tey
Copy link

steven-tey commented Aug 20, 2022

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);
}
@steven-tey
Copy link
Author

@theobr might be doing this already with https://github.com/TheoBr/pscalebench/blob/main/src/pages/index.astro 👀

@CaptainYarb
Copy link

Ideally this would become a connector for Prisma

@dgraham
Copy link
Member

dgraham commented Aug 23, 2022

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.

@dgraham dgraham closed this as completed Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants