-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Templating queries to avoid view inefficiencies #25
Comments
This is an example syntax of a view to achieve the same thing: view_customer.sql create view view_customer as
select
first_name,
last_name,
gender,
id_customer,
customer_type.name as name_customer_type
from customer
inner join customer_type
using(id_customer_type) get_male_customers.sql select * from view_customer
where
gender = "m" |
A View is the database solution to this problem of DRY/ query re-use. You wouldn't contemplate using templates like this in a php function, to avoid needing to cut & paste php code - you'd break it out into a function you can call from multiple places. Views are the db equivalent. (Views & SProcs). Now, that said... I do cut & paste sql code from one file to another, keeping a master version of each snippet in a separate file somewhere. I do it because the MySQL query cache doesn't like Views. But in the cold hard light of day I bet I'm killing code maintenance for want of a millisecond or two here and there. |
After testing the performance of concatenation/templating vs. views, the outcome is that views can be extremely slow compared to the copy-paste method or what would be introduced in this feature. Therefore my preference is to add this as a feature, but v2 (otherwise nothing will ever get completed!) This repository introduces the organisation helper of QueryCollections, which would also be a nice way of organising the template files. For example, the |
Template queries should be stored in src/query/collection/_template to match the way pages are templated. |
The functionality exposed in #124 surmounts the issues this idea faced. No solid ideas have been defined for template queries, so I am closing this issue with the intention of following on in #124. |
Allow queries to import shared SQL templates for easier and more efficient reuse than using views.
select_customer.sql
get_male_customers.sql
Your thoughts, @j4m3s?
The text was updated successfully, but these errors were encountered: