Search code examples
scaladatomicdatomisca

Determining if an attribute exists in Datomic (Datomisca)


I am trying to find an efficient way to determine if a Datomic attribute is already defined in a database.

I am using the Scala wrapper Datomisca. Here is the best way that I have found so far:

val exists =
  Datomic.q(Query("""
    [:find ?attr
     :in $
     :where [_ :db.install/attribute ?i]
            [?i :db/ident ?part]
    ]"""), Datomic.database).map {
      case DKeyword(keyword) => keyword.toString
    }.contains(":some/attribute")

but I guessing that there is a better way.

I'm running Datomic-pro 0.9.4755 with Datomisca 0.6.


Solution

  • I think you're looking for datomisca.SchemaManager.hasAttribute(...): https://github.com/pellucidanalytics/datomisca/blob/develop/core/src/main/scala/datomisca/schemaManagement.scala