This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-02
Channels
- # announcements (2)
- # babashka (21)
- # beginners (80)
- # bristol-clojurians (1)
- # calva (1)
- # cider (4)
- # clara (2)
- # clj-kondo (5)
- # cljs-dev (41)
- # clojure (8)
- # clojure-dev (2)
- # clojure-europe (28)
- # clojure-italy (11)
- # clojure-nl (4)
- # clojure-spec (13)
- # clojure-sweden (1)
- # clojure-uk (11)
- # clojuredesign-podcast (5)
- # clojurescript (5)
- # code-reviews (4)
- # cursive (25)
- # data-science (5)
- # datomic (25)
- # duct (15)
- # emacs (6)
- # fulcro (13)
- # graalvm (1)
- # graphql (5)
- # helix (2)
- # jobs (3)
- # jobs-discuss (4)
- # luminus (1)
- # malli (13)
- # meander (3)
- # off-topic (16)
- # pathom (2)
- # pedestal (1)
- # re-frame (5)
- # ring-swagger (3)
- # spacemacs (4)
- # sql (16)
- # tools-deps (1)
- # tree-sitter (8)
- # vrac (2)
- # xtdb (16)
- # yada (2)
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.
By better I mean more succinct @U0NCTKEV8. I will be using different queries, so I don't always know which columns will be dates.
@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.
might be better to use a date formatter for better readability rather than just calling .toString()
, though
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)