3 ms·
He's correct that there's always a version of the schema in one's code — he's also correct that it's also nice to have a version of the schema in SQL, where cer
by eadmund 8y ago
He's correct that there's always a version of the schema in one's code — he's also correct that it's also nice to have a version of the schema in SQL, where certain properties can be checked & verified.
Wouldn't it be nice to have a schema DSL which enabled one to declare the schema in code, and have it checked at compile time? Sounds to me like that'd be the best of both worlds.
And client programs could just import that package as a library, so every would be on the same page …
- foobarbecue 8y agoIsn't this what, for example, Django models are? Or even js simpleschema?
- thecatspaw 8y agoBasically every ORM does it. Django models, hibernate (java) as well for just 2 examples.
- chatmasta 8y agoDjango models only work insofar as all clients are interacting with the database through django. If even one other path to the database exists, the django models become unreliable as a source of truth. With the profliferation of microservices written in different languages, it would be nice to have a cross-language, shared-service solution as simple as django models. Something like protobufs or JSON might work well, but ultimately you still need to write a messaging and persistence layer for them, so it's not as simple as just writing a few model files.
- smt88 8y agoAs far as I know, those only check at runtime (or when generating code), not at compile time.
- foobarbecue 8y agoWhat you mean by compile time, when we're talking Django and nodejs?
- smt88 8y agoYeah, that's part of my point. JS and Python can't even do what we're talking about here.
- shiveringking 8y agoOCaml can do this with the PG'OCaml[0] library 0: http://pgocaml.forge.ocamlcore.org/ http://pgocaml.forge.ocamlcore.org/
- pdimitar 8y agoAwesome link, thank you.
- gwbas1c 8y agoThat's kind-of what some ORMs try to do. Either the learning curve is too high, the ORM is too buggy, or someone screws something up and ends up writing software that's worse that just doing it the old-fashioned way. Honestly, I'd rather that the DSL just import adapters for stored procedures; or that the language itself is modified to be more SQL-like.
- wvenable 8y agoA lot of ORMs do this. In .net Entity Framework, you can define your schema entirely with classes, properties, and attributes and if your database doesn't match on startup then it will fail. As well you can do migrations to match your database schema to your current code model when it changes.