4 ms·
I generate Typescript types directly from a Postgres database. That works great with Knex and a bit of custom code I've written on top.
by kristiandupont 5y ago
I generate Typescript types directly from a Postgres database. That works great with Knex and a bit of custom code I've written on top.
- madeofpalk 5y agoHow do you know you're saving and retrieving data that correctly matches your typescript definition? Or are you just saying "trust me"?
- kristiandupont 5y agoKnex has some built-in support for it, but I've made a wrapper that does it quite well. So I can write db.select('member', { displayName: 'John' }) -- and because I specify the table name in the first parameter, I get type checking on the second.
- hebrox 5y agoThis has been an issue for me as well. I created https://github.com/wwwouter/typed-knex https://github.com/wwwouter/typed-knex to mitigate this. At first I had to do a lot of weird things, but with the evolution of TypeScript, it is getting more and more like 'normal' Knex.js. The end goal is to be nothing more than a very small wrapper, if any.