How to implement in Datomic relationships sorted by many?

Datomic lacks an out-of-box function for sorting child objects in many ways, but this is a very common requirement. Googling revealed several solutions, so I wanted to describe the requirements and solutions here and rely on community comments.

Possible requirements

  • R1: small numbers (N) of child objects (not sure what the small / large threshold should be)
  • R2: a large number of children
  • R3: single parent children
  • R4: children with multiple parents
  • R5: recursive children, i.e. trees stored in datomic

My specific use case is R1 + R3 + R5, which I suspect is fairly common, but I wanted to list as many as possible so that this could be a useful reference for others in the future.

Solutions

Problems

Each solution has problems. Can I think:

  • P1: , . "",
  • P2:
  • P3: , .
  • P4: "position" " " , .
  • P5: / ( ) -

, P2 P1 , N

, , S2. , - , , .

: - , ? R, S P , . ( ) .

A , .

+4
2

( ), Datomic Linked List -, , fork/fix/deploy .

, .

. , 1 , . , , .

, .

0

( ).

one-to-many many-to-many parent-child:

  • one-to-many , , :db/id, :my.domain/guid, :ordinal/ref .
  • many-to-many , .

, latest change date/ , . , , .

, recursive pull patterns and queries. attribute on child - . separate entity, :

{:foo/bars [{:db/id 4}
            {:db/id 2}]
 :foo/bars-order [{:db/id 9 :ordinal/idx 0 :ordinal/ref {:db/id 2}}
                  {:db/id 8 :ordinal/idx 1 :ordinal/ref {:db/id 4}}]} 

: , .

, linked list vs. position values . , positional values tx-data (, 0 10 10 -, 10 ).

, - - - (parent-wrapper-child), .

:
single-parent + recursive queries= idx next .

0

Source: https://habr.com/ru/post/1679700/


All Articles