-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't generate schema of a composite spec #10
Comments
We have also thought that this would be a useful feature. The way you implemented this feature in #11 is by including a separate function (spectomic/datomic-schema [(with-map-keys ::user)])
=> [{:db/ident :entity/id
:db/valueType :db.type/uuid
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity
:db/index true}
{:db/ident :user/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :user/favorite-foods
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many}
{:db/ident :user/orders
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}] I think the A possible implementation here is to continue generating values for the map spec, taking the keys off that map and storing them in a set. We'd then continue doing this until that set stops changing or N number of iterations was hit. If N iterations was hit and the set of keys was still changing then we throw an exception. Alternatively, the |
My |
Your function correctly uses Yes, the function needs to be renamed. composite-spec is not a universally recognized term. I'd vote for |
Thanks for the clarification. But I still did not understand the case for using generators. Is it because if there are multiple levels of compositions in a spec i.e. if |
Link to code I've been using to extract map keys for composite specs: https://github.com/Provisdom/maali/blob/master/src/provisdom/maali/rules.cljc#L73 |
@kennyjwilli Instead of using the generator approach, I walked through the form/description of the composite spec and basically merged all the optional keys of a component spec into the required keys, regenerated the entire composite spec and generated a sample record for it. After that I just took out all the keys from that sample record and fed it into the |
@sparkofreason So sorry, just saw your code. Looks like You and me are following the same approach. |
The Take a look at @sparkofreason's code. We need a function that takes a map Spec and returns all keys (optional and required) for that Spec. That result can be passed to the A note on coding style: You use an |
@kennyjwilli Will be omitting the atom to make the code more idiomatic. |
@kennyjwilli Please take a look at #14 for the updated code. |
Currently, if a spec if defined using
s/merge
ors/keys
i.e. a composite spec, generating datomic schema out of it usingspectomic.core/datomic-schema
does not generate schema for all the individual specs it is made of.If this is implemented, it will alleviate the pain of individually populating the spec vector to be fed to the
spectomic.core/datomic-schema
function.Overriding of the individual specs' schemas should still be possible.
The text was updated successfully, but these errors were encountered: