3 ms·
> No more "models", ORMs / query builders, and crunching data in app code. Just build your schema, write plain sql queries, and you're off to the races. I tend
by majewsky 7y ago
> No more "models", ORMs / query builders, and crunching data in app code. Just build your schema, write plain sql queries, and you're off to the races.
I tend to do it the same way, but how do you deal with the lack of a query builder when you truly need to build a query on the fly? For example, what do you do when implementing a REST endpoint like GET /things where the user can give any number of 10 query parameters to filter the result?
- spiderxxxx 7y agoYou do "or <parameter> IS NULL". It makes the query plan uncacheable or requiring a godly cache, but it's fine for searches.
- mmckelvy 7y agoFor cases like this, I use pl/pgsql functions and dynamic queries. Dynamic queries take extra care and aren't the most pleasant things to write, but they can handle the GET /things with 10 parameters endpoints quite well.
- wilmoore 7y ago> what do you do when implementing a REST endpoint like GET /things where the user can give any number of 10 query parameters to filter the result? https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html https://www.elastic.co/guide/en/elasticsearch/reference/curr...