This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-21
Channels
- # announcements (51)
- # asami (5)
- # babashka (25)
- # babashka-sci-dev (26)
- # beginners (33)
- # calva (10)
- # clj-kondo (51)
- # clj-yaml (99)
- # clojure (96)
- # clojure-australia (3)
- # clojure-berlin (5)
- # clojure-europe (151)
- # clojure-norway (58)
- # clojurescript (20)
- # cursive (13)
- # datalevin (1)
- # datomic (19)
- # docker (6)
- # emacs (55)
- # events (1)
- # fulcro (50)
- # gratitude (8)
- # juxt (7)
- # leiningen (5)
- # malli (6)
- # membrane (1)
- # nbb (28)
- # off-topic (22)
- # pathom (7)
- # polylith (20)
- # portal (1)
- # reagent (37)
- # reitit (2)
- # releases (2)
- # reveal (32)
- # scittle (34)
- # shadow-cljs (46)
- # testing (10)
- # tools-deps (33)
- # xtdb (18)
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"}
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?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)
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?
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"
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
can you share what you pass to hikari (with redacted sensitive details like password/user/url)?
{: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}
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
btw, if you create hikari datasource, as in javax.sql.DataSource
instance, you can use db explorer on that
when i tap the hikari object, it doesn’t have a db-explorer option, but it’s type is com.zaxxer.hikari.HikariDataSource
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
com.zaxxer.hikari.HikariDataSource implements javax.sql.DataSource… If you open a reveal context menu on datasource instance, will it show db explorer action?
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!
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
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 []))))
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 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)There is nrepl middleware that you can add to the middleware list that will open renewal window with evaluation results automatically shown
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