News for hackers. Stuff that matters.
Re:Databases always have a schema (2018) by eadmund on Monday February 25, 2019 @09:46AM (#19245942)
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 …

Re:Databases always have a schema (2018) by shiveringking on Monday February 25, 2019 @09:53AM (#19245995)
OCaml can do this with the PG'OCaml[0] library

0: http://pgocaml.forge.ocamlcore.org/

Re:Databases always have a schema (2018) by pdimitar on Monday February 25, 2019 @09:55AM (#19246008)
Awesome link, thank you.
Re:Databases always have a schema (2018) by gwbas1c on Monday February 25, 2019 @09:59AM (#19246049)
That'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.

Re:Databases always have a schema (2018) by foobarbecue on Monday February 25, 2019 @09:50AM (#19245974)
Isn't this what, for example, Django models are? Or even js simpleschema?
Re:Databases always have a schema (2018) by chatmasta on Monday February 25, 2019 @09:57AM (#19246025)
Django 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.
Re:Databases always have a schema (2018) by thecatspaw on Monday February 25, 2019 @09:55AM (#19246015)
Basically every ORM does it. Django models, hibernate (java) as well for just 2 examples.
Re:Databases always have a schema (2018) by smt88 on Monday February 25, 2019 @09:57AM (#19246028)
As far as I know, those only check at runtime (or when generating code), not at compile time.
Re:Databases always have a schema (2018) by foobarbecue on Monday February 25, 2019 @11:57AM (#19247004)
What you mean by compile time, when we're talking Django and nodejs?
Re:Databases always have a schema (2018) by smt88 on Monday February 25, 2019 @04:25PM (#19249597)
Yeah, that's part of my point. JS and Python can't even do what we're talking about here.
Re:Databases always have a schema (2018) by wvenable on Monday February 25, 2019 @10:59AM (#19246520)
A 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.