Fork me on GitHub
#datomic
<
2017-07-06
>
mss14:07:05

hey all, newbie question regarding the pull api. when resolving a ref entity in the pull api, the value returned is a map of attributes (e.g. pull [*] -> {:my-ref-attribute {:db/id 12345} ...}, pull [* {:my-ref-attribute [*]}] -> {:my-ref-attribute {:db/id 12345 :db/ident :my-ns/my-ident} ...}). when resolving a ref entity in the query api, the actual ident is returned. (e.g. find ?eid ?my-ref-attribute -> [12345 :my-ns/my-ident]). is there any way to return the actual ident for a ref from a pull (as in the query api), as opposed to a map of attributes? so the return value would be {:my-ref-attribute :my-ns/my-ident}. this thread – https://groups.google.com/forum/#!topic/datomic/xxoYiko2muY – on the datomic user mailing list gets at what I’m trying to do. just wanted to check if that’s still something unsupported by the api thanks for any input or advice!

jjttjj15:07:11

do people usually default to include project names in their :db/ident keywords? for example, do you use :myapp.user/first-name or just :user/first-name

favila15:07:08

@mss The query api does not automatically change ids to idents. I am not sure how you got that impression

favila15:07:37

@mss The only api that has the behavior you describe is the entity api.

mss15:07:54

you’re right, my mistake. meant to say that there’s an easy syntax for specifying how to return an ident

mss15:07:03

and what shape to return it in

mss15:07:11

pull can return an ident easily, but it’s always in a map of attrs

favila15:07:51

in a query you need to explicitly follow :db/ident to the ident

favila15:07:12

the only api that implicitly treats entities-with-idents as keywords is the entity api

favila15:07:22

in every other case, if you want an ident you need to ask for it

favila15:07:56

with pull results, a common strategy is to walk the results with clojure.walk/prewalk and replace any maps with :db/ident in them with the ident itself

favila15:07:05

then ensure you pull :db/ident in your pull pattern

favila15:07:43

pull [* {:my-ref-attribute [:db/ident]}] in your example

mss15:07:21

makes sense, really appreciate the help

kurt-o-sys18:07:52

I'm a bit confused about datomic starter and free. (I'm developing an app for a small ngo, so the pro version is certainly a no-go due to the pricing. small ngo's can't afford it). I do understand the Client not available on the free version and limited to 2 peers etc. But, it's about the updates: the free version can be updated at any time (meaning: install a new version and start using it), while using the starter version, this is not possible? Am I right?

spieden19:07:13

i believe starter is free upgrades for a year but then you need to pay. not sure if you get a perpetual license for the latest version at the end of that year but it seems that way

kurt-o-sys19:07:02

So, free is unlimited updates, starter only for 1 year and than you need to upgrade to pro to receive updates... Too bad.

jaret20:07:25

@kurt-o-sys @spieden starter has perpetual licensing so you can continue using versions released prior to the expiration of your starter license indefinitely.

kurt-o-sys20:07:57

@jaret Right, but no updates, meaning, after a few years, you'll probably lacking some features/security updates/ ... . Not a good idea, experience tells me.

spieden20:07:04

Yeah, thankfully for any reasonably sized money making enterprise the license cost is pretty affordable

kurt-o-sys20:07:57

right... that's it: > any reasonably sized money making enterprise the license cost is pretty affordable I'm talking about small non-profit organizations/associations, working with 1-3 FTE and a lot of volunteers (from 30 to >100). It's really not affordable for them. They are financially very small, but they are not small at all in terms of tech needs. Their 'business' is often pretty complex compared to usual businesses and they need to fall-back to poorer tech, which isn't really helping them either. (Yes, I know, the free edition, but in this use case, the client library makes much more sense.)

spieden21:07:31

@kurt-o-sys maybe talk to them and they’ll cut you a deal(?)

spieden21:07:39

cognitect that is

matan23:07:05

A late thank you for the discussion about enforcing constraints in transactions. I'm not sure what the practical conclusion might be, and my question was for the sake of understanding, not a particular use case.

matan23:07:48

I can't help but wonder though, how people make sure their data doesn't get corrupt, when constraints are expected in the data. I guess only smart and proactive testing might allow smooth sailing....

matan23:07:32

But the cost of an error would be eternally corrupt data, given the write-only nature of datomic, which is a bit more than with an RDBMS, where the cost of an error is more transient (in the non-pathological case). Just a thought.

hmaurer23:07:26

@matan Hi! There was a discussion on precisely this topic yesterday (or the day before yesterday?) on this channel

hmaurer23:07:28

The gist of it was that you cannot enforce constraints directly. If enforcing them in your application code is not enough, you can enforce them in a “transaction function” which runs on the transactor, but this relies on your application code using that transaction function (it could bypass it)

hmaurer23:07:59

Another approah could be to either inspect backups or inspect the transaction log live on the lookout for constraint violations

hmaurer23:07:11

(e.g. run a dedicated process to do this check)

matan23:07:15

Yes, I know, I skimmed the discussion

hmaurer23:07:23

Errors would then be reported back to you, and you can fix them

matan23:07:37

It just seems that's a soft spot as is

hmaurer23:07:37

Hopefully shouldn’t happen too often unless a big error was made in production code

hmaurer23:07:02

It’s not quite right that the data would get eternally corrupted though

hmaurer23:07:27

you can always excise data, commit a transaction which fixes the issue, or in extreme scenarios I guess you could even re-build your whole database

hmaurer23:07:34

if the data corruption is really too nasty

hmaurer23:07:26

We are talking disaster recovery here, not routine operation

matan23:07:27

seems to boil down to exceptionally judicious testing

hmaurer23:07:31

but for example, say you are doing daily backups

hmaurer23:07:53

and you realise that an event has occured today which has corrupted your data in a non-fixable way

hmaurer23:07:11

you could restore to yesterday’s backup, then apply every transaction that was ran before yesterday and today

hmaurer23:07:21

fltering out the transactions that caused the data corruption

hmaurer23:07:30

or something like that

matan23:07:03

any good book covering such processes? not that online docs aren't good enough...

hmaurer23:07:30

You’ll have to wait for someone else’s answer, I just started learning about Datomic

hmaurer23:07:37

But the online doc does talk about the “Log API”

hmaurer23:07:47

which could be used in conjunction with backups to do this kind of recovery

hmaurer23:07:18

Are you worried about a particular kind of data corruption?

matan23:07:17

Not really, I was just assessing the pros and cons of using datomic

hmaurer23:07:55

Do you have a kind of constraint in mind that would be enforced by a relational DB and, if not enforced, would lead to “unrecoverable” data corruption?

matan23:07:04

hmaurer: unrecoverable is subjective... so, not really

matan23:07:24

By the way, in clojure core, we do have validators built-in to the api, for the state handling constructs (atoms, agents...) I wonder why this concept was not carried over to the flagship database being datomic

val_waeselynck06:07:11

matan: well, generally speaking, Datomic's authors' line of conduct has always been to be minimalistic about adding new features in order to keep things simple, and I think it's a good strategy. Now, specifically, you can emulate validators using a transaction function as shown above - it does require a the Peer to be cooperative about it, but that's not too much of a hassle IMO

matan23:07:12

hmaurer: Thanks, will review it! hopefully it's not marketing material though

hmaurer23:07:20

@matan for you to judge. It was written by someone using Datomic in his startup, and the points are well justified imo

val_waeselynck06:07:49

@matan I wrote it, and I confirm it's not marketing material. FWIW, I've also tried to assess the limitations of Datomic in the post.

val_waeselynck06:07:27

(of course, do feel free to challenge the content, it can only help me make it better)

matan20:07:27

@U06GS6P1N thanks again for all the assistance

hmaurer23:07:01

Mmh, I would be curious to hear about that too

matan23:07:00

Well, maybe someone will chime in ..

matan23:07:14

Calling it a day