datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
pedrorgirardi 2018-05-15T01:35:37.000294Z

Hi @tonsky, I saw that re-posh’s TODO example attaches a :app/type attribute to the entity. I had the same doubt as @eslachance, so I was wondering if that is a good way to have some kind of distinction of the kind (table) of the entity.

eslachance 2018-05-15T01:36:46.000082Z

Actually what I think I'd like is... some examples of this. tbh I'm not sure it will work for me, I can accept that datascript might not be the right store for me.

pedrorgirardi 2018-05-15T01:37:57.000199Z

Did you see this https://github.com/denistakeda/re-posh/blob/master/examples/todomvc/src/cljs/todomvc/db.cljs ? It might help.

eslachance 2018-05-15T01:39:38.000021Z

Hmm. I'll have to study that a bit!

2018-05-15T21:29:15.000512Z

Give it a little time. This paradigm may feel a little odd at first coming from SQL, but it's actually much simpler and more flexible. It's actually a benefit that you only have to specify the attrs and can mix and match things, because it means you can get polymorphism for free, something that can get messy in SQL. And ultimately, it's less work for you to do up front. At the end of the day though, if you want your data to conform to some notion of tables or entity types, this is generally pretty easy to accomplish, and you get to be pretty thoughtful and in more control of how you do that.

pedrorgirardi 2018-05-15T01:42:27.000100Z

You will see that is quite simple and what Tonsky said about everything being an entity hopefully will make sense 🙂

2018-05-15T07:02:30.000332Z

yes, you can maintain :app/type attr for every entity to be sure which is which. In practice, though, I found that it’s rarely needed

pedrorgirardi 2018-05-15T10:56:38.000255Z

Cool, thank you. If I don’t use the :app/type attr, but I want to query all artists, how could I do that? In DataScript/Datomic we define ‘meaning’ to attrs, is that right? So we can share attrs among entities and it means that some other entity could use the :artist/name attr. If I query for entities with that attribute I will get other entities that are not of the ‘artist type’, right?

pedrorgirardi 2018-05-15T10:58:32.000315Z

Is it right to think that for that to work I would have to attach an :app/type attr to artist so I can guarantee that I only get entities of that ‘type’?

2018-05-15T11:10:10.000471Z

kind of

2018-05-15T11:10:47.000450Z

usually there’s an attribute that’s unique to the entity though. Like :artist/id or smth. You can mix attrs between entities but it’s more like an exception than a commonplace practice

pedrorgirardi 2018-05-15T11:19:09.000383Z

Right, I see. Thank you very much, Tonsky!

1
2018-05-15T21:29:15.000512Z

Give it a little time. This paradigm may feel a little odd at first coming from SQL, but it's actually much simpler and more flexible. It's actually a benefit that you only have to specify the attrs and can mix and match things, because it means you can get polymorphism for free, something that can get messy in SQL. And ultimately, it's less work for you to do up front. At the end of the day though, if you want your data to conform to some notion of tables or entity types, this is generally pretty easy to accomplish, and you get to be pretty thoughtful and in more control of how you do that.