I'm creating a Python web application using sqlalchemy to talk with mysql database. To date I've mostly used sqlalchemy's ORM layer to talk with the database. The finest help to me of ORM continues to be the rate of development, not needing to write each one of these sql queries after which map these to models.
Lately, however, I have been needed to alter my design to talk with the database through saved methods. Does anyone determine if there's in whatever way to make use of sqlalchemy ORM layer to utilize my models with the saved methods? Can there be another Python library which may let me do that?
Generate an income view it I ought to have the ability to write my very own choose, place, update and remove claims, attach these to the model and allow the library perform the relaxation. I have been through sqlalchemy's documentation multiple occasions but can't appear to find away out to get this done.
Any assist with this is great!
SQLAlchemy does not have great way to transform card inserts, updates and removes to saved procedure calls. It most likely would not be very difficult to include the capacity to possess rather_place,remove extensions on mappers, but nobody has bothered yet. I consider the necessity to have simple DML claims undergo saved methods rather silly. It truly does not offer something that you could not use triggers.
If you cannot steer clear of the silliness, you will find some methods which you can use SQLAlchemy to accompany it. You'll lose a few of the ORM functionality though. You are able to build ORM objects from saved procedure results using query(Obj).from_statement(text("...")), simply have the column labels within the statement match the column names that you simply told SQLAlchemy to map.
One option to handle DML claims would be to turn autoflush off and rather than eliminating feel the periods .new, .dirty and .erased characteristics to determine what's transformed, problem corresponding claims as saved procedure calls and expunge the objects before carrying out.
Or just forgo SQLAlchemy condition monitoring and problem the saved procedure calls directly.