In my application, I have a lot of SQL queries that have business logic embedded in them. For example, in searches I 'hide' results that are low ranked, less than -5 'community rating' because those results contain spam, inaccuracies, etc and have been flagged by the community.
In my SQL query, it might look like:
SELECT ... ... WHERE community_rating > -5
Here, I'm embedding business logic right into the query. What if we change our minds later about the threshold for hiding results? I have 4 queries right now that use this magic number, and more might be coming.
My gut says to pull these numbers out into a 'database config file', because the numbers are reused a lot and can be changed, but I'm tempted to say no because it adds a lot of confusion as you add more
$-type variables like:
SELECT ... ... WHERE community_rating > $5
And I would have an array of values to pass to the query like:
[..., ..., ..., ..., DB_CONFIG.HIDE_RESULTS_AT_RATING]
I imagine that it would get even sloppier and hard to understand over time, but that's probably inexperience talking.
Should one pull database-level business logic out to a configuration file?
Edit: This is the backend to a web service. This isn't a parameter that a user who is doing a search can change. In all queries, results are excluded at this threshold, and the threshold is decided by me. There are multiple search functions, all of which use this threshold.