Created
April 19, 2022 07:07
-
-
Save kbosompem/b8e6a40aed607204b187e641df73fab2 to your computer and use it in GitHub Desktop.
Get Time Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[babashka.pods :as pods]) | |
(pods/load-pod 'huahaiy/datalevin "0.6.6") | |
(require '[pod.huahaiy.datalevin :as d]) | |
(def schema (read-string (slurp "https://gist.githubusercontent.com/kbosompem/e2554c77ce32c4a862d87c3d2eaef9d9/raw/cd8f9eca7f3f0e8adf8572bf7761e5656133b25e/schema.edn"))) | |
(def data (read-string (slurp "https://gist.githubusercontent.com/kbosompem/e2554c77ce32c4a862d87c3d2eaef9d9/raw/cd8f9eca7f3f0e8adf8572bf7761e5656133b25e/data.edn"))) | |
(def conn (d/get-conn "./ldtdb" schema)) | |
(d/transact! conn data) | |
(def db (d/db conn)) | |
(d/defpodfn age [birthday today] | |
(quot (- (:time (bean today)) | |
(:time (bean birthday))) | |
(* 1000 60 60 24 365))) | |
(def qry '[:find ?name | |
:in $ ?age ?today | |
:where | |
[?e :person/name ?name] | |
[?e :person/born ?dob] | |
[(age ?dob ?today) ?age]]) | |
(d/defpodfn age2 [birthday today] | |
(quot (- (.getTime today) | |
(.getTime birthday)) | |
(* 1000 60 60 24 365))) | |
(def qry2 '[:find ?name | |
:in $ ?age ?today | |
:where | |
[?e :person/name ?name] | |
[?e :person/born ?dob] | |
[(age2 ?dob ?today) ?age]]) | |
;Works | |
(d/q qry db 63 #inst "2013-08-02T00:00:00.000-00:00") | |
;Fails | |
(d/q qry2 db 63 #inst "2013-08-02T00:00:00.000-00:00") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment