I recently ran into a bug in my Clojurescript project which uses a Datascript database.
I am summing up a bunch of transactions associated with an account. In my query I pass in an EID of an account and return the
:plaid-transaction/amount fields of each of that account’s transactions.
It seems that depending on the order the transactions are put into the database, the first query below returns a different number of results. I performed a shuffle when inserting records into the datascript database and it impacts the results of the first query below.
The second query, which uses the
pull syntax inside of a query returns the correct result each time.
I ran both queries against the same database back-to-back and would sometimes get different results. I understand that the first query might not return the same number of records if some of the records are missing a
:plaid-transaction/amount field, but when looking at the results of the second query there weren’t any nil values (as well as looking at my input data).
(ds/q '[:find ?amount :in $ ?account-eid :where [?account-eid :plaid-account/plaid-transactions ?eid] [?eid :plaid-transaction/amount ?amount]] @conn account-eid)
(ds/q '[:find (pull ?eid [:plaid-transaction/amount]) :in $ ?account-eid :where [?account-eid :plaid-account/plaid-transactions ?eid]] @conn account-eid)
What is logically different between these two queries?