Hi there. I’m having a problem with Postgresql not being very happy with HoneySQL@v2 converting :foo/bar
to "foo"."bar"
when set
-ing a new value. For example:
(-> (helpers/update :user)
(helpers/set {:foo/bar 1})
(helpers/where [:= :user/id id])
(helpers/returning :*)
(sql/format {:dialect :ansi}))
will not work because PSQL requires that columns do not contain the table name. Is there a way to disable this behaviour? I can just convert those keywords to simple keywords but that’s a bit ugly. Thanks in advance.Open an issue on github and I'll fix it tomorrow. It's a bug.
Will do. Thanks 🙂
Hi there. Where should I be looking into if I want to configure automatic conversion between kebab-case
and snake_case
for both table names and column names? Thanks in advance.
it does that already
It doesn’t for me for some reason…
I’m using Hikari for pooling, and every time I use honeysql it always yell at me for not having the proper relation
are you using next jdbc?
yep
do you have csk on your classpath?
I dont know what that is sorry
camel snake kebab
oh yeah I do
I have it in lein
do I need to also require
it like next.jdbc.datetime
?
so here’s what I have atm:
;; conn
(connection/->pool HikariDataSource (select-keys env [:jdbcUrl]))
(s/defn read-user-tab :- [TabDB]
[{:user/keys [id]} :- {:user/id s/Uuid}]
(log/info "Reading tabs for user id" id)
(nj/with-transaction [tx db]
(nj/execute! tx (-> (helpers/select :*)
(helpers/from :tab)
(helpers/where [:= :tab/user-id id])
(sql/format {:dialect :ansi})))))
I’m getting yelled at that user-id
relation doesn’t exist
it’s called user_id
in the db
you don't need the :tab/user-id
just [:= :user-id id]
let me test real quick
@dharrigan No luck. It’s still giving me ERROR: column "user-id" of relation "tab" does not exist
with or without the tab
namespace
changing it to user_id
works as expected
question why dialect ansi?
because I want quoting
the quoting may disable the undasherizing
@_@
holy heck
you’re right
I just removed it and it works
:party-corgi:
haha is that even intended?
probably. Sean wouldn't do anything without a reason 🙂
it's probably because as you're using ansi, it won't make any assumptions about the identifiers
it'll treat them "literally"
rather than trying to undasherize them
I mean I can rename the table, but it’s hard trying to find anything more suitable than user
I have another problem it seems. The returned map still keeps it as user_id
…
Well that’s tomorrow’s problem. Time for me to do something else 😅
User
is the only convention I break (keeping tables singular) and I call it users
makes life simple 🙂
@rextruong To clarify some stuff about the camel snake kebab stuff: that only affects next.jdbc
and it only affects 1) names in ResultSet
’s that the library converts to Clojure and 2) names in Clojure data structures that the library converts to SQL — it does not (cannot) affect anything in the SQL string itself.
HoneySQL V2 defaults to :ansi
dialect so you don’t need to provide it as an option (it’s relatively harmless to do so). If you specify a dialect, you get quoting. You can also ask for :quoted true
to get quoted with the current/default dialect.
If you ask HoneySQL to quote names, it does so without dealing with -
/`_` — in both V1 (which is the code @dharrigan linked to) and V2 here: https://github.com/seancorfield/honeysql/blob/v2/src/honey/sql.cljc#L150-L169
user=> (-> {:select :* :from :tab :where [:= :tab/user-id 42]} (sql/format))
["SELECT * FROM tab WHERE tab.user_id = ?" 42]
user=> (-> {:select :* :from :tab :where [:= :tab/user-id 42]} (sql/format {:quoted true}))
["SELECT * FROM \"tab\" WHERE \"tab\".\"user-id\" = ?" 42]
See some of the important differences around V1/V2 handling of names here https://github.com/seancorfield/honeysql/blob/v2/doc/differences-from-1-x.md#option-changes