P
Prisma•4d ago
vpjm

prisma generate --sql and seeding

Hi, How can I use raw SQL to seed my database in Prisma? I would like to use the new SQL feature, but it seems to not work well with nested folders. ( prisma > sql > [version] > seed > [file].sql ) Also, I tried to read the content of SQL files, but I don't know why, when they are read, they aren't syntactically correct anymore to be called in executeRawUnsafe.
2 Replies
vpjm
vpjmOP•3d ago
Thanks for your help and your time Steps: I exported my seeding script into a .sql file and ran it with executeRawUnsafe, which caused the error: "cannot insert multiple commands into a prepared statement." Then, I tried splitting each "statement" by parsing the file with a regex, but now I am encountering the error: "control reached end of trigger procedure without RETURN." This is happening because, once read and stored in a string, the file seems to be invalid. Eventually, I manually split the statements and placed them in a folder structure under /sql, but I now realize that prisma generate --sql does not pick up files that are not in the root directory. Unfortunately, I can't find the documentation for prisma generate --sql. If you have any information/advice (on raw SQL) , feel free to ping me on the channel. Thank you very much for taking the time to read this. I wish you a happy 2025 ! 🎊 :prisma_xmas: I still haven't found the solution. :prismagrimace: The error came from the SQL file I provided: misplaced quotation marks were the cause. In general, the errors returned by Prisma do not always correspond to those you might encounter when executing the SQL code directly in a terminal, which makes debugging more difficult
RaphaelEtim
RaphaelEtim•2d ago
Hi @vpjm Thank you for providing the solution to the problem you encountered. The prisma generate --sql command is used to generate the Prisma Client to ensure the TypeScript functions and types for your SQL queries are created. From the issue, you encountered, it looks like you were using the TypedSQL feature in Prisma. You can also take a look at this documentation to learn how to properly work with this feature.
Writing Type-safe SQL with TypedSQL and Prisma Client | Prisma Docu...
Learn how to use TypedSQL to write fully type-safe SQL queries that are compatible with any SQL console and Prisma Client.

Did you find this page helpful?