Database that stores sum types?

Is there any database that stores sum types in a convenient / non-convoluted manner ?

When serializing Rust to mysql/postgres, product types work fine, but sumtypes / enum are always a pain. Is there any db out there that does this right ?

I don't know of any. One of the main goals of my PhD research is to come up with a database abstraction layer that can handle sum types out of the box. This, and the treatment of recursive types is what is severely lacking in most databases and ORMs. (rCTEs are a thing in SQL, but I've never actually seen an ORM that could actually generate rCTEs from a recursive data model.)


I use document databases like Mongo and Elastic a lot. If your type is serializable, it can be stored in a document.

  1. Are you using serde to dump Rust enums/structs into json ? If not, how are you storing it in Mongo / Elastic ?

  2. Since we can't use SQL, what is the query language like ?

Yes. Technically its Bson in Mongo, but your observation of the workflow for storing data is correct.

In both cases, queries are just documents. So if you want to query your data you have to write funny looking documents. I don't know the complexity of your queries, but for my humble CRUD use-cases, it was never a problem. I find Mongo's query capabilities straight forward and sufficient most of the time. Elastic's querying capabilities are much stronger (it's designed as a full-text search engine, after all), but also a lot more complex and strange IMO. There is even support for SQL, but I never used it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.