Commits

Anonymous committed c11189d

fix api to suppress leading space while merging top-level clause keys (SELECT, INSERT etc)

Comments (0)

Files changed (3)

src/main/clj/org/bituf/sqlrat/clause.clj

             >> [\"WHERE id=?\" 45]
    Example: (merge-key-clause :group-by (cscols [:qty :cost]))
             >> [\"GROUP BY qty, cost\"]"
-  [^Keyword k ^Vector clause]
-  (if (empty-clause? clause) (empty-clause)
-    (merge-clauses (str-clause-key k) clause)))
+  ([^Keyword k ^Vector clause]
+    (merge-key-clause k false clause))
+  ([^Keyword k ^Boolean toplevel-key ^Vector clause]
+    (if (empty-clause? clause) (empty-clause)
+      (merge-clauses (str-clause-key k (if toplevel-key nil \ ))
+        clause))))
 
 
 ;; short hand functions for merging clauses

src/main/clj/org/bituf/sqlrat/clause/internal.clj

 (ns org.bituf.sqlrat.clause.internal)
 
 
+;; ======== Clause meta data ========
+
+(def clause-key :sqlrat-sql-clause?)
+
+
+(def clause-meta {clause-key true})
+
+
+(defn assoc-clause-meta "Add clause meta data to specified object"
+  [obj]
+  (with-meta obj (merge (meta obj) clause-meta)))
+
+
 ;; ======== Keyword to String conversion ========
 
 (defn str-col
    :where becomes \" WHERE \"
    :group-by becomes \" GROUP BY \"
    and so on."
-  [^Keyword clause-key]
+  [^Keyword clause-key key-prefix]
   (assert (keyword? clause-key))
   (.toUpperCase
     (.replace
-      (str \  (name clause-key) \  )
+      (str key-prefix
+        (name clause-key) \  )
       \- \  )))
-
-
-;; ======== Clause metadata ========
-
-(def clause-key :sqlrat-sql-clause?)
-
-
-(def clause-meta {clause-key true})
-
-
-(defn assoc-clause-meta "Add clause meta data to specified object"
-  [obj]
-  (with-meta obj (merge (meta obj) clause-meta)))

src/main/clj/org/bituf/sqlrat/entity.clj

         other-clause   (as-clause other)
         from-str       (name (:name entity-meta))
         sql-vector (merge-clauses
-                     (merge-key-clause :select   (cscols cols))
-                     (merge-key-clause :from     (as-clause from-str))
-                     (merge-key-clause :where    where-clause)
-                     (merge-key-clause :group-by (cscols groupby))
+                     (merge-key-clause :select true (cscols cols))
+                     (merge-key-clause :from        (as-clause from-str))
+                     (merge-key-clause :where       where-clause)
+                     (merge-key-clause :group-by    (cscols groupby))
                      other-clause)
         ]
     (find-by-sql entity-meta sql-vector)))