Fork me on GitHub
#xtdb
<
2021-01-28
>
refset18:01:37

Not currently, although I definitely see the merits and I added it as an idea on our backlog a while ago šŸ™‚ In the meantime I suspect the DataScript implementation could be fairly easily adapted and used for Crux in userland https://github.com/tonsky/datascript/commit/5bc0b3e6090152d6cfd2726d3d92ddc821185cf7

šŸ‘ 3
refset21:01:17

this might be of some use, if you hadn't already created your own version

(defn q2
  "Decorate a supplied `q` call with return maps
  Caveats:
   - no error handling, simply reverts to default behaviour (return tuples)
   - no enforcing of keys/syms/strs types
   - does not ensure keys are unique
   - not usable with `crux.api/open-q`
   - a built-in implementation could probably be more efficient"
  [qfn {:keys [find keys syms strs] :as query} & args]
  (let [ks (or keys syms strs)]
    (cond->> (apply qfn query args)
      (and (vector? ks)
           (= (count ks)
              (count find)))
      (map (partial zipmap ks)))))

;; e.g.
(q2 (partial crux/q (crux/db (crux-node)))
    '{:find [e v]
      :keys [:ent :val]
      :where [[e :crux.db/id v]]})
;; => [{:ent 1 :val 1}]

šŸ‘ 3
refset15:02:57

We have just added it to master so it will be in the next release šŸ™‚ https://github.com/juxt/crux/pull/1407

šŸŽ‰ 3
R.A. Porter20:01:07

Poking at this, trying to figure it out on my own, but so far Iā€™ve been unsuccessful. Iā€™m moving to Postgresql-backed datastore and txact store and Iā€™m not clear on a) whether Iā€™m supposed to include com.opentable.components/otj-pg-embedded in my deps (I think so, as it is clearly a pg driver but the docs on it are sparse and this statement of theirs confuses/concerns me: ā€œExcellent for allowing you to unit test with a ā€œrealā€ Postgres without requiring end users to install and set up a database cluster.ā€œ) b) again, as those OpenTable docs are a bit sparse, I donā€™t know what to provide for my :db-spec values. Iā€™ll be trying a few different url options but Iā€™m not clear here.

R.A. Porter20:01:01

I think Iā€™ve found it. Had to search github for db-spec in files named config.edn.

R.A. Porter20:01:27

Spoke too soon. Still not quite there.

refset20:01:53

Hey šŸ™‚ we only use otj-pg-embedded for testing - I don't know if it's feasible to use it in production without missing some critical features (e.g. backup/restore). What is your motivation behind wanting to use an embedded Postgres?

R.A. Porter20:01:03

I donā€™t want to use an embedded Postgres.

R.A. Porter20:01:18

Iā€™m just following the guideā€¦

R.A. Porter20:01:03

where it says > Each of these also require an additional dependency to pull in the relevant JDBC driver - see the Crux JDBCĀ https://github.com/juxt/crux/blob/master/crux-jdbc/project.cljĀ for our latest dependencies.

R.A. Porter20:01:34

The only postgresql-related dependency was the OpenTable library.

R.A. Porter21:01:12

I got it. Also pushed a PR to the docs. Not sure thatā€™s how it should be documented, but figured a first pass at it would be better than nothing. https://github.com/juxt/crux/pull/1403

šŸ™ 3
refset21:01:07

Ahh, I see, yes you're perfectly correct about all that (sorry it wasn't explained!), and thanks for the PR šŸ™‚

šŸ‘ 3
jarohen21:01:25

Hey @U01GXCWSRMW - thanks for the PR šŸ™‚ I'd prefer that we fix this in the project.clj though - I suspect what's happened is that someone's changed the project.clj to be suitable for dev without realising that the docs point to it

R.A. Porter21:01:56

Makes sense, but would that require scaffolding (setting up and tearing down a PG instance) to then run the tests?

jarohen21:01:16

It would, but the test dependencies are handled independently in crux-test's project.clj. In crux-jdbc they're marked as provided dependencies, so they'll only be included automatically at dev-time

jarohen21:01:52

In short, let's update the dep there to the main Postgres dep - if need be, we can include the pg-embedded dep in the dev profile so that it's still included when developing crux-jdbc (although the dev advice is to run the project from the root of the repo, which already includes the embedded dep)

jarohen21:01:17

I'll push a commit through now - thanks šŸ™‚

Toyam Cox17:01:24

Fun fact, there is no real way to figure out that the dependency is wrong because it does in fact write to the configured postgresql database. Ask me how I know!

R.A. Porter17:01:45

Yeah. I saw that as well. šŸ˜„

Toyam Cox17:01:25

I tested by replacing the dep, spinning up a second instance, and hey, there was my original data still there! I couldn't just read the database directly, it's opaque to me

nivekuil17:01:17

@U050V1N74: I fell victim to this as well! I suspect you can safely close https://github.com/juxt/crux/issues/1364 and blame the dep

jarohen17:01:45

aaaaah! šŸ’”

jarohen17:01:55

I could not repro that one šŸ˜„

jarohen17:01:10

thanks for letting me know!

nivekuil17:01:16

haha, sorry about that :) thanks for your effort!

jarohen17:01:55

ah, no worries - just glad you got to the bottom of it šŸ™‚