How to list avaliable databases in datomic, using the datomic Clojure REPL CLI interface

Viewed 198

Hello I'n new to datomic database, I have a existing datamic connection with 2x datomic databases.

I used info from https://docs.datomic.com/cloud/tutorial/client.html#prerequisites

Now I have to hardcode the db-names to create a backup. But how do I query datomic for the existing names of the databases? I have searched for the documentation on the datomic site but could not figure out how to list the availible db names. For example creating database is like this

starting the repl

$ ./bin/repl

then connecting and defining a database like this

user=> (require '[datomic.api :as d])

now create first database

user=> (def db-uri "datomic:sql://firstDatabase?jdbc:postgresql://datomic-postgresql:5432/datomic?user=datomic&password=****")
user=> (d/create-database db-uri)

second database

user=> (def db-uri2 "datomic:sql://secondDatabase?jdbc:postgresql://datomic-postgresql:5432/datomic?user=datomic&password=****")
user=> (d/create-database db-uri2)

Later on, I want to list my database names without wanting to know the originals, what api call can I use? I cannot find any api similar to:

user=> (d/list-database) ....?

Maybe it is not possible using the repl api? are there any workarounds?

1 Answers

Thanks to this answer:

https://forum.datomic.com/t/simplest-way-to-get-all-database-names/404/2

I have found a api call called get-database-names, which will show all the created databases, * must be used where the name would be:

(get-database-names uri)

user=>   (d/get-database-names "datomic:sql://*?jdbc:postgresql://datomic-postgresql:5432/datomic?user=datomic&password=XXXX")
2020-06-08 15:06:49.047 INFO  default    datomic.kv-cluster - {:event :kv-cluster/get-pod, :pod-key "pod-catalog", :phase :begin, :pid 271, :tid 11}
2020-06-08 15:06:49.049 INFO  default    datomic.kv-cluster - {:event :kv-cluster/get-pod, :pod-key "pod-catalog", :msec 1.14, :phase :end, :pid 271, :tid 11}
("mydatabase1" "mydatabase2")
Related