This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-22
Channels
- # architecture (30)
- # beginners (56)
- # cider (16)
- # cljs-dev (12)
- # cljsrn (21)
- # clojure (169)
- # clojure-austin (1)
- # clojure-estonia (1)
- # clojure-italy (3)
- # clojure-russia (1)
- # clojure-spec (56)
- # clojure-uk (46)
- # clojurescript (53)
- # consulting (3)
- # core-async (3)
- # cursive (14)
- # data-science (16)
- # datascript (1)
- # datomic (26)
- # defnpodcast (11)
- # docs (3)
- # emacs (6)
- # fulcro (4)
- # graphql (24)
- # hoplon (8)
- # instaparse (4)
- # java (2)
- # jobs (1)
- # jobs-rus (1)
- # jobs_rus (1)
- # keechma (1)
- # luminus (2)
- # lumo (1)
- # mount (36)
- # off-topic (30)
- # om-next (5)
- # onyx (29)
- # precept (23)
- # re-frame (20)
- # reagent (2)
- # remote-jobs (9)
- # ring (2)
- # ring-swagger (3)
- # rum (3)
- # shadow-cljs (100)
- # spacemacs (17)
- # sql (10)
- # timbre (2)
- # unrepl (29)
- # yada (2)
How do you guys use dates in clojure? I want a symbol to represent a timestamp a couple months before current date to pass into a query
@josmith2016 I've used a number of libraries over the years. I still quite like date-clj
-- https://github.com/stackoverflow/date-clj -- but it only traffics in java.util.Date
so we use clj-time
-- https://github.com/clj-time/clj-time -- which is the de factor standard for Joda Time (for UTC-based time). We're switching over to clojure.java-time
-- https://github.com/dm3/clojure.java-time -- which is a great wrapper for Java Time (using the native Java libraries makes sens if you're on Java 8 or 9).
All of them support date arithmetic.
Example using clojure.java-time
:
boot.user=> (require '[java-time :as jt])
nil
boot.user=> (-> (jt/zoned-date-time) (jt/minus (jt/months 2)) (jt/java-date))
#inst "2017-11-22T18:01:47.451-00:00"
boot.user=>
Thank you @seancorfield. Also I was wondering if I have 2 different databases I’m connecting to, say db1 and db2. If I run a query on db1, using the jdbc/query db1 command, then I query the second using jdbc/query db2, then I query the first one again the same way. What happens? Does it reuse the connection from the first query? Does it open and close a connection to db1 then db2 then db1 again? If it doesn’t use the same connection, is this something the connection pooling would fix?
When you say "different databases" do you mean different schemas within the same database instance, or genuinely separate database instances?
For the former, assuming user permissions allow you to select from both schemas, you can use a single connection for both db1 and db2 queries. For the latter, each database instance would have its own set of connections.
As for reusing connections against any particular database, read http://clojure-doc.org/articles/ecosystem/java_jdbc/reusing_connections.html -- connections are only going to be reused if you set things up that way.
So you'll have a connection pool set up for db1 and a separate connection pool set up for db2.