Having multiple generator in schema.prisma

Hello, Currently if I add my entities in main.wasp then the generated schema.prisma has generator in it which has js as provider. I am working on a project which has both wasp and python in it. And I would like to access db from both wasp code and python code. My plan is to define all the entities/tables needed by both python and wasp in the main.wasp file. Wasp will take care of generating client for node. If you can provide a way to add following generator somehow to generated schema.prisma
generator pyclient {
provider = "prisma-client-py"
}
generator pyclient {
provider = "prisma-client-py"
}
then I can create client for python using following simple command:
prisma generate --schema=./app/.wasp/out/db/schema.prisma --generator="prisma-client-py"
prisma generate --schema=./app/.wasp/out/db/schema.prisma --generator="prisma-client-py"
I am not sure whether this feature exists already and I couldn't find it in docs. If yes, please point me to the docs else please help me in figuring this out. Thanks in advance.
9 Replies
MEE6
MEE67mo ago
Wohooo @Kumaran, you just became a Waspeteer level 1!
kapa.ai
kapa.ai7mo ago
Hi @Kumaran. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The current documentation and knowledge sources do not provide a direct way to add multiple generators in the schema.prisma file generated by Wasp. However, there is an open discussion on Wasp's GitHub about the possibility of extending Wasp's generator functionality, which might include the ability to add custom generators in the future. You can follow the discussion here (https://github.com/wasp-lang/wasp/issues/227). For now, you might want to consider running your Python code as a separate server and interacting with it via HTTP requests from your Wasp server code, as suggested in this Discord thread (https://discord.com/channels/686873244791210014/1204014940512452639). I recommend reaching out to the Wasp community directly for more specific guidance on this issue. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kumaran, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho7mo ago
We are planning to move entities out of the Wasp file and into a separate Prisma file. That's our long term plan and I can't really say when will it happen, since we are just starting to plan the how: https://github.com/wasp-lang/wasp/issues/2002 In the meantime, I'd maybe suggest a following approach. 1. Keep the entities in the Wasp file 2. Before running your command, patch the schema.prisma file by replacing lines with awk or similar 3. Use the command you wanted prisma generate --schema=./app/.wasp/out/db/schema.prisma --generator="prisma-client-py" ChatGPT says this is how you can append the extra lines at line 9:
awk 'NR==9{print $0 "\ngenerator pyclient {\n provider = \"prisma-client-py\"\n}\n"; next}1' schema.prisma > temp.prisma && mv temp.prisma schema.prisma
awk 'NR==9{print $0 "\ngenerator pyclient {\n provider = \"prisma-client-py\"\n}\n"; next}1' schema.prisma > temp.prisma && mv temp.prisma schema.prisma
This way, you build on top of Wasp, but in a very precise way and it should be stable.
GitHub
Create a Prisma file RFC · Issue #2002 · wasp-lang/wasp
We are looking to move entities out of the Wasp file and into a dedicated Prisma file. Benefits of doing this are: tooling support, better Prisma feature support (enums, generators, datasources etc...
martinsos
martinsos7mo ago
@Kumaran , I am curious, how are you using Js and Python together in Wasp at the moment? We are investigating adding actual support for Python in the future, so any information would be helpful! Here are some of our thoughts on it so far: https://github.com/wasp-lang/wasp/issues/1940
GitHub
Add support for Python backend · Issue #1940 · wasp-lang/wasp
We had multiple people ask if they could use Python backend in Wasp. Mostly Flask was assumed, as a backend server. React as frontend is ok, even great. I will list here some ideas on how Python co...
Kumaran
KumaranOP7mo ago
Hello @martinsos, Currently my implementation is same as the first way mentioned under Using Python right now in the above issue. In the wasp repo itself, in a separate directory, I keep all my FastAPI code and I also have a pyproject.toml to manage library version, dependencies, tool configs, etc. I have a separate Dockerfile for FastAPI deployment. I thought of adding FastAPI code in the wasp docker image itself by manipulating wasp generated Dockerfile but decided against it as this could quickly get out of control. I define all my tables required by both node and python as entities in the main.wasp file itself. To generate prisma client for python, I use an approach which is similar to what @miho mentioned above. I call the FastAPI routes from node code. One can host the FastAPI docker either in same machine as node or in a separate machine as per their need. This is the approach which is currently working for me.
martinsos
martinsos7mo ago
Awesome, thanks for letting me know! This will help us in designing better Python support in the future. Except for this issue with Prisma, anything else you tihnk could help quite a bit in what you are doing? If we were to somehow support Python better in Wasp, what would you like to see?
Kumaran
KumaranOP7mo ago
If you are going to support python, then please try to provide an option to include and start python webserver in wasp dockerfile itself. Easiest way is to generate a separate dockerfile for python stuff. But once that is accomplised maybe try to do including python in wasp dockerfile. Thanks for providing support and listening to my opinions
martinsos
martinsos7mo ago
@Kumaran in the sense that Python server would start alongside Nodejs server? It could be a separate Dockerfile, or it could even be the same, right, that makes sense!
Kumaran
KumaranOP7mo ago
Yes, easiest solution for v0/v1 would be is to start python webserver in a separate Dockerfile. You can even enhance it by putting both node and python in same network. Then the next upgrade could be trying to start both in same.
Want results from more Discord servers?
Add your server