Fork me on GitHub
#datomic
<
2016-12-27
>
kwladyka11:12:34

I want add data like [{:pl “a” :en “b”}{:pl “c” :en “d”}] what choice of schema i have? Not sure how to operate on vector of maps in datomic 🙂

pesterhazy15:12:47

@kwladyka, at my company we came up with a pattern

pesterhazy15:12:13

:product/name, :product/description are in English

pesterhazy15:12:42

:product/translations is a ref and points to a "translation" entity with all the same fields

pesterhazy15:12:26

{:db/id ... : :pl, :product/name "Polish name", :product/description "Polish descr"}

pesterhazy15:12:50

that's of course assuming that there's a primary language (in our case, English)

pesterhazy15:12:12

it works for us, but I'm curious how others work with i18n in Datomic

kwladyka15:12:12

hmm i wanted make it simple on the beginning, but maybe it is not possible 🙂

pesterhazy15:12:43

I think our pattern is actually relatively simple

pesterhazy15:12:42

the problem of course is that you need a relation with a primary key consisting of product_id and language (in SQL terms)

kwladyka15:12:49

why not refer the :product/name :product/description etc. instead of :product/translation?

pesterhazy15:12:20

that would work too, but it's convenient to have the English name attache directly to the entoty

kwladyka15:12:11

i prefer to not stick to any language, because my native language and country doesn’t have english language as primary

pesterhazy15:12:08

same for me, but our company does have a primary lang

kwladyka15:12:41

anyway… is it possible to just save vector of maps in datomic in any way? Just to start from scratch?

kwladyka15:12:01

or i have to choose this pattern or another?

pesterhazy15:12:13

you can only store EAV tuples

pesterhazy15:12:52

you cannot store a vector, but you can store a set of refs

kwladyka15:12:07

but i need the right order

pesterhazy15:12:18

then you need to store a position attribute too

pesterhazy15:12:39

AFAIK, though maybe there's some other smart way

kwladyka15:12:44

so as i understand i can’t use :db.cardinality/many

kwladyka15:12:57

because i have to store ingredients etc.

kwladyka15:12:37

mmm i really don’t want make complexity by position

kwladyka15:12:42

but if i have to....

pesterhazy15:12:09

it's not that bad, but you need to do the sorting yourself (in clojure code, outside of d/q)

kwladyka15:12:11

i mean i can add this, but it will be nice to write/read in datomic in the same order without adding additional position value

kwladyka15:12:47

thx for share your solution

pesterhazy15:12:01

let me know if you discover a better way

marshall15:12:18

The other option for ordering is to store things as a ‘linked list’ (i.e. each entity has a ‘next’ ref) instead of storing an index explicitly with each individual entity

pesterhazy15:12:18

so you'd use a recursive query to get all the elements?

marshall15:12:58

yep. Since all the work of query is local to the peer and caching provides local access, you don’t have to worry about the n+1 problem the same way as you would with a traditional DB

marshall15:12:33

of course, the decision is similar to that of array vs linked list for a data structure - each is better at some things and worse for other things

marshall15:12:47

i.e. insert in the middle vs random access, etc

pesterhazy15:12:31

interesting. at first glance it sounds scary, because of the danger of circular lists

dottedmag15:12:42

If order is an "insertion order", then one does not need a separate attribute and might use transaction id for sorting.

dottedmag15:12:06

or entity id.

marshall15:12:37

@dottedmag also correct - if you don’t need to “update” it later

dottedmag15:12:56

retract and re-insert everything :)

marshall15:12:57

@pesterhazy You can always limit the recursion (i.e. with pull)

marshall15:12:24

@dottedmag true, if you’re using tx id - that also mandates that you transact each entity in a separate transaction

marshall15:12:44

since transactions themselves are atomic there’s no order within them

pesterhazy15:12:06

relying on txid works but can be limiting if you want to dump/restore portions of dbs

pesterhazy15:12:04

e.g. a development snapshot of the prod db, or just copying a few products from one, say, supplier to another

jdkealy15:12:44

is there some best practice for stringing together datomic queries... I have a situation where i'd like to provide the customer with a variable number of filters. I have tried passing some DIY syntax to the backend and reducing the client inputs into one large datomic query, and it works with some success however the code looks quite brittle and I've yet to apply any appropriate order of executing queries (biggest diffs to smallest diffs)... So I was just wondering if anyone had any recommendations basically about how to abstract a datomic query into modular filters.

jdkealy16:12:41

like the basic problem is... let's say i wanted someone to search for User entities. I provide a search by email, name, city inputs. On the backend the combinations of email,name,city could result in 8 or 9 defined query functions. ['name', 'city', 'email', 'name,city', 'city,email'] etc etc

kwladyka20:12:57

@pesterhazy can you show me shema and how you operate on this data structure? For now i have https://www.refheap.com/9347805f7fb2e7604e132f761

kwladyka20:12:39

i am learning datomic and after thinking what you said me.... i am confuse how it work

kwladyka20:12:28

i am confuse how to create schema, add data, read data for solution what you showed me

kwladyka20:12:37

it probably means i totally miss same important part of datomic 😕