This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-08
Channels
- # adventofcode (9)
- # announcements (5)
- # babashka (3)
- # beginners (46)
- # calva (21)
- # cider (15)
- # clj-kondo (20)
- # cljs-dev (57)
- # cljsrn (10)
- # clojure (147)
- # clojure-dev (6)
- # clojure-europe (3)
- # clojure-france (2)
- # clojure-italy (8)
- # clojure-nl (18)
- # clojure-norway (5)
- # clojure-spec (16)
- # clojure-uk (63)
- # clojuredesign-podcast (7)
- # clojurescript (65)
- # clojurex (42)
- # cursive (12)
- # datomic (10)
- # fulcro (47)
- # graalvm (102)
- # graphql (2)
- # jobs (5)
- # joker (12)
- # off-topic (33)
- # pedestal (6)
- # re-frame (6)
- # reagent (8)
- # reitit (6)
- # remote-jobs (4)
- # rewrite-clj (10)
- # shadow-cljs (86)
- # sql (45)
- # testing (4)
- # tools-deps (43)
- # vim (8)
- # xtdb (3)
Where do I specify/pass the :schema argument as described in https://cljdoc.org/d/seancorfield/next.jdbc/1.0.9/doc/datafy-nav-and-schema?
https://github.com/seancorfield/next-jdbc/blob/master/src/next/jdbc/result_set.clj#L677 looks like it takes the schema as an option, but I'm not seeing where this gets called and it is marked as private.
Ah, I found an example in the tests that I think explains it https://github.com/seancorfield/next-jdbc/blob/master/test/next/jdbc/result_set_test.clj#L33-L44.
I'm working on documentation today so I'll make that clearer with more examples @markbastian -- thanks for the feedback!
Updated docs for :schema
https://github.com/seancorfield/next-jdbc/blob/master/doc/datafy-nav-and-schema.md#identifying-foreign-keys
BTW, I came up with an exceptionally minimalist example that works. You are welcome to use it if you want. https://github.com/markbastian/datafy-playground/blob/master/src/datafy_playground/datafy_jdbc_next.clj
See the updated docs I linked to -- you would pass the :schema
option to execute!
. You would not call datafiable-row
on its own.
The result of execute!
is already datafiable.
Cool, I'll check it out right now. Thanks!
You pretty much would never call datafy
/`nav` yourself -- that's generally going to be part of tooling, like REBL.
Yeah, I had this idea to create a web interface to navigate some data, so I guess that would be my own custom tool. Thanks for the all the help and advice.
The whole result set from execute!
is datafiable so as your tool calls datafy
/ nav
on it, things will "just. work." magically.
nice!
About the only time you'd ever call datafiable-row
yourself is inside a reduction of plan
, and even then it's only if you want an entire row realized without performing any operations on it (e.g., calling assoc
would realize the row with datafiable-row
anyway).
Then there's datafiable-result-set
which is useful for dealing with metadata pulled directly from JDBC (rather than via queries).
Updated example with your comments and it works perfectly https://github.com/markbastian/datafy-playground/blob/master/src/datafy_playground/datafy_jdbc_next.clj
the results of a query is namespaced with the table-name. is there a way to remove the table namespace and just have the column names?
(jdbc/execute-one! ["SELECT 1"] {:builder-fn next.jdbc.result-set/as-unqualified-arrays}
I would love to see a concrete example about this in the jdbc next docs. Today I was using jdbc next for the first time and I faced this issue with qualified names. I saw :builder-fn
mentioned in the docs but (because I’m a noob) I didn’t know where to give that map. Fortunately slack comes to rescue!
FYI @sonnyto clojure.java.jdbc
used to make column names unique by adding _N
to them (`_1`, _2
, etc) when there were collisions. next.jdbc
does not do that, so if you use unqualified builders, any column conflicts will result in "missing columns" (since it's "just" a hash map). If you use qualified columns -- which I _strongly recommend_ -- then they will remain unique.
Yeah, it's just something to watch out for. It's better practice to explicitly alias overlapping column names in your SQL than rely on the auto-numbering behavior of c.j.j. of course.
That implies you strongly recommend NOT to use Oracle :rolling_on_the_floor_laughing: I wholeheartedly agree!
Consider select a.*, b.* from table1 a join table 2 b on a.id = b.someid where b.col = ?
-- if both table1
and table2
contain id
(very likely!), then you will end up with just one :id
column in your rows (which will be b.id
I expect).
If you use qualified columns, you'll get both :a/id
and :b/id
.
(I plan to add that as a caveat in both the migration guide and the result set builder section of the docs today)
Updated docs for :schema
https://github.com/seancorfield/next-jdbc/blob/master/doc/datafy-nav-and-schema.md#identifying-foreign-keys
Any other documentation improvements that folks would like to see, while I'm doing a "documentation Friday"? https://github.com/seancorfield/next-jdbc/commits/master
When migrating from java.jdbc to next.jdbc is there a preferred replacement for the create-table-ddl functions? Should I be using honeysql instead?
create-table-ddl
was a pretty poor helper -- you might just as well write it all out as a string.
(jdbc/execute-one! ds ["
create table foo (
id int auto_increment,
name varchar(32),
primary key(id)
) engine=innodb"])
Aside from string-bashing, I think create-table-ddl
was actually worse to use 😐Yeah, it doesn't buy you a whole lot over just rolling it on your own.
One more easy one: How do I convert this java.jdbc connection map {:connection-uri "jdbc:h2:mem:mem_only"}
to jdbc.next. I've got {:dbtype "h2" :dbname "mem:mem_only"}
but that isn't right. I've tried many of the options at https://github.com/seancorfield/next-jdbc/blob/master/doc/all-the-options.md but no luck. I need to put mem into one of the keys, but not sure which.
I expect it to be {:dbtype "h2" :dbname "mem_only" :some-key "mem"}
. Just trying to figure out what :some-key is.
{:dbtype "h2:mem" :dbname "mem_only"}
would be the same answer for clojure.java.jdbc
BTW
Perfect. I just hadn't tried putting the mem on the dbtype, which makes sense.
@markbastian {:dbtype "h2:mem" :dbname "mem_only"}
See https://cljdoc.org/d/seancorfield/next.jdbc/1.0.9/api/next.jdbc#get-datasource
OK folks, here's a new feature I'm sketching out https://github.com/seancorfield/next-jdbc/commit/b2b7696973e96581450f9997af8b34f60c32bc87 -- the idea is that you can use it for logging (see the test added in that commit) so builder-adapter
is a terrible name for it but I'm not sure if logging-adapter
is descriptive enough... Suggestions?
I would love to see a concrete example about this in the jdbc next docs. Today I was using jdbc next for the first time and I faced this issue with qualified names. I saw :builder-fn
mentioned in the docs but (because I’m a noob) I didn’t know where to give that map. Fortunately slack comes to rescue!