4 ms·
> Your compiler doesn’t — and can’t — know what’s in your database. At compile time, yes it can. Not inherently the compiler itself, but at compile time the pr
by asdkhadsj 7y ago
> Your compiler doesn’t — and can’t — know what’s in your database.
At compile time, yes it can. Not inherently the compiler itself, but at compile time the process can fail to build if your models do not match the schema in the DB. Diesel, for example, keeps the schema in code and (optionally) compares it to that of the DB. Ensuring that at compile to your code matches the schema of the DB.
That of course doesn't handle changes to the schema post-build, but I hope no one is ad-hoc modifying their DB :)
edit: And this becomes even more of a local, isolated solution if your ORM is also managing your migrations. Which, in the case of Diesel, it also (optionally) does.
- jmull 7y agoMaybe I should have added: it doesn't know what's in your database at runtime. It's not you'll be ad hoc modifying your DB. It's that your schema and your application-side entities will change over time (continuously, during development, and somewhere between continuously and periodically in production, depending on how you release). Generally you won't be able to guarantee that they are updated in lock-step, or you won't want to pay the price to ensure that they always are.