This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-19
Channels
- # announcements (4)
- # asami (1)
- # babashka (48)
- # beginners (84)
- # bristol-clojurians (1)
- # calva (15)
- # chlorine-clover (11)
- # cider (37)
- # clj-kondo (17)
- # clojure (72)
- # clojure-europe (13)
- # clojure-italy (43)
- # clojure-nl (6)
- # clojure-spec (8)
- # clojure-uk (19)
- # clojuredesign-podcast (7)
- # clojurescript (132)
- # code-reviews (7)
- # conjure (3)
- # cursive (24)
- # datascript (10)
- # datomic (61)
- # docker (4)
- # duct (24)
- # emacs (2)
- # figwheel-main (8)
- # fulcro (43)
- # graalvm (5)
- # juxt (1)
- # keechma (14)
- # malli (2)
- # off-topic (120)
- # re-frame (111)
- # reagent (6)
- # reitit (13)
- # shadow-cljs (118)
- # spacemacs (3)
- # tools-deps (32)
- # uncomplicate (5)
- # xtdb (6)
I have a schema with two attributes - :ent/uuid :db.unique/identity
and :ent/context :db.type/ref
- is there a way I can make this automatically create the referenced entity?
(d/transact datomic
[{:ent/context [:ent/uuid (d/squuid)]}])
(obviously this is a contrived example, the (d/squuid)
would almost always be a uuid from somewhere else)(ideally, there's a schema attribute that can set this as a property of :ent/uuid
- but I suspect I'll have to actually go lookup and create the entity if it doesn't exist?)
hmm
(d/transact datomic
[{:ent/uuid #uuid "093eaee6-ebc7-45f2-9a3f-b923f4864e5c"}
{:ent/user [:ent/uuid #uuid "093eaee6-ebc7-45f2-9a3f-b923f4864e5c"]}])
doesn't work? that's a shame - am I looking at this wrong, or do I pretty much have to resort to lookup+tempid's?if i'm reading this correctly, you want to transact an entity while also transacting a reference to that entity in the same transaction, right?
if so, then you can use temporary ids within the same transaction
(d/transact datomic
[{:ent/uuid #uuid "093eaee6-ebc7-45f2-9a3f-b923f4864e5c"
:db/id "newuser"}
{:ent/user "newuser"}])
ye, that's basically what I'm doing as a workaround (using d/tempid
) - trouble is that you have to actually have to think about it, at a higher level
where I would have preferred to just (effectively):
(->>
[(when user-not-found {:ent/uuid #uuid "093eaee6-ebc7-45f2-9a3f-b923f4864e5c"})
{:ent/user [:ent/uuid #uuid "093eaee6-ebc7-45f2-9a3f-b923f4864e5c"]}]
(remove nil?))
instead, I need to collaborate the two pieces of code to pass the temporary id around> I'm wanting to write my code for adaptive gradual backfill of existing entities with uuid's from other database i do something similar from time to time, and what i do is first transact the entities in the DB, and then in a second transaction i establish their references. you might be able to do something clever, like walk your input data and create a tempid out of the uuid (i never had to go that far)
ye, I'm trying to whittle down a simple paradigm for consistently interacting with datomic that I can then teach to the team.. save then load would work, but a bit too much of fickle
well if you ever write a generic walker/id replacer for the input code let us know! in my case i migrate slices of the datomic graph from one database to another, and over time i have just added steps for each "kind" of entity. another useful tool would be to replace UUIDs with new ones.. in other words clone parts of the graph and their relationships (within the same db).
just another thought, and i don't know if this applies to your scenario, but you can transact new entities as reference values if the reference is a component
{:tx-data [{:user/id #uuid "093eaee6-ebc7-45f2-9a3f-b923f4864e5c"
:user/address {:address/id #uuid"f0ef5f94-8125-4aa1-a906-524ec0274941"
:address/street "Maple Street"
:address/country-code "US"}}]}
that is good to know, thanks! but no, this is for the generic case, not really components
I guess I could handle a generic walker, but that would add a bunch of overhead for 99% of the code that doesn't need it + be an extra bit of complexity to keep having to think about
You can transact the whole thing as a nested map:
[{:ent/user {:ent/uid #uuid "MY_UUID_HERE"}}]
[{:ent/user {:ent/uid #uuid "MY_UUID_HERE"} :ent/ident "1"}
{:ent/user {:ent/uid #uuid "MY_UUID_HERE"} :ent/ident "2"}]
for instancecool - ye, I'll be enforcing :ent/uuid
- so that it can always gradually converge to the same entity.. I do have a few more identity
attributes, but there's a possibility of creating two rows for the same entity, then not being able to reconcile later.
(for context, I'm wanting to write my code for adaptive gradual backfill of existing entities with uuid's from other databases - as opposed to a dedicated ETL process)
Does anyone actually uses the schema type :db.type/uri
? There's some real benefit apart from semantics? Using :db.type/string
works just fine and I don't need any code to serialize/deserialize the data.
I have used it. I like that it rejects invalid uris. I also see more types as a bonus.
Oh, I didn't have that in mind. Thanks! I think I'll use :db.type/uri
because of the free type checking.
I took this :db.type/tuple
schema example from Datomicās On-Prem documentation. https://docs.datomic.com/on-prem/schema.html#heterogeneous-tuples
{:db/ident :player/location
:db/valueType :db.type/tuple
:db/tupleTypes [:db.type/long :db.type/long]
:db/cardinality :db.cardinality/one}
But I get this error when running a transact
(with com.datomic/client-pro
ā0.9.57ā ( also tried ā0.9.63" )).
Is this just a bug? Or is there something else to making tuple types work?
Caused by: datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/not-an-entity Unable to resolve entity: :db/tupleTypes
{:entity :db/tupleTypes, :db/error :db.error/not-an-entity}
Did you upgrade your base schema? https://docs.datomic.com/cloud/operation/howto.html#upgrade-base-schema
I havenāt deployed yet. This is all in development, with this version.
com.datomic/client-proĀ "0.9.57"
The db you are connecting to: was it created with a version of datomic earlier than the one that started supporting tuples?
Has anyone gotten dev-local working on windows 10? I'm having a hard time with specifying {:storage-dir "C:\\Users\user\foo"}
Execution error at datomic.dev-local.impl/user-config (impl.clj:324).
Unsupported escape character: \U
you probably need "C:\\\\Users\\user\\foo" to escape the \'s ?
@alexmiller Different error message, but still doesnt work
what's the error?
Execution error (ExceptionInfo) at datomic.core.anomalies/throw-if-anom (anomalies.clj:94).
You must specify an absolute path under :storage-dir in a map in
your ~/.datomic/dev-local.edn file, or in your call to client.
interesting, it's checking for absolute path - maybe "\\C:\\\\Users\\user\\foo" ?
sorry, that extra pair of \\ isn't needed and paths on windows starting with the drive should be considered absolute. "C:\\Users\\user\\foo" I would expect to work, but maybe I'm missing something
well, I'll invoke @jaret and @marshall to check with the Datomic team then :)