Question

I am developing a webapp which makes use of datomic. Like every webapp I do have a user management which I want to provide as a separate module/library.

Now my Idea is to have a basic user schema with an email, password and an enabled flag. Then, every library that uses my user library would add additional domain specific user attributes.

So I would have two schemas like this:

 {:db/id #db/id [:db.part/db],
          :db/ident :friendui
          :db.install/_partition :db.part/db
          :db/doc "The partition of the database for releases"}
  {:db/id #db/id [:db.part/db]
          :db/ident :friendui/id
          :db/valueType :db.type/uuid
          :db/cardinality :db.cardinality/one
          :db/unique :db.unique/identity
          :db.install/_attribute :db.part/db
          :db/doc "A unique identifier for any element"}
  ;; users
  {:db/id #db/id [:db.part/db]
          :db/ident :user/email
          :db/index true
          :db/unique :db.unique/identity
          :db/valueType :db.type/string
          :db/cardinality :db.cardinality/one
          :db.install/_attribute :db.part/db}
]...

And the lib that uses the user library like this:

  {:db/id #db/id [:db.part/db],
          :db/ident :lweb
          :db.install/_partition :db.part/db
          :db/doc "The partition of the database for releases"}
  {:db/id #db/id [:db.part/db]
          :db/ident :lweb/id
          :db/valueType :db.type/uuid
          :db/cardinality :db.cardinality/one
          :db/unique :db.unique/identity
          :db.install/_attribute :db.part/db
          :db/doc "A unique identifier for any element"}


  ;; users
  {:db/id #db/id [:db.part/db]
          :db/ident :user/attr1
          :db/index false
          :db/valueType :db.type/string
          :db/cardinality :db.cardinality/one
          :db.install/_attribute :db.part/db}

....

Now the problem that I see is that I have two different partitions which should be merged into on. Is there a way to solve that with datomic?

Update The more I think about it, the more I guess that i just have to define the schema within the using library and declare what the user library needs in the schema.

Was it helpful?

Solution

Design wise, I think the proper approach is for your library to be schema-agnostic.

If what you're building is a library, schema shouldn't be defined in there.

Alternatives for me are:

  • Your library delegates db actions using multimethods implemented in your application.
  • Your library receives database and field mapping on some initialization function.

The second approach just maps schema fields to known library keywords such as :email and :friendui.

First approach is even datomic agnostic.

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