generate-schema icon indicating copy to clipboard operation
generate-schema copied to clipboard

SQL to Prisma generator

Open m-abdelwahab opened this issue 4 years ago • 2 comments

It would be very nice to have a SQL to prisma generator.

For example the following SQL QUERY

SELECT * FROM Users WHERE city = 'Copenhagen'

Should be converted to the following prisma query

await prisma.users.findMany({
  where: {
      city: "Copenhagen"
  }
})

m-abdelwahab avatar Jul 07 '21 07:07 m-abdelwahab

Did a little bit of research since I'm not particularly fluent in prisma.

  1. Model names are PascalCase
  2. Client model names are camelCase
  3. Columns are untouched

Let me know if anything above here is incorrect.


Notes:

  • Will do PostgreSQL -> Prisma Query as there is an AST parser for it.
  • Secondary library might be good for this generate-queries or pivot the idea of purely "JSON to X" and more "X to Y" where "Y" could be a "Query Schema"

nijikokun avatar Jul 07 '21 09:07 nijikokun

Everything you mentioned is correct 👍🏼

m-abdelwahab avatar Jul 12 '21 05:07 m-abdelwahab