datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
Michael Lan 2021-04-06T18:51:13.187100Z

is there a way to print the schema of a database?

Joe Lane 2021-04-06T18:54:22.188100Z

@michaellan202 Check out https://github.com/cognitect-labs/day-of-datomic-cloud/blob/master/tutorial/schema_queries.clj, print whatever you want 🙂

ghadi 2021-04-06T18:54:43.188700Z

@michaellan202 since schema is still plain data within datomic, you can query for it and print it (using same schema attributes that you use to define it)

Michael Lan 2021-04-06T18:55:14.189400Z

Yea, this was the bit that confused me. So schema is just defined with datoms?

Joe Lane 2021-04-06T18:55:40.189700Z

Yup

Michael Lan 2021-04-06T18:55:47.189900Z

Thank you both!

ghadi 2021-04-06T18:57:00.191Z

[?n :db/ident ?ident] ^ give me all the named entities in the database

ghadi 2021-04-06T18:57:20.191400Z

then you can pull out their :db/valueType or :db/cardinality

👍 1
Michael Lan 2021-04-06T19:02:22.192400Z

There seems to be a lot of duplicates? I vaguely remember from a video how to remove duplicates by putting the output into a set but I can’t recall how to do it. Any tips?

Joe Lane 2021-04-06T19:03:01.192800Z

(into #{} cat (d/q my-query db))

Michael Lan 2021-04-06T19:04:22.193500Z

Thanks. It turns out there weren’t any duplicates, just a very weird schema. I’m looking at the mbrainz-subset sample dataset right now 😁

Joe Lane 2021-04-06T19:05:22.193900Z

Why do you think that a weird schema? Weird compared to what?

Michael Lan 2021-04-06T19:26:47.194600Z

There are a lot of :language/<3 random letter> idents, here is a snippet of the output:

#{:language/mmz :language/thq :language/mdc :language/cno :language/tdk
  :language/orr :country/CX :language/nxu :medium.format/dvd
  :language/xku :country/MV :language/bil :language/wri :language/zoo
  :language/bdu :language/tuc :language/mlh :language/anf :language/kdi
  :language/ahi :language/mec :language/kxd :language/bau :country/GG
  :language/osa :release/script :language/nki :language/acw
  :language/hmi :country/SN :language/lcp :language/ces :language/rej
  :medium.format/vinyl :language/cog :language/bfi :language/sfs
  :language/brz :language/dae :label/type :language/zuh :language/phw
  :language/uam :language/lbu :language/tak :language/bmd :language/chz
  :language/jia :language/pic :language/nfa :language/jel :language/gic
  :language/kzr :language/yiy :language/lmh :language/ktq :language/trh
  :language/hix :language/krl :medium.format/cassette :language/ntj
  :language/kvm :language/sld :language/apl :language/guo :script/Lisu
  :language/bfx :language/bcl :language/duv :language/pcj :language/bjr
  :language/oaa :language/mbi :country/BQ :language/etr :language/tsd

2021-04-06T21:08:13.196700Z

It’s pretty common to define enumerable values as idents. Allows you to refer to them with keywords (that check whether the ident exists!) instead of something like ordinal values. In your particular example, these idents appear to be ISO 639-2 language codes 🙂. https://docs.datomic.com/cloud/best.html#idents-for-enumerated-types

👍 1
Michael Lan 2021-04-06T22:35:22.198300Z

What does Only find-rel elements are allowed in client :find mean? I am trying to do:

(d/q '[:find [?month ...]
         :where [_ :release/month ?month]]
       db)
and the ... is causing this error

favila 2021-04-06T22:44:10.199300Z

That syntax is only supported on on-prem peer api

Michael Lan 2021-04-06T22:51:59.201Z

that’s odd. thanks