honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
benny 2020-08-13T05:11:24.001300Z

any idea why my timestamps are being stored without a timestamp when i store like so

{:insert-into :invites
                  :values      [{:name       name
                                 :user_id    user-id
                                 :requested  (clj-time.coerce/to-sql-date requested)}]}

seancorfield 2020-08-13T05:21:46.001800Z

Nothing to do with HoneySQL -- that's up to the JDBC driver.

seancorfield 2020-08-13T05:23:59.002300Z

^ @benny HoneySQL just produces SQL -- it does not interact with the database at all.

seancorfield 2020-08-13T05:24:10.002600Z

Which Clojure wrapper for JDBC are you using?

benny 2020-08-14T04:16:15.014Z

so i was able to get mostly switched over but now i’m still getting an error inserting a LocalDateTime (or any DateTime)

Can't infer the SQL type to use for an instance of org.joda.time.LocalDateTime

benny 2020-08-14T04:31:09.014200Z

got it, had to just use java.util.Date

seancorfield 2020-08-14T05:36:39.014400Z

Or just require next.jdbc.date-time I suspect? PostgreSQL?

benny 2020-08-14T14:41:58.014600Z

yeah i had to require that and use a DateDateTime of any sort didn’t work, but yes psql

seancorfield 2020-08-14T15:10:45.014800Z

There's a next.jdbc.types namespace as well. Depending on what operation you're trying to perform, sometimes you can give PG a hint with one of those functions from the types namespace.

👍 1
benny 2020-08-13T05:25:53.003100Z

clojure.java.jdbc

seancorfield 2020-08-13T05:32:18.003600Z

What database are you using and what actual type is the requested column?

benny 2020-08-13T05:33:24.003800Z

pg — timestamp

benny 2020-08-13T05:33:37.004Z

requested timestamp not null,

seancorfield 2020-08-13T05:33:48.004200Z

FYI, clojure.java.jdbc is "stable", i.e., no longer being developed -- all maintenance effort has switched to next.jdbc which is both higher performance and has extra features to support date/time conversions, specifically for PostgreSQL.

benny 2020-08-13T05:34:16.004400Z

oh man

benny 2020-08-13T05:34:24.004600Z

well i’ll be switching then!

benny 2020-08-13T05:34:53.004800Z

mostly 1 for 1 swap?

seancorfield 2020-08-13T05:34:55.005Z

Feel free to ask questions about JDBC/database access/`next.jdbc`/c.j.j in #sql

seancorfield 2020-08-13T05:35:21.005200Z

Read the migration guide https://cljdoc.org/d/seancorfield/next.jdbc/1.1.582/doc/migration-from-clojure-java-jdbc

seancorfield 2020-08-13T05:35:37.005500Z

(one thing you'll immediately see is that next.jdbc has much better documentation!)

seancorfield 2020-08-13T05:36:20.005700Z

The http://clojure-doc.org site is broken and can't be updated, so even the limited c.j.j docs there are outdated and there's nothing I can do about that 😞

seancorfield 2020-08-13T05:37:02.005900Z

There's also a whole section on PG-specific tips & tricks in next.jdbc's docs: https://cljdoc.org/d/seancorfield/next.jdbc/1.1.582/doc/getting-started/tips-tricks#postgresql

benny 2020-08-13T05:40:01.006300Z

that’s awesome, thanks @seancorfield!

benny 2020-08-13T05:41:54.006500Z

i’m curious, just looking at stars (admittedly not a great start to my question), these sql libraries like honey and yesql have 1.5k stars, but neither cjj nor next have even 1k, are people interested in the libraries but not using it in practice, using raw jdbc, or something else? the numbers just don’t add up on the surface

seancorfield 2020-08-13T05:46:47.006700Z

@benny That was one of the things that shocked me, back in 2011, when I started working with Clojure: almost no one was doing JDBC stuff! That's how come I ended up taking over clojure.contrib.sql as it was then and turned it into clojure.java.jdbc in the new Contrib setup. I seemed to be the most active JDBC user with Clojure back then. Since then, a lot more people have started using JDBC with Clojure but since there was really no other JDBC library, you don't see "stars" in GitHub: it's not popularity, it's just what people use.

seancorfield 2020-08-13T05:47:33.006900Z

In order not to break c.j.j's API but to create the API I really wanted it to have, I created next.jdbc about 18 months ago, drawing on the lessons of maintaining c.j.j for eight years.

seancorfield 2020-08-13T05:47:50.007100Z

So next.jdbc is the "1.0" release that c.j.j was never going to get.

seancorfield 2020-08-13T05:50:37.007300Z

(and, no, I don't think stars are a useful measure of anything 🙂 )

benny 2020-08-13T05:52:49.007500Z

makes sense, thanks!

seancorfield 2020-08-13T05:53:32.007700Z

I don't have Maven download stats for c.j.j but next.jdbc has notched up 107K downloads in about a year.

wombawomba 2020-08-13T20:01:53.010900Z

I’d like to be able to call some of the Postgres pattern matching operators (https://www.postgresql.org/docs/current/functions-matching.html). Ideally I’d like them to work like any of the built-in binary operators (e.g. :=) and handle parametrization correctly (i.e. not be injectable). How should I go about this?

seancorfield 2020-08-13T20:07:02.011600Z

:like and :not-like are already built into HoneySQL @wombawomba -- can you be a bit more specific about what exactly you are trying to do?

seancorfield 2020-08-13T20:08:45.012400Z

And https://github.com/nilenso/honeysql-postgres#pattern-matching adds ILIKE etc.

wombawomba 2020-08-13T20:10:12.013300Z

well, I wanted to use SIMILAR TO and I couldn’t find it in honeysql or honeysql-postgres

wombawomba 2020-08-13T20:10:41.013800Z

however, I did find this: https://github.com/nilenso/honeysql-postgres/blob/master/src/honeysql_postgres/format.cljc#L91-L93 — figure I’ll just implement it the exact same way