-
-
Save Jaretbinford/e570d7e9b4a5076e88eea43f208f5943 to your computer and use it in GitHub Desktop.
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
;com.datomic/peer {:mvn/version "1.0.7075"} see: https://docs.datomic.com/accessing/integrating-peer-lib.html and peer docs: https://docs.datomic.com/clojure/index.html | |
(ns jaretbinford.excision | |
(:gen-class) | |
(:require [datomic.api :as d])) | |
; Start a dev transactor `bin/transactor config/samples/dev-transactor-template.properties` see: https://docs.datomic.com/setup/pro-setup.html | |
; Use backup and restore to make a dev database of the Mbrainz sample. Or transact your own schema and data on your test system. See:https://github.com/Datomic/mbrainz-sample | |
; bin/datomic restore-db file:///Users/jaret.binford/Jaret/releases/pro/backups/mbrainz-1968-1973 datomic:dev://localhost:4334/mbrainz-1968-1973 | |
(d/get-database-names "datomic:dev://localhost:4334/*" ) | |
(def db-uri "datomic:dev://localhost:4334/mbrainz-1968-1973") | |
(def conn (d/connect db-uri)) | |
(def db (d/db conn)) | |
;A pull on my John Lennon entity, 527765581346058 to see what attributes the entity has | |
(d/pull db '[*] 527765581346058) | |
;=> | |
;{:artist/sortName "Lennon, John", | |
; :artist/name "John Lennon", | |
; :artist/type #:db{:id 17592186045423}, | |
; :artist/country #:db{:id 17592186045580}, | |
; :artist/gid #uuid"4d5447d7-c61c-4120-ba1b-d7f471d385b9", | |
; :artist/startDay 9, | |
; :artist/endDay 8, | |
; :artist/startYear 1940, | |
; :artist/endMonth 12, | |
; :artist/endYear 1980, | |
; :db/id 527765581346058, | |
; :artist/startMonth 10, | |
; :artist/gender #:db{:id 17592186045420}} | |
;Excise John Lennon's attribute name from the John Lennon entity: | |
@(d/transact conn [{:db/excise 527765581346058 | |
:db.excise/attrs [:artist/name]}]) | |
;=> | |
;{:db-before datomic.db.Db, | |
; @abe6d57e :db-after, | |
; datomic.db.Db @35f69a7d, | |
; :tx-data [#datom[13194139681660 50 #inst"2024-05-25T11:54:17.594-00:00" 13194139681660 true] | |
; #datom[17592186192765 15 527765581346058 13194139681660 true] | |
; #datom[17592186192765 16 67 13194139681660 true]], | |
; :tempids {-9223300668110598143 17592186192765}} | |
; Note excision will not happen immediately: https://docs.datomic.com/operation/excision.html#how-it-works but you can track excision with https://docs.datomic.com/operation/excision.html#tracking-excisions | |
(d/q '[:find ?e | |
:in $ ?e | |
:where [_ :db/excise ?e]] | |
(d/db conn) | |
527765581346058) | |
;=> #{} | |
; After running the excision I will request index and sync: | |
(d/request-index conn) | |
;Once indexing completes and I grab a new db: | |
(d/q '[:find ?e | |
:in $ ?e | |
:where [_ :db/excise ?e]] | |
(d/db conn) | |
527765581346058) | |
;=> #{[527765581346058]} | |
;;In the logs you will see: | |
;│2024-05-25 07:54:17.614 INFO default datomic.update - {:event :update/create-index, :next-t 148350, :id "mbrainz-1968-1973-392b18a1-7301-4a88-bee1-369ae05f3a98", :phase :begin, :pid 67684, :tid 25} │ | |
;│2024-05-25 07:54:17.624 INFO default datomic.index - {:event :excise/ents, :next-t 148350, :count 1, :pid 67684, :tid 25} | |
;Your process monitor will also report: :ExciseSegments {:lo 0, :hi 1, :sum 4, :count 8} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment