clojuresqlitekormasqlkorma

select's fields function of korma does not reject colums?


I play around with clojure and its korma library using an sqlite3 database on windows. I follow an example of the 7web book. It introduces the select* function and its friends.

But using the fields function adds fields instead of restricting.

;; models.clj
(defentity issue
  (entity-fields :id :project_id :title :description :status)
  (has-many comment))

;; repl
test=> (-> (select* issue)
  #_=>     (fields :title)
  #_=>     (as-sql))
"SELECT \"issue\".\"id\", \"issue\".\"project_id\", \"issue\".\"title\", \"issue\".\"description\", \"issue\".\"status\", \"issue\".\"title\" FROM \"issue\""

Did i miss anything?


Solution

  • Like mentioned in issue #251 the reason is the entity-fields expression. It defines the default fields for queries. The fields function adds more fields to the defaults. Works as designed.

    Therefore I removed entity-fields within defentity.

    ;; models.clj
    (defentity issue
      (has-many comment))
    
    ;; repl
    test=> (-> (select* issue)
      #_=>     (fields :title)
      #_=>     (as-sql))
    "SELECT \"issue\".\"title\" FROM \"issue\""
    test=> (-> (select* issue)
      #_=>     (as-sql))
    "SELECT \"issue\".* FROM \"issue\""