3 ms·
One of the classic bikesheds. I've wound up writing a low key system in, at the time, Scala, that did something to the effect of: class Select { fie
by pnathan 7y ago
One of the classic bikesheds.
I've wound up writing a low key system in, at the time, Scala, that did something to the effect of:
class Select {
fields: Either[List[String], All]
table: String
wheres: List[Clauses]
orderBy: Option[String]
def render(): String
}
The render() method generated SQL; the Select class allowed a _fairly typed_ input; with some evolution, you can get shared queries quite nicely.
This works _reasonably well_. Part of _why_ I went this route is that I tend to use Postgres in a very serious way: it's not just a fancy set of spreadsheets with FK linking: I have indexes, check constraints, enums, pg-specific types, triggers, etc. So being able to directly interact with the database gives you a rich control surface that ORMs tend to exclude you from.
By the way, this was an evolution in concept from a different database oriented system I wrote in Python. Both systems used Postgres rich types, the class/render system was implemented in Scala and was Very Nice.