Closed andrusieczko closed 8 years ago
Sorry for taking so long time to respond.
You can also use with-db
to set the database connection when you execute the query. I would recommend setting database connection to entity only if it really is entity specific i.e. different entities live in different databases.
Korma is very macro heavy due to historical reasons. I checked your branch and it looks fine (if you provide a PR with tests I’ll merge it) but in the end of the day it just solves one problem with the entity system that wasn’t really designed to be used like you do.
Hey,
I'm truly sorry for not responding for such a long time.
After digging more into your code, I agree with you that the initial design is totally different from what I wanted to achieve. Writing tests would be a huge challenge with the current state of the codebase and the added value for the community would be probably not worth it.
Moreover, that would be a very hacky solution, I don't want to contribute in that way :)
Thank you for taking time in trying to understand my problem and I'm sorry for not taking action for a long time.
All the best, Karol
Hey,
I don't want to use
defentity
macros because I want to have a possibility of setting up the database connection later on, no to have a global state as I'm using Stuart Sierra's reloaded workflow (http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded).Anyway, it all works fine until you use
many-to-many
relationship. I set up two repositories where you can see what my problem is:Basically, if you want to achieve this:
without using macros, you'd probably do sth like this:
The problem here is that as
rel
function uses reflection to resolve the variables later on during the runtime, you'll get the error "Unable to resolve var: roles-entity in this context".Even if you use
many-to-many-fn
:then you'll also get an error because
many-to-many-fn
function expects a variable to passed.The change I'd love to see is that I could pass the subentity as a
map
generated bycreate-entity
function. With the changes I proposed in this branch, you are able to usemany-to-many-fn
in this example.Unfortunately you are not able to do the two-way relationships with this approach. The only one solution that comes to my mind would be to split the definitions from creations, so the user would first
create-entity
and thenbuild-entities
.Now it is resolved by the deferred variables resolution which is done using reflection that I cannot use.
Thanks to the approach with
build
step, the whole workflow would be much easier to understand and of course it would give more flexibility.I hope everything what I've written is clear.
Thanks for your enormous effort in this project, Karol
P.S. I just realized I could use
assoc-db-to-entity
to pass thedb-spec
later on. I still have to usedefentity
but at least the connection details are defined later on. Nonetheless, if I were to read the entities definitions from some text file, I'd still need a way without macros.