tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.5k stars 309 forks source link

:db/valueType :db.type/tuple support in schema? #407

Closed joodie closed 3 years ago

joodie commented 3 years ago

I'm working on some code that uses composite tuples. Looking at the datomic documentation, I was trying to define such a tuple as

{:db/valueType :db.type/tuple
  :db/tupleAttrs [:my/att1 :my/att2]
  :db/unique :db.unique/identity}

But that fails with

Bad attribute specification for ..., expected one of #{:db.type/ref}

Reading the datascript docs more closely it seems that I must not use db/valueType here; composite attributes are defined by having a :db/tupleAttrs attribute in their schema.

Is this difference in behavior intentional? I wouldn't mind providing a patch to allow a db.type/tuple in this specific case if that's a welcome addition.

tonsky commented 3 years ago

The idea was that DataScript does not support typing (yet), so we don’t allow type definitions. The only exception was db.type/ref because you need to know if something is a ref in some situations.

db.type/tuple seems like a reasonable and pretty isolated addition. I think we can allow it to be specified, seems like no harm in that. But not required, if we require it to be always present, that will break backwards compatibility.

I’ll happily accept a PR, thanks!