This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-07
Channels
- # announcements (11)
- # babashka (29)
- # beginners (70)
- # biff (13)
- # calva (1)
- # clojure (24)
- # clojure-europe (125)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-portugal (2)
- # clojure-uk (3)
- # clojurescript (9)
- # core-async (29)
- # cursive (4)
- # emacs (10)
- # etaoin (14)
- # events (3)
- # fulcro (10)
- # funcool (4)
- # helix (1)
- # honeysql (12)
- # introduce-yourself (1)
- # jobs (2)
- # juxt (2)
- # lsp (1)
- # off-topic (17)
- # polylith (58)
- # portal (20)
- # remote-jobs (2)
- # shadow-cljs (2)
- # squint (4)
- # tools-deps (9)
It seems to me from the examples bit of the https://www.postgresql.org/docs/current/sql-truncate.html that postgres accepts multiple tables to truncate, whereas honey does not?
=# create table t1 (id int);
CREATE TABLE
=# create table t2 (id int);
CREATE TABLE
=# insert into t1 values (1);
INSERT 0 1
=# insert into t2 values (2);
INSERT 0 1
=# select * from t1;
id
----
1
(1 row)
=# select * from t2;
id
----
2
(1 row)
=# truncate t1, t2;
TRUNCATE TABLE
=# select * from t1;
id
----
(0 rows)
=# select * from t2;
id
----
(0 rows)
=#
Is this worth reporting as an issue?Sure, open an issue. I was looking at this just the other day as I extended truncate to support cascade etc. Not sure what the syntax would have to be now, since a sequence argument already means "table + options", but I'll give it some thought.
I'm observing super weird behavior:
user=> (honey.sql/format
{:replace-into :accounts
:values [{:public-key 1 :private-key 2}]
:returning [:*]})
ExceptionInfo These SQL clauses are unknown or have nil values: :replace-into {:replace-into :accounts}
user=> (honey.sql/format
{:replace-into :accounts
:values [{:public-key 1 :private-key 2}]
:returning [:*]}
{:dialect :mysql
:quoted-kebab true})
ExceptionInfo These SQL clauses are unknown or have nil values: :replace-into {:replace-into :accounts}
And then suddenly...
user=> (honey.sql/format
{:replace-into :accounts
:values [{:public-key 1 :private-key 2}]
:returning [:*]}
{:dialect :mysql
:quoted-kebab true})
["REPLACE INTO `accounts` (`public-key`, `private-key`) VALUES (?, ?) RETURNING *" 1 2]
user=> (honey.sql/format
{:replace-into :accounts
:values [{:public-key 1 :private-key 2}]
:returning [:*]})
["REPLACE INTO accounts (public_key, private_key) VALUES (?, ?) RETURNING *" 1 2]
I thought format was "just" a function but then how come it's not consistent? Does it have some state outside the function for the options?Oh okay digging in the source I figured it out. The first time the :mysql dialect is used it adds the clauses globally which means later calls (even if the :dialect passed to format is not :mysql) have access to it. https://github.com/seancorfield/honeysql/blob/23be700b7eb74ff75096bc5c8324634a8e2b9e84/src/honey/sql.cljc#L109
Yeah, my feeling with that was that if you use a dialect, it's "harmless" to have any additions it makes stay in play -- if two dialects conflict, selecting back and forth between them should "correct" the formatting anyway.
If you are only using one dialect, you probably should set-dialect!
at startup. Specifying :dialect
in a format
call also turns on quoting for that call (unless you also say :quoted false
).
Yeah I can understand that. I think the element that really bugged me was that the first call with :dialect :mysql would fail
With? Or without?
Oh, that's definitely a bug - can you open an issue? I'm on my phone.