This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Hello! How do I get a max value and its entity id using the same query?
(d/q '[:find [(max ?a) ...]
:where [?e :a ?a]]
[[1 :a 10]
[2 :a 20]
[3 :a 30]])
=> [30]
Returns 30. ok.
(d/q '[:find [(max ?a) ?e]
:where [?e :a ?a]]
[[1 :a 10]
[2 :a 20]
[3 :a 30]])
=> [10 1]
Returns [10 1]. How do I write a query that returns [30 3]?anytime you include a non-aggregate lvar in :find
, it's going to group the aggregates by that lvar
heh, I should have tagged you - @lboliveira ^^
@bhagany: Ty. So the idiomatic way to query the id is making two queries?
@lboliveira: in this case, I would say yes. In general, you don't need to worry about round tripping to the database with datomic like you do with other db's
I'm pretty positive that ?e
is already going to be in local memory because of the first query
@bhagany: I am wondering if I could have some issues if a new value is inserted between these calls.
@lboliveira: ah, this is another thing you don't need to worry about with datomic
if you pass the same db
value in to d/q
, that is guaranteed not to happen; it's immutable
you are soo right. It takes time to wrap the mind about it. 😃
thank you soo much.
@lboliveira: my pleasure it took me a bit to wrap my head around it too.
and the "don't worry about round trips".
it make all queries diferent
It is very cool way to interact with the database.
yes, very! there's a great talk by Rich where he goes into detail about the benefits of the datomic operational model, and this one really struck me. It's just so nice not to have to grab all the data you might need up front
https://github.com/Yuppiechef/datomic-schema
This is to arbitrarily support extra generating options, including the new index-all? option, which flags every attribute in the schema for indexing (in line with Stuart Halloway's recommendation that you simply turn indexing on for every attribute by default).
@bhagany: Do you have any thoughts about it?@lboliveira: I haven't used it, but I have seen people refer positively to it here and on IRC.
And about index all?
personally, I don't have a problem with the raw schema, and I kind of like having it there as data.
Yes. Do you do that?
oh, I missed your first message somehow. Yes, I do that, based on the same recommendation from Stu.
This is a "wow" thing to me.
I could not find the Halloway's recommendation. Do you have a link? I have some boolean attributes. It seems odd to index them.
{:db/error :db.error/incompatible-schema-install, :entity :ping.reply/start, :attribute :db/index, :was false, :requested true}
:ping.reply/start is a :db.type/instantI was trying to add an index to it
@lboliveira: hmm, I would guess you can't change the :db/index
setting of an installed attribute?
this rings a bell, I bet it's partially why they started recommending that you index all attrs. It isn't too expensive, and much easier than adding it after the fact.
@bhagany: This post says I can set :db/index to true : https://groups.google.com/forum/#!msg/datomic/UHGf2beACog/GKHqoSig0noJ
\o/
#object[datomic.promise$settable_future$reify__6754 0x7227ddab {:status :ready, :val {:db-before datomic.db.Db@887b21a0, :db-after datomic.db.Db@d16e8b12, :tx-data [#datom[13194139669062 50 #inst "2015-08-02T04:12:53.505-00:00" 13194139669062 true] #datom[80 44 true 13194139669062 true] #datom[80 44 false 13194139669062 false] #datom[0 19 80 13194139669062 true]], :tempids {}}}]
@bhagany: Thank you again. 😃@bhagany and @lboliveira one thing to note re: turning index on, is that this recommendation is meant for data models which stick pretty fairly close to Datomic’s modeling recommendations. We’ve found (since making the recommendation) that it collides with some common antipatterns in Datomic - e.g. storing large blobs/documents in string attributes.
@bkamphaus: thanks! good thing I'm not doing that
Cool. I don’t think most are doing that, but definitely a few have run into perf issues, index failures, etc. introduced by the combo of :avet + 10MB document-like string values.