Fork me on GitHub
#datomic
<
2015-07-13
>
timothypratley05:07:02

Any advice on how to structure data for an elementary school report card? There are numeric metrics Several lists and text fields… but I’m hoping to keep them flexible; So the data might be:

[{:db/id 3
     :components [[:metrics "Metrics" ["Productivity"
                                       "Leadership"
                                       "Happiness"]]
                  [:ol "Achievements" ["Won the spelling bee."]]
                  [:ol "Weaknesses"]
                  [:ol "Coach goals"]
                  [:ol "Player goals"]
                  [:textarea "Coach comments"]
                  [:textarea "Player comments"]]}])
Bearing in mind that the categories might change. I’m thinking I should be using :metric/happiness :comments/coach instead of nested data… but it feels like then I have some path info tied up in my keywords

timothypratley05:07:00

Alternatively maybe I should be making a new entity for ‘metrics’ and ‘achievements’ etc

bhagany05:07:45

If I'm reading your intentions here correctly, I think there's a mismatch between what you're attempting in the code snippet, and what datomic does -

bhagany05:07:03

in particular, datomic doesn't natively support vectors or lists

bhagany05:07:11

is the entity in your code snippet a student?

bhagany05:07:14

okay, when you say "the categories might change", what part of the snippet are you referring to?

timothypratley05:07:39

new/different metrics for example “Math"

timothypratley05:07:49

and new categories

timothypratley05:07:10

like a list of friends or something I haven’t thought of

bhagany05:07:43

still not sure what a category is… is "Achievements" a category?

timothypratley05:07:12

yes, though I don’t have any special meaning to ‘category’ simple_smile

bhagany05:07:41

heh, alright. well, at a first blush, here's how I'd do it -

bhagany05:07:08

a student entity would have these (optional) attributes: :metrics, :achievements, :weaknesses, :goals, and :comments

bhagany05:07:15

:metrics, :achievements, and :weaknesses look like they can just be db.type/string with :db.cardinality/many

timothypratley05:07:20

is there a way to preserve order in a many relationship? or would I need to make them entities that relate to each other to do that?

bhagany05:07:10

ordering isn't really straightforward - the easiest way to do it, imo, is to give the things you want to order an :order attribute and sort in your client code

bhagany05:07:37

so if you need to order those first three, you'd need to make them entities, rather than just strings

bhagany05:07:49

:goals and :comments would be entities in their own right, because you need to note authors

bhagany05:07:13

they'd just have an attribute for the goal or comment, and then another attribute to note the author - either an enum-like thing if you just want it to be :coach or :player, or you could represent people as their own entities and refer to them from there

timothypratley05:07:26

thanks that makes a lot of sense

bhagany05:07:36

okay, good simple_smile

timothypratley05:07:51

is there a shorthand way to insert my root with it’s various sub-entities, or should I write a transformation from my datastructure that produces all the entities and throw them at transact?

bhagany05:07:30

you can nest your entities when you transact them… let me get you a link

bhagany05:07:21

Can't link you directly to the content, but search for "nested" here: http://docs.datomic.com/transactions.html

bhagany05:07:00

also, note that even though the syntax for nesting uses vectors, the entities don't end up being ordered in datomic

timothypratley05:07:12

thank you very much simple_smile

bhagany05:07:08

sure, have fun! simple_smile

stijn09:07:15

@bhagany: cool, I didn’t know about that. every once in a while you need to re-read the datomic docs for added features simple_smile

bhagany13:07:16

@stijn: heck yeah, I learn new things every time

wilkerlucio19:07:45

hi nice people simple_smile one question: if I do a transaction using upsert, but nothing is changing (let's say I'm transacting data with the same value that is already on the DB), this will create a new transaction anyway or it's going to skip since nothing was going to change?

arohner19:07:40

@wilkerlucio: that will create a new transaction

wilkerlucio20:07:44

thanks @arohner, so I think I'm better do a query to check if the data is the same to avoid unintended history I think

arohner20:07:16

@wilkerlucio: depends on what you’re trying to do. Re-asserting a fact can be a valid strategy as well. “on today’s date, I observed X to still be true"

wilkerlucio20:07:41

@arohner: my case is just a simple facebook login, I'm actually login at the client-side, I just send the access token and then I create/read the user ID, is on that point that I was going to always transact (in case it didn't generate a new one), but since it does I'll just check if the user is there and avoid when it is. makes sense?

arohner21:07:06

I’d like to debug a query that is slow in production. Is there a way to clear the peer cache, without restarting?

tcrayford21:07:04

arohner: not that I know of. I'd bet you can, but it'll involve reflection and poking around in the internals of a db (which may violate a thing you signed when you downloaded datomic)