Yuppiechef / macaron

A way to declaratively describe your database model and get going without much fuss.
3 stars 0 forks source link

Create convenience query function for simple listings #4

Closed CmdrDats closed 8 years ago

CmdrDats commented 12 years ago
(list-user-by :firstname ["John" "Mary"])

should be equivalent (in result, don't have to create an actual named query) to running a named query:

(defentity user
  (fields
    [firstname :varchar])
  (queries
    :list-queries "SELECT * FROM user WHERE firstname IN (:names)"))

(list-user-query :list-queries {:names ["John" "Mary"]})

It should support multiple columns:

(list-user-by :firstname ["John" "Mary"] :group_id [1 2 3 4] :member "admin")

should run the query "SELECT * FROM user WHERE firstname in (?,?) AND group-id IN (?,?,?,?) AND member=?"

Notice the handling of collections - passing a collection should make it an 'in', but passing a single value should make it an =.

This will lead to the creation of more specific named queries, such as reports and joins instead of a lot of utility listing queries, at the tradeoff of not having visibility on all the queries used in the system in one place.

CmdrDats commented 11 years ago

A note on this - Start off by creating a simple function to call for any entity before generating the one in the defentityrecord macro:

(list-entity-by :user :firstname ["John" "Mary"])
crisptrutski commented 8 years ago

Done