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)}]}
Nothing to do with HoneySQL -- that's up to the JDBC driver.
^ @benny HoneySQL just produces SQL -- it does not interact with the database at all.
Which Clojure wrapper for JDBC are you using?
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
got it, had to just use java.util.Date
Or just require next.jdbc.date-time
I suspect? PostgreSQL?
yeah i had to require that and use a Date
— DateTime
of any sort didn’t work, but yes psql
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.
clojure.java.jdbc
See if this helps http://clojure-doc.org/articles/ecosystem/java_jdbc/using_sql.html#protocol-extensions-for-transforming-values
What database are you using and what actual type is the requested
column?
pg — timestamp
requested timestamp not null,
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.
oh man
well i’ll be switching then!
mostly 1 for 1 swap?
Feel free to ask questions about JDBC/database access/`next.jdbc`/c.j.j in #sql
Read the migration guide https://cljdoc.org/d/seancorfield/next.jdbc/1.1.582/doc/migration-from-clojure-java-jdbc
(one thing you'll immediately see is that next.jdbc
has much better documentation!)
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 😞
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
that’s awesome, thanks @seancorfield!
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
@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.
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.
So next.jdbc
is the "1.0" release that c.j.j was never going to get.
(and, no, I don't think stars are a useful measure of anything 🙂 )
makes sense, thanks!
I don't have Maven download stats for c.j.j but next.jdbc
has notched up 107K downloads in about a year.
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?
: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?
And https://github.com/nilenso/honeysql-postgres#pattern-matching adds ILIKE
etc.
well, I wanted to use SIMILAR TO
and I couldn’t find it in honeysql or honeysql-postgres
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