honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
benny 2020-08-14T15:17:59.016200Z

what’s the proper way to use a pg enum? i see #224 and others related but don’t see the conclusion

benny 2020-08-14T15:30:37.017200Z

my current path forward is this, but obviously not ideal

(sql/raw (str "'" (name :keyword-i-use) "'"))

seancorfield 2020-08-14T15:44:08.018200Z

Why not just (name :keyword-i-use) as a parameter @benny? Why try to make it into a raw SQL string?

benny 2020-08-14T15:45:00.018900Z

afaik i’m using pg and that imposes double quotes which references a column

seancorfield 2020-08-14T15:45:03.019200Z

(and then read https://cljdoc.org/d/seancorfield/next.jdbc/1.1.582/doc/getting-started/tips-tricks#working-with-enumerated-types for how to have the conversion handled by next.jdbc)

seancorfield 2020-08-14T15:45:44.019400Z

I don't understand you.

seancorfield 2020-08-14T15:46:20.019600Z

(name :keyword-i-use) is a string and will be treated just like any other string (parameter).

benny 2020-08-14T15:46:25.019800Z

right, sorry

benny 2020-08-14T15:46:32.020Z

that was a different approach i tried

benny 2020-08-14T15:46:45.020200Z

but using (name passes it as a parameter

benny 2020-08-14T15:46:50.020400Z

which implied character varying

benny 2020-08-14T15:46:55.020600Z

instead of enum

seancorfield 2020-08-14T15:47:06.020800Z

It will probably help people help you if you can share actual code then instead of talking about abstractions 🙂

seancorfield 2020-08-14T15:47:15.021Z

Did you read the link I posted in the main channel?

benny 2020-08-14T15:47:27.021300Z

i did, that’s what i’ll use

benny 2020-08-14T15:47:32.021500Z

it mimics what i’m doing it looks

seancorfield 2020-08-14T15:47:34.021700Z

It explains how to have those string parameters treated as enums.

seancorfield 2020-08-14T15:47:54.021900Z

It is not like what you're doing.

benny 2020-08-14T15:48:03.022100Z

but to clarify:

(sql/format {:select [:*] :from [:foo] :where [:= :status (name :pending)]})
=> ["SELECT * FROM foo WHERE status = ?" "pending"]

benny 2020-08-14T15:48:13.022300Z

that is invalid for an enum column

seancorfield 2020-08-14T15:48:30.022500Z

Read the link I posted. It says how to make that work.

benny 2020-08-14T15:49:01.022700Z

agreed, just clarifying why just using (name :foo) wouldn’t suffice

benny 2020-08-14T15:49:11.022900Z

it passes it as a parm

seancorfield 2020-08-14T15:49:18.023200Z

Right, which is what you want.

benny 2020-08-14T15:49:29.023400Z

i don’t want a param

benny 2020-08-14T15:49:40.023600Z

pg sees it as a character varying value

benny 2020-08-14T15:49:45.023800Z

if it’s passed as a param

benny 2020-08-14T15:49:50.024Z

it has to be inline

seancorfield 2020-08-14T15:49:55.024200Z

No it doesn't.

seancorfield 2020-08-14T15:50:07.024400Z

That link I posted shows how to handle this situation.

seancorfield 2020-08-14T15:50:22.024600Z

It is specifically about enumerated types in PostgreSQL.

seancorfield 2020-08-14T15:50:55.024800Z

(as-other (name :pending)) or even just (as-other "pending")

benny 2020-08-14T15:51:46.025Z

agreed

benny 2020-08-14T15:51:50.025200Z

as-other is needed

seancorfield 2020-08-14T15:52:02.025400Z

Which is why I posted that link 🙂

benny 2020-08-14T15:52:11.025600Z

that’s all i’m saying, it can’t just be name

benny 2020-08-14T15:52:27.025800Z

it has to be name + your or my wrapper

seancorfield 2020-08-14T15:52:44.026Z

But it can be a parameter, which was what I was telling you.

benny 2020-08-14T15:52:50.026200Z

it can’t 🙂

benny 2020-08-14T15:52:57.026400Z

well with yours it can

benny 2020-08-14T15:53:04.026600Z

but just as name it can’t

benny 2020-08-14T15:53:08.026800Z

i think we’re in violent agreement

benny 2020-08-14T15:53:29.027Z

just don’t want someone to fall into the trap that just name will work, you need more like as-other

seancorfield 2020-08-14T15:54:05.027200Z

If anyone actually reads the PostgreSQL-specific docs in next.jdbc, they would know that.

benny 2020-08-14T15:54:45.027400Z

practically i don’t think many people read them all the way through and a bunch of google’s only lead me to 224

seancorfield 2020-08-14T15:55:00.027600Z

My two messages were basically "Don't do that awful raw thing -- use plain ol' (name :keyword-i-use) and then do what it tells you in the docs."

👍 1
benny 2020-08-14T15:55:15.027900Z

i blame google’s indexing 😉

seancorfield 2020-08-14T15:55:26.028200Z

I blame people for not actually reading the docs 🙂

benny 2020-08-14T15:55:49.028400Z

i guess the same could be said about eulas lol

benny 2020-08-14T15:56:04.028600Z

lots of important things in there that people glaze over too

benny 2020-08-14T15:56:35.028800Z

i agree though, i should’ve read it

benny 2020-08-14T15:56:45.029Z

and thank you for spending your time pointing me in the right direction

benny 2020-08-14T15:56:58.029200Z

your stuff is above par

seancorfield 2020-08-14T15:58:31.029400Z

Thanks. When I rewrite HoneySQL, I intend it to have docs on par with next.jdbc.

👍 1