I would like to be able to pass a user-defined array of fields which contains a list of all the columns that need fetching. Can korma/fields take an array of columns?
What I am essentially wanting to create is something like this:
(defn fetch [fields]
(->
(korma/select* foo)
(as-> query
(if (not-empty? fields)
(korma/fields query fields)
query))
(korma/select)))
I think your assumption is correct, and it's also possible to override this. If you look at the map generated by
(defentity foo)it has a:fieldskey with all the fields.korma.core/entity-fieldsdoesn't replace what's already there, but this will:I used variadic args in this example to mirror
korma.core/entity-fields(and madefetchreturn the SQL string for my testing rather than execute the query):