Question

Have 2 queries about datomic attributes. 1. If I know the attribute name (String), how do I check if the attribute is already defined or not in the schema? 2. Based on my experimenting with datomic, I see that datomic treats attributes with colon prefix and without colon prefix same. i.e if we create attributes named "foo" and ":foo", they are one and the same. Is this true? Is this a limitation?

I am using datomic with groovy.Below is the code used to create the attribute. Along with name, other params are input.



    static def createAttribute(String name, String type, String description, Connection connection) {
     List schema = [[
                    ':db/id': Peer.tempid(':db.part/db'),
                    ':db/ident' : name,
                    ':db/valueType': type,
                    ':db/cardinality': ':db.cardinality/one',
                    ':db/doc': description,
                    ':db.install/_attribute': ':db.part/db'
            ]]
            connection.transact(schema).get()


And the query I use to verify attribute presence is



    def attributeFor(String attributeName, Database db) {
     db.entity(attributeName).get(':db.install/_attribute')
    }


If I call "createAttribute" with "foo" as attribute name and "attributeFor" method ":foo" as attribute name, I get a result. i.e "foo" and ":foo" are treated same. How can I create and query for attributes with name that contain a colon prefix?

Was it helpful?

Solution

Datomic attribute names are not Strings, they are edn keywords. The prefix colon is required (and always stored, regardless of whether you specify it in code.) The optionality of the colon when working from languages that do not support a name literal (e.g. Java or Groovy) is intended as a convenience.

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