-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make datoms function work with system attribute components (#704)
* Make datoms function work with system attribute components * FIXUP --------- Co-authored-by: Jonas Östlund <[email protected]>
- Loading branch information
1 parent
acd9d4b
commit e1cb9b0
Showing
4 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
(ns datahike.test.attribute-refs.datoms-test | ||
(:require | ||
#?(:cljs [cljs.test :as t :refer-macros [is deftest testing]] | ||
:clj [clojure.test :as t :refer [is deftest testing]]) | ||
[datahike.api :as d] | ||
[datahike.db :as db :refer [ref-datoms]] | ||
[datahike.test.utils :refer [with-connect provide-unique-id | ||
recreate-database]])) | ||
|
||
(def cfg | ||
{:store {:backend :mem} | ||
:keep-history? true | ||
:attribute-refs? true | ||
:schema-flexibility :write}) | ||
|
||
(deftest test-datoms-with-components | ||
(with-connect [conn (-> cfg | ||
provide-unique-id | ||
recreate-database)] | ||
(d/transact conn [{:db/ident :name | ||
:db/cardinality :db.cardinality/one | ||
:db/index true | ||
:db/valueType :db.type/string} | ||
{:db/ident :age | ||
:db/cardinality :db.cardinality/one | ||
:db/valueType :db.type/long}]) | ||
(d/transact conn [{:name "Alice" | ||
:age 10}]) | ||
(let [all-datoms (d/datoms @conn {:index :avet :components []}) | ||
all-tx-inst-datoms (filter (fn [datom] | ||
(and (= (:e datom) | ||
(:tx datom)) | ||
(instance? java.util.Date | ||
(:v datom)))) | ||
all-datoms) | ||
name-datoms (filter (fn [datom] (= "Alice" (:v datom))) | ||
all-datoms)] | ||
(is (= 1 (count name-datoms))) | ||
(doseq [datom name-datoms] | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :avet | ||
:components [(:a datom)]}))) | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :avet | ||
:components [(:a datom) | ||
(:v datom)]}))) | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :avet | ||
:components [(:a datom) | ||
(:v datom) | ||
(:e datom)]}))) | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :avet | ||
:components [(:a datom) | ||
(:v datom) | ||
(:e datom) | ||
(:tx datom)]})))) | ||
|
||
(is (= 3 (count all-tx-inst-datoms))) | ||
(is (= (set all-tx-inst-datoms) | ||
(set (d/datoms @conn {:index :avet | ||
:components [:db/txInstant]})))) | ||
(is (= (set all-tx-inst-datoms) | ||
(set (d/datoms @conn {:index :aevt | ||
:components [:db/txInstant]})))) | ||
(doseq [datom all-tx-inst-datoms] | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :avet | ||
:components [:db/txInstant | ||
(:v datom) | ||
(:e datom)]}))) | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :avet | ||
:components [:db/txInstant | ||
(:v datom) | ||
(:e datom) | ||
(:tx datom)]}))) | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :aevt | ||
:components [:db/txInstant | ||
(:e datom)]}))) | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :aevt | ||
:components [:db/txInstant | ||
(:e datom) | ||
(:v datom)]}))) | ||
(is (= [datom] | ||
(d/datoms | ||
@conn | ||
{:index :aevt | ||
:components [:db/txInstant | ||
(:e datom) | ||
(:v datom) | ||
(:tx datom)]}))))))) |
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