【问题标题】:select's fields function of korma does not reject colums?korma 的选择字段功能不拒绝列?
【发布时间】:2015-05-24 14:22:06
【问题描述】:

我在 windows 上使用 sqlite3 数据库玩弄 clojure 及其 korma 库。我以 7web 书为例。它介绍了select* 函数及其朋友。

但是使用fields 函数会添加字段而不是限制。

;; 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\""

我错过了什么吗?

【问题讨论】:

    标签: clojure sqlite korma sqlkorma


    【解决方案1】:

    就像问题#251 中提到的那样,原因是entity-fields 表达式。它定义了查询的默认字段。 fields 函数将更多字段添加到默认值。按设计工作。

    因此我在defentity 中删除了entity-fields

    ;; 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\""
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多