W
Wasp-langKumaran

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.
MEE6
MEE615d ago
Wohooo @Kumaran, you just became a Waspeteer level 1!
kapa.ai
kapa.ai15d 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
miho15d 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
martinsos8d 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
Kumaran6d 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
martinsos5d 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
Kumaran4d 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
martinsos4d 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
Kumaran4d 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
More Posts
Direct to a defined page after successful loginHello I have the standard LoginPage, as given in the ToDo App tutorial (see picture). I now would lRemove email loginIs it possible to only rely on OAuth and disable email login when using OpenSaas? When I comment outHow to use Env variables in main.wasp?I want to set the email authentication `fromField.name` to `process.env.FROM_NAME` and `fromField.can not find "wasp/server/_types" module or declarationany suggestion? this error won't effect dev, but I can't have the right type with action's params arDisable email loginIf I only want Google signup, is there a way to remove the email login? I tried commenting ``` emailDo I have a way to use useLazyQuery ?My app filters some data. I need to be able to refetch whenever the user clicks on "search" with theWhere to see migration files?I have messed up one migration (because I had to delete my local code), and now I don't know where tFile upload size limitI'm trying to implement max file upload size to the s3 bucket. I've handled the front-end but I worrAuthis there a sample bypass to login the auth while in developmentQuick Start not working?I'm following this tutorial: https://wasp-lang.dev/docs/quick-start After opening my terminal and rI cant see ubunbtu on my Linux sub system folderI just started with this programming stuff and i wanted to try my app with this new ai called magegpIs it possible to separate client and server wasp build?each time I update stuff on client, and want to push to netlify, I need to run wasp build, but it refly.io deployment errorI tried to deploy to fly.io, and I set DATABASE_URL, and I tested it can connect successfully with dfront end developers demand in job marketCan anyone please tell me about the demand of a beginner level front end developer in job market nowPassing Context for Dependency InjectionIs there a standard pattern for passing the context object for database interaction to functions? WGetting Updates to the Open SaaS Template (not working?)I am following the guide in [Getting Started](https://docs.opensaas.sh/start/getting-started/), howeCant find app and blog in my folder but it says wasp already installed.Hi everyone, ive installed Wasp but i cant find where the app and blog folder is at. It keeps says NsignupWhen defining action in main file If i dont want to use entity as i dont want to store in the db. CaStoring additional data in sessionHi everyone 😉 I'm exploring a possibility to develop my new project in WASP which looks really awesOAuth Login Error with Google Credentials in Local EnvironmentHello everyone, I need a bit of help. In my local environment, I've correctly set up the GOOGLE_CLIE