4 ms·
I agree with your point that adding multiple layers = more attack vectors and abstraction of a really good domain specific language. But what seems to happen on
by yasserf 5y ago
I agree with your point that adding multiple layers = more attack vectors and abstraction of a really good domain specific language. But what seems to happen on most of the projects I work on is we end up hiding away extremely common logic behind helper functions. It always starts off with SQL and then slowly gets moved into higher level functions that offer a better developer experience.
Shameless plug, but I just posted a library I wrote (for node https://github.com/vramework/postgres-typed/blob/master/README.md https://github.com/vramework/postgres-typed/blob/master/READ...) which pretty much is a tiny layer ontop of pg-node (which is query based / with value parameters) and provides small util functions with typescript support derived straight from postgres tables.
In an ideal world (one I think we are getting very close to) I think we will end up having SQL queries validated in our code against the actual DB structure the same way we have any other compilation error. But until then we'll need to rely on tests or helper libraries, and for the purpose of refactoring and development I find the latter more enjoyable (although still far from perfect).
- mcdonje 5y ago>SQL queries validated in our code against the actual DB structure the same way we have any other compilation error Good point about validation. The ideal scenario you propose would indeed be ideal.
- x-shadowban 5y agoF# (and surely there are others) offers type providers, which can reach into your db schemas at compile time and typecheck linq-ish or even raw sql strings and the subsequent uses of the result set. But in the simplest case it makes compilation a function of not only source files but also db schema state. You can extract schema defs and point the type provider at the "cached" defs, but make sure rebuilding those is part of the build process.
- throwaway858 5y ago> In an ideal world (one I think we are getting very close to) I think we will end up having SQL queries validated in our code against the actual DB structure the same way we have any other compilation error. This library for TypeScript works exactly like this https://github.com/MedFlyt/mfsqlchecker https://github.com/MedFlyt/mfsqlchecker