Wednesday, April 17, 2013

Django queries v/s raw database queries

It has been quite some time romancing with django, and my favourite language python together. You didn't get the picture but here you are ,amused by the dirty picture created by your mind. Well, if there would have been anyone as simple as python , I would import her into my life. Django , a web framework is like friend of python , making you see that you can do anything by her side and how easy it is to be in love with her.
Ok , now enough of my love story. I have been working as an intern developing scripts for the datafeeder layer for the website MoneyuTrade.com . It has been some time experimenting with django's orm for handling very large database. Django provides clean and simple layer over database , that can be manipulated to keep the platform and your code, independent of the database and hence ,could be shifted from your workspace to another with minimal effort required in process.
But , in a relationship there are fights , time when you realise that there is no way around her to make her understand what you want to do. When you don't want to be so simple, that she could understand how harsh life is , and that it could not be made any simpler.You want some time alone from her , and want to do things the old way.
Here, I want to shift the focus on the raw queries, that is also provided by django , for when the time comes , when orm alone cannot efficiently do work or process queries, as you could have when using raw queries , depending on the database you are using . It kills the very soul of django to use raw queries.
You would ask that why would django allow raw queries ?
Why would she let me go, realising how much she had given me?
The answer is about the flexibility that django provides, if you aim at building a product that would be running on the same database or same type of database , then there is no harm in using raw queries, even there comes situation that you cannot make way around keeping time constraint in mind , and end up using the raw queries , that you have avoided so far. But, it would make the product platform-dependent , if that's the bargain you are willing to do, then don't hesitate in your decision.
I had also found myself in this situation, that the query I was trying to make was taking too much time (around 3-4 hours and still running) , even after avoiding loops . Even at first , I was told (by my mentor) to not use the raw queries , but as time constraint plays an important role , It was used in the end. Like, I said you have to choose between two factors ,to whom to favour time constraint or database-independent.
Still,  we should try not to use raw-sql queries as far as possible.But, there are always some exceptions, and try not to ruin the beauty of  her due to these little fights, and don't forget how simple she is.

No comments:

Post a Comment