Created
November 30, 2024 17:28
-
-
Save darkleaf/6f069156b263b55655a0075515ad4c06 to your computer and use it in GitHub Desktop.
datomic composite index
This file contains hidden or 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
(ns experiments.datomic | |
(:require | |
[datomic.api :as d])) | |
(comment | |
(def db-uri "datomic:mem://hello") | |
(d/create-database db-uri) | |
(def conn (d/connect db-uri)) | |
@(d/transact conn [{:db/ident :post/uuid | |
:db/valueType :db.type/uuid | |
:db/cardinality :db.cardinality/one | |
:db/unique :db.unique/identity} | |
{:db/ident :post/published-at | |
:db/valueType :db.type/instant | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :post/status | |
:db/doc "note: try to use enums: https://docs.datomic.com/schema/schema-modeling.html#enums" | |
:db/valueType :db.type/keyword | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :post/status+published-at | |
:db/valueType :db.type/tuple | |
:db/tupleAttrs [:post/status :post/published-at] | |
:db/cardinality :db.cardinality/one | |
:db/index true}]) | |
@(d/transact conn [{:post/uuid #uuid "00000000-0000-0000-0000-000000000001" | |
:post/status :published | |
:post/published-at #inst "2024-11-30T21:00:01+04:00"} | |
{:post/uuid #uuid "00000000-0000-0000-0000-000000000002" | |
:post/status :published | |
:post/published-at #inst "2024-11-30T21:00:02+04:00"} | |
{:post/uuid #uuid "00000000-0000-0000-0000-000000000003" | |
:post/status :draft | |
:post/published-at #inst "2024-11-30T21:00:03+04:00"}]) | |
(d/index-pull (d/db conn) | |
{:index :avet | |
:selector '[:post/uuid] | |
:start [:post/status+published-at | |
[:published #inst "2024-11-30T21:00:00+04:00"]]}) | |
;; => (#:post{:uuid #uuid "00000000-0000-0000-0000-000000000001"} | |
;; #:post{:uuid #uuid "00000000-0000-0000-0000-000000000002"}) | |
,,,) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment