Advertisement
Guest User

Untitled

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