Hello. I have recently started using Django for an ERP project where one module is on book keeping (accounting ).
There are invoices which are to be linked with payment vouchers.
Now there is a view in my database combining both the tables.
In fact it is a materialised view in Postgresql.
My question is, should I even care to model this view or just use raw queries to access it?
More clearly, I want to know if I might loose out performance by creating a model for this view?
To give more details, this view will be used in queries with equality condition and aggregating amounts (received or payed ) and calculating opening, credit, debit and closing balances for generating results.
Even cash flow statements (aka opening balance for the day, total DR and cr transactions and closing for the day ) will be calculated.
Which approach will be better?
Welcome @Bookmatic !
Bottom line first:
There’s no way to answer that here.
It’s going to depend on a lot of specific factors, only some of which you’ve mentioned, and that only in general, and others you haven’t.
The only way you’re going to know, is to try it in practice and see how each measures up, across all relevent issues.
You won’t lose any performance simply by creating the model. Whether you use is later is a different issue. (Nothing prevents you from using a raw query instead of the ORM, even if you have a model for it.) You can even pick & choose when you use each.
You’ll also want to evaluate this is terms of “developer productivity”. Is everyone who is going to work on this, now and in the future, as comfortable with SQL as you are? How is this going to affect maintentance efforts?
Since each separate use is indepdentant of the others, there’s nothing preventing you from using the ORM to start, and then switching to raw SQL for those situations where you find it to be necessary.
These are things that only you are going to be able to evaluate.