datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
2019-03-10T12:10:15.005300Z

I was trying out Datascript on a personal project, and I ended up with an initial schema like

(def schema {:player/name {:db/index true}
             :game/t1 {:db/index true}
             :game/t2 {:db/index true}
             :game/p1 {:db/valueType :db.type/ref}
             :game/p2 {:db/valueType :db.type/ref}
             :game/p1-points {}
             :game/p2-points {}
             :game/time {}})

2019-03-10T12:12:27.007200Z

I'm quite surprised that the ref types don't actually reference anything explicitly in Datascript

2019-03-10T12:12:56.007900Z

but just says it's a ref, I guess that's normal, but it means you can't easily generate a graph of all the schema and the various relationships?

pithyless 2019-03-11T13:44:25.008500Z

What would the ref types reference, exactly? In DataScript the reference can point to any other entity in the DB. You could generate a graph of various relationships once you populate it with data (e.g. “show me all the ‘kinds’ of entities that are referenced by :game/p1“, but how you define ‘kinds’ is specific to your domain).

isak 2019-03-11T17:02:05.008700Z

You can just add your own metadata to the schema.

2019-03-11T18:53:20.008900Z

Yeah I mean it's weird that you only what something references to when you populate with data

2019-03-14T05:29:45.015500Z

Datascript / Datomic are inherently polymorphic, which can feel a bit weird if you're used to thinking about SQL relations between tables. But if you've ever had to do polymorphism in SQL (LSS: it sucks), the relative freedom in DS is marvelous. You can still add entities to the db if you like that represent each of your reference types (in DS I mean; In Datomic, you create schema by creating entities already), and add entity types for different kinds of entities. But this is sort of a build it yourself endeavor. Which is also kind of freeing in a way, because you can do it just the way you want it, instead of being boxed into the specifics of a SQL/table relational model.

1
2019-03-14T09:04:50.015700Z

Yeah I got it now and it's quite cool