asami

Asami, the graph database https://github.com/threatgrid/asami
plexus 2020-08-03T11:57:31.003Z

One of the things that set Asami apart seems to be have it handles attributes with multiple values. Instead of making a distinction via the schema it allows setting array values which get represented as linked lists in the graphs. Are there any ways to manipulate these like, like add/remove a single element?

plexus 2020-08-03T11:58:18.003800Z

I also noticed that if you transact an array value, then try to transact a regular value for the same entity/attribute, it still returns the array when you query afterwards

quoll 2020-08-03T12:13:49.004600Z

When you query with asami.core/q or when you use the asami.core/entity function?

quoll 2020-08-03T12:14:32.005400Z

The entity function makes a presumption that you didn’t try to modify the data, so it’s not expecting multiple uses of an attribute

quoll 2020-08-03T12:15:17.005500Z

Yes. Asami takes the RDF approach. This is intentional

quoll 2020-08-03T12:17:15.005700Z

But it means that if your data is structured like an entity (which usually only has one value per attribute), then you either want to use transact to insert/update the data as an entity and not with datoms, or else you need to be careful

quoll 2020-08-03T12:18:39.007200Z

The entity function is just looking for one value per attribute. If you have 2, then it will just return the first one that it finds. I have a ticket to instead return a set for attributes that have multiple values

quoll 2020-08-03T12:28:32.007300Z

I’m not sure what you mean here… Did you do something like:

(transact conn [{:db/ident "mary"
                 :name "Mary"
                 :children ["Aaron", "Betty"]}])
(transact conn [{:db/ident "mary"
                 :children "Charles"}])
???

quoll 2020-08-03T12:31:30.007500Z

I’m expecting that it’s something like that, since it would lead to the behavior that you state.

quoll 2020-08-03T12:32:54.007700Z

If you wanted to append to the array, then at this point I’m expecting you to rewrite the array. i.e.:

(transact conn [{:db/ident "mary"
                 :children' ["Aaron" "Betty" "Charles"]}])

quoll 2020-08-03T12:34:18.007900Z

But… I can see that adding to that attribute would more naturally append to the array. I could do that…

plexus 2020-08-03T14:26:14.008100Z

Yeah that's exactly what I did. Just trying some stuff out to get a better feel of how Asami deals with things. In this case I actually expected it would return "charles" as a single value...

plexus 2020-08-03T14:26:58.008300Z

But don't take that as a feature request, I'm just trying to test my mental model

quoll 2020-08-03T14:53:08.008500Z

I’ll take this back to the main room…

quoll 2020-08-03T14:53:20.008800Z

From the thread above…

quoll 2020-08-03T14:54:04.009700Z

Asami features have mostly been driven by use cases. The rest of it has come about by me wanting to choose what I hoped were sensible defaults

quoll 2020-08-03T14:54:44.010300Z

Since it’s schemaless, I have not tried to duplicate Datomic exactly

quoll 2020-08-03T14:58:35.012900Z

I have been giving a bit of thought to what it means to add data that relates to an existing entity. Do I replace attributes? Do I append? How do I stay consistent with those cases where the attribute doesn’t exist? How do I minimize the work that’s done? After all, I can just remove all triples that pertain to an object, and then insert new ones. But that has performance costs in needing to query and then re-insert, and do I want to wear that overhead for every transaction?

quoll 2020-08-03T14:59:16.013500Z

This was what drove the introduction of annotated attributes

quoll 2020-08-03T15:01:28.014Z

These force a lookup and modification of the existing structure, rather than just blindly inserting