Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; load from database
- (defn get-activities [db users_id & [limit]]
- (let [query (if limit ["select * from activity where users_id = ? order by for_date desc limit ?" users_id limit]
- ["select * from activity where users_id = ? order by for_date desc" users_id])]
- (j/query db query {:identifiers #(.replace % \_ \-)})))
- ; write to database
- (s/fdef insert-activity :args (s/cat :db any? :content ::content :date inst? :users_id number?))
- (defn insert-activity [db content date users_id]
- (j/insert! db :activity {:content content
- :for_date (new java.sql.Date (.getTime date))
- :users_id users_id}))
- ; calling function
- (db-act/insert-activity db "some text" (t-coerce/to-date (t-core/today)) 1)
- ; loading function
- (db-act/get-activities db 1)
- ; ==> output:
- :for-date #inst "2016-12-20T23:00:00.000-00:00"
- ; while as today clearly is the 21. of Dec here in Germany
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement