reveal

bmd 2022-09-21T02:16:00.208159Z

I’m trying to play with the db explorer and have tried various maps, but none of them give the db explorer menu item. From the next.jdbc docs, I’m guessing only :java-url, :user, and :password are needed. Do I need to add some metadata to it or something?

{:dbtype "postgres"
 :jdbcUrl "jdbc:"
 :host ""
 :port 5432
 :user "myuser"
 :password "mypw"}

vlaaad 2022-09-21T05:41:35.936919Z

Do you have next.jdbc on the classpath?

vlaaad 2022-09-21T05:42:59.301449Z

Or an old clojure jdbc?

bmd 2022-09-21T12:07:19.971259Z

It’s next.jdbc

vlaaad 2022-09-21T12:19:36.047009Z

Hmm, can you try this code in the REPL and report the results?

(require '[clojure.string :as str] 'next.jdbc)
(import '[clojure.lang Associative])
(let [get-ds (resolve 'next.jdbc.protocols/get-datasource)
      get-conn (resolve 'next.jdbc.protocols/get-connection)
      sourceable (resolve 'next.jdbc.protocols/Sourceable)
      x {:dbtype "postgres"
         :jdbcUrl "jdbc:"
         :host ""
         :port 5432
         :user "myuser"
         :password "mypw"}]
  (if (or (and (string? x) (str/starts-with? x "jdbc:"))
          (and (instance? Associative x)
               (or (contains? x :jdbcUrl)
                   (and (contains? x :dbtype) (contains? x :dbname))))
          (contains? (meta x) 'next.jdbc.protocols/get-datasource)
          (->> sourceable
               deref
               :impls
               keys
               (remove #{Associative String})
               (some #(instance? % x))))
    (get-conn (get-ds x) {})
    :doesn't-work))
does it return something? does it throw?

bmd 2022-09-21T12:58:03.097889Z

When evaling that and not tapping it to reveal, I get {:fx/type #function[vlaaad.reveal.view/observable-view], :ref #atom[nil 0x739d0f14], :fn #function[permiso.source.sphere.db.bmd-db/eval64902/fn--64905]} If I cider-tap-last-sexp, it causes a stackoverflowerror. If it helps, we pass a map w/ these keys to #’hikari-cp.core/make-datasource

(:adapter
 :metric-registry
 :application-name
 :password
 :username
 :max-lifetime
 :minimum-idle
 :connection-timeout
 :leak-detection-threshold
 :url
 :read-only
 :maximum-pool-size
 :idle-timeout)

vlaaad 2022-09-21T13:03:11.435809Z

hmm, not sure what’s your REPL setup, but it’s impossible to return a map there, it should either throw, return :doesn’t-work or return connection?

vlaaad 2022-09-21T13:04:41.718369Z

can you share stackoverflow error stack trace?

bmd 2022-09-21T13:08:31.886259Z

doh, i’m sorry. I copy/pasted and then had to do other stuff, and then i eval’d the wrong code when i came back. When I eval the code (w/o tapping it to reveal), i get FATAL: password authentication failed for user "spheredb"

vlaaad 2022-09-21T13:09:56.871139Z

This is the reason reveal does not suggest db explorer, you need valid credentials

vlaaad 2022-09-21T13:11:28.936169Z

I assume you replaced x with other map that has “spheredb” user?

bmd 2022-09-21T13:13:14.447839Z

i had replaced the x map w/ the proper values when i got that error. But now when i replaced it w/ what we pass to hikari, i get :doesn’t-work

vlaaad 2022-09-21T13:14:11.381389Z

can you share what you pass to hikari (with redacted sensitive details like password/user/url)?

bmd 2022-09-21T13:16:47.814419Z

{:adapter "postgresql"
 :application-name "myapp"
 :password "mypw"
 :username "myuser"
 :max-lifetime 60000
 :minimum-idle 4
 :connection-timeout 30000
 :leak-detection-threshold 10000
 :url "jdbc:"
 :read-only true
 :maximum-pool-size 10
 :idle-timeout 60000}

vlaaad 2022-09-21T13:19:40.344679Z

Is this format supported by next.jdbc? When I implemented next.jdbc support, I mimicked what next.jdbc expects from maps to be treated as data source description, namely, it needed to have either :jdbcUrl key, or both :dbtype and :dbname keys

vlaaad 2022-09-21T13:24:23.517519Z

btw, if you create hikari datasource, as in javax.sql.DataSource instance, you can use db explorer on that

bmd 2022-09-21T13:27:33.675269Z

when i tap the hikari object, it doesn’t have a db-explorer option, but it’s type is com.zaxxer.hikari.HikariDataSource

bmd 2022-09-21T13:28:16.817339Z

and not sure if next.jdbc consumes the map or not, as i’m new on this project

bmd 2022-09-21T13:46:41.896279Z

when i call (next.jdbc/get-connection on the datasource (type com.zaxxer.hikari.HikariDataSource) i get a com.zaxxer.hikari.pool.HikariProxyConnection object, which i use in a next.jdbc/execute! call

vlaaad 2022-09-21T15:41:55.203319Z

com.zaxxer.hikari.HikariDataSource implements javax.sql.DataSource… If you open a reveal context menu on datasource instance, will it show db explorer action?

bmd 2022-09-21T16:10:20.709119Z

doesn’t seem to. I tried the menu from each of the 4 components of the datasource. I’ll work on getting a straight next.jdbc object into reveal tonight and report how it goes (it’ll be middle of the night for you). Thanks for your time and help!

vlaaad 2022-09-21T16:38:53.022529Z

Great! Just a note — if action isn't available, it probably means that an attempt to evaluate it threw an exception, and reveal drops all action evaluation exceptions as "unavailable actions" — https://github.com/vlaaad/reveal/blob/master/src/vlaaad/reveal/action.clj#L53

vlaaad 2022-09-21T16:39:59.961559Z

You can disable this and see if there are exceptions

vlaaad 2022-09-21T16:42:27.164309Z

To disable, re-evaluate it to something else in the REPL, e.g.:

(in-ns 'vlaaad.reveal.action)
(defn collect [annotated-value]
  (let [{:keys [value annotation]} annotated-value
        actions (->> @*registry
                     (keep (fn [[id check]]
                             (try
                               (when-let [f (check value annotation)]
                                 (let [label (name id)]
                                   {:id id
                                    :label label
                                    :form (stream/horizontal
                                            (stream/raw-string "(" {:fill :util})
                                            (stream/raw-string label {:fill :symbol})
                                            stream/separator
                                            (stream/stream value annotation)
                                            (stream/raw-string ")" {:fill :util}))
                                    :invoke f}))
                               (catch Exception e (.printStackTrace e))))))                  ;; <- I only changed this line
        freqs (->> actions (map :label) frequencies)]
    (->> actions
         (sort-by (juxt :label :id))
         (map #(cond-> % (< 1 (freqs (:label %))) (assoc :label (str (symbol (:id %))))))
         (into []))))

bmd 2022-09-21T18:36:42.640819Z

Got it to pretty much the smallest possible code:

(def next-source-map
  (let [d    (datasource-map)]
    {:dbtype    "postgres"
     :dbname    dbname
     :host      host
     :jdbc-url  (:url d)
     :user      (:username d)
     :password  (:password d)
     :read-only true}))

(def next-source (next.jdbc/get-datasource next-source-map))

(with-open [connection (jdbc/get-connection next-source)]
  (jdbc/execute! connection [sql-query-str]))
The above code does run the sql-query. I hadn’t snapped that there are two version of reveal, so I switched to the latest reveal-pro on maven 1.3.351 and restarted my repl, and eval’d next-source-map, the datasource (created from get-datasource), and the connection (from get-connection). None of these had a db-explorer menu item. Though it’d be nice to have this working, it isn’t critical. We can drop it for now and I’ll revisit once I have more time to devote to learning reveal better from your reveal/extend github page. Again thanks for your time thanks3

vlaaad 2022-09-21T19:25:37.728929Z

Btw it's :jdbcUrl, not :jdbc-url

bmd 2022-09-21T19:28:45.322149Z

I’ve been using

(evil-define-key 'normal cider-mode (kbd ", e q") 'cider-tap-last-sexp)
to have a keystroke to easily tap, but it just being listed as a key binding in spacemacs. Is there a better way to work w/ reveal? (I sadly don’t know elisp very well)

vlaaad 2022-09-21T19:35:47.148519Z

There is nrepl middleware that you can add to the middleware list that will open renewal window with evaluation results automatically shown

bmd 2022-09-21T19:56:20.158809Z

i’ve been wanting that, and have tried, but obviously have been doing something wrong. In ~/.lein/profiles.clj I have this under user:

:dependencies [[com.bhauman/rebel-readline "0.1.4"]
                       ; [vlaaad/reveal "1.3.276"]
                       [dev.vlaaad/reveal-pro "1.3.351"]
                       ]
and this at the top level of the map (parallel to :user)
:repl {:dependencies [[vlaaad/reveal-pro "1.3.351"]]
        :jvm-opts ["-Dvlaaad.reveal.prefs={:theme,:light}"]}
        :global-vars {*print-length* 100}
        :repl-options {:nrepl-middleware [vlaaad.reveal.nrepl/middleware]}
        }
and then for extra measure added this to the root level of my project in .nrepl.edn
{:middleware [vlaaad.reveal.nrepl/middleware]}
I then lein repl from a terminal and jack into it from emacs. I still need to add-tap to a reveal/ui

vlaaad 2022-09-21T20:00:11.730519Z

Why do you still need to tap? Is there a window shown? Does it have repl output?

bmd 2022-09-21T20:05:41.944999Z

No window appears until i add-tap. There is a background java app that starts when the repl does, iirc (have done enough permutations not 100% positive when it starts, but 99.9% certain it’s before add-tap). But no window pops up when the java app does