Question

With Datomic, I am confused as to how to get a local database to play around with

If I type:

>>(ns datomic-tut (:use [datomic.api :as d]))
nil

>>(d/create-database "datomic:mem://hello")
true

>> (d/connect "datomic:mem://hello")
#<LocalConnection datomic.peer.LocalConnection@57102fab>

>> Ctrl-D to Disconnect

Then, if I restart the repl:

>> (ns project-ns   (:use [datomic.api :as d]))
nil

>> (d/connect "datomic:mem://hello")
ExceptionInfo :peer/db-not-found Could not find hello in catalog  clojure.core/ex-info (core.clj:4227)

Is there another type of local uri I can create that saves the database that I create?

Was it helpful?

Solution

The getting started guide talks about using free storage protocol

Running the transactor with the free storage protocol

The free storage protocol uses local disk files for storage.

You can start a local transactor with free storage as follows:

bin/transactor config/samples/free-transactor-template.properties

This script will print a few lines of output, including the base URI you will use to connect, e.g.

datomic:free://localhost:4334/<DB-NAME>

To create a connection string, simply replace with a database name of your choice, e.g. "hello":

datomic:free://localhost:4334/hello

Using this URI, you should now be able to repeat the steps from the previous section, this time making your connection to the transactor.

OTHER TIPS

As of 2020, while datomic free does still exist, it lags a bit in features. Cognitect introduced a new Pro Starter edition which they intend as a better way to get started. That is also free and gives a perpetual license. The limitation is just on the duration of free updates you get, limited to one year.

Here's the latest install guide: https://docs.datomic.com/on-prem/dev-setup.html

If you only want to try it out though, you're probably better off using in-memory first: https://docs.datomic.com/on-prem/getting-started/connect-to-a-database.html

Note also datomic cloud is an even newer product. But even if considering cloud, exploring on-prem first seems not unreasonable. If so just be aware though to focus on learning the client api, rather than the peer, because peers don't exist in datomic cloud (actually, they do, as the peer server... which is what the light weight clients then connect to, to run queries).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top