4 ms·
This is a good take. I've been offended by this aspect of NoSQL for some time now, always using something like Mongoose to add schemas on top of it, but I'm sta
by _bxg1 8y ago
This is a good take. I've been offended by this aspect of NoSQL for some time now, always using something like Mongoose to add schemas on top of it, but I'm starting to think that what I was really offended by was the lack of types inherent to plain JavaScript. It now occurs to me that a type system could be used to define the canonical form of a given DB schema.
I spent a year and a half at an enterprise Java shop, and there was a ton of work there put into maintaining and syncing the Java types and the SQL schema, even though that Java application was the only thing that would ever use that database.
I wonder what it would look like to have a schema definition system that was equally understood by the DB and the code, so you didn't have to pick one or the other or both.
- Arcsech 8y agoYou could use something like JOOQ[0], which (optionally) generates Java code based on your SQL schema. [0] https://www.jooq.org/ https://www.jooq.org/
- _bxg1 8y agoWe used hibernate, which does the opposite (Java classes/annotations -> SQL). You'd still have the same disadvantages: having an imperfect "clone" of your schema.
- Jyaif 8y agoCan you elaborate what you mean by "imperfect"?
- _bxg1 8y agoA Java string isn't precisely the same thing as a varchar(255), for example. Nor is an ArrayList (ordered) the same thing as a set of rows (unordered). Mapping between these slightly different sets of concepts usually works well enough, but it's an additional piece of disjointedness.
- threeseed 8y agoBut it's unavoidable. At some point you have to do that translation. And I would rather leave that up to the ORM where it fundamental to what they do then reimplement it.
- erik_seaberg 8y ago> that Java application was the only thing that would ever use that database It's a mistake to make this assumption unless you've taken extreme measures to lock down and audit all access. It's pretty common for the entire dev team to have read access, and someone has inevitably built some ad hoc thing taking advantage of that.
- _bxg1 8y agoPerhaps I should've said "the only piece of infrastructure that would ever use that database". DB browsing software and even ad-hoc scripts don't need a perfect schema; you can usually just grok it by visual inspection
- erik_seaberg 8y agoThat's a problem when we break something ad hoc the founder wrote to reconcile the books once per month. Data attracts surprising and important uses.
- ben509 8y agoI've been working on a kind of "universal type language" to address this problem. My goal is that it can have semantically identical data structures that function in multiple host languages, and then similarly on the DBMS. https://tenet-lang.org/ https://tenet-lang.org/