Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
refactor ->db-basis
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrasp committed Aug 9, 2023
1 parent cd8cc94 commit 4514f39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
21 changes: 5 additions & 16 deletions src/gxtdb/adapters/db.clj
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
(ns gxtdb.adapters.db
(:require [gxtdb.adapters.tx-time :refer [->clj-time]]
[gxtdb.utils :refer [not-nil?]]
[xtdb.api :as xt]))

(defn ->db-basis [params]
(let [valid-time (some-> params :valid-time ->clj-time)
tx-time (some-> params :tx-time ->clj-time)
tx-id (some-> params :tx-id :value :some)]
(case [(not-nil? valid-time) (not-nil? tx-time) (not-nil? tx-id)]
[true true true] {::xt/valid-time valid-time}
[true false false] {::xt/valid-time valid-time}
[true true false] {::xt/valid-time valid-time ::xt/tx-time tx-time}
[true false true] {::xt/valid-time valid-time ::xt/tx tx-id}
[false true false] {::xt/tx-time tx-time}
[false false true] {::xt/tx tx-id}
nil)))
(:require [gxtdb.utils :as utils]))

(defn db-basis->proto [db-basis-reponse]
{:xt-id (-> db-basis-reponse :xt/id str)
:valid-time (-> db-basis-reponse :xtdb.api/valid-time utils/->inst-str)
:tx-time (-> db-basis-reponse :xtdb.api/tx-time utils/->inst-str)})
8 changes: 4 additions & 4 deletions test/gxtdb/adapters/db_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
:tx-time {:value {:some "2023-06-12T21:32:44.717-05:00"}}
:tx-id {:value {:some 3}}})

(deftest ->db-basis-test
(deftest db-basis->proto-test
(testing "When all fields are none"
(is (= nil (db/->db-basis all-none-input))))
(is (= nil (-> actual db-basis->proto all-none-input))))
(testing "When all tx inputs are some"
(is (= nil (db/->db-basis tx-some-inputs))))
(is (= nil (-> actual db-basis->proto tx-some-inputs))))
(testing "When only tx-id input is some"
(is (= {::xt/tx 3} (db/->db-basis {:tx-id {:value {:some 3}}}))))
(is (= {::xt/tx 3} (-> actual db-basis->proto {:tx-id {:value {:some 3}}}))))
(testing "When only tx-time input is some"
(is (= {::xt/tx-time #inst "2023-06-13T02:32:44.717-00:00"} (db/->db-basis {:tx-time {:value {:some "2023-06-12T21:32:44.717-05:00"}}}))))
(testing "When only valid-time is some"
Expand Down

0 comments on commit 4514f39

Please sign in to comment.