Hi, I'm getting java.sql.Date
instances from a query. I'm wondering if there's something better than checking for type
and applying .toString
to those values.
Better for what?
And you shouldn't have to check types, columns will always be the same type
@zanategdl Why would you want strings from date/time/timestamp columns in the database?
@seancorfield Because I'm writing this stuff to a Google Sheet.
By better I mean more succinct @hiredman. I will be using different queries, so I don't always know which columns will be dates.
might be better to use a date formatter for better readability rather than just calling .toString()
, though
^ @zanategdl That would be my recommendation too.
In honeysql, is it possible to select the result of applying a binary operator without resorting to raw
? e.g. SELECT 2 - 1;
? If I try something like (hsql/format {:select [[:- 2 1]]})
or variants, I run into "Alias should have two parts" errors.
I suppose (hsql/format {:select [(hsql/call :int8mi 2 1)]}
works, but is it the best/only way?
user=> (require '[honeysql.helpers :refer [select]] '[honeysql.core :as h])
nil
user=> (h/format (select (h/call :- 2 1)))
["SELECT (? - ?)" 2 1]
Is that what you're after?
Under the hood, it's
user=> (select (h/call :- 2 1))
{:select (#sql/call [:- 2 1])}
That works, thanks @seancorfield! I was just slightly off in one of my other attempts to use call - (h/format {:select [(h/call :- 2 1)]})
works. I was just missing the square brackets. I didn't see any examples to show that call is clever enough to handle operators as well as function calls, I thought it was trying to do _(?,?)
.
This is an example in the readme but it's easy to miss
(-> (helpers/update :films)
(sset {:kind "dramatic"
:watched (sql/call :+ :watched 1)})
(where [:= :kind "drama"])
sql/format)
(and there are a couple of tests around it -- also easy to miss in the mass of other tests)