|
28 | 28 |
|
29 | 29 | (defn- list-columns [data]
|
30 | 30 | (if (map? data)
|
31 |
| - (map name (keys data)) |
| 31 | + (str " (" (string/join ", " (map name (keys data))) ") ") |
32 | 32 | (recur (first data))))
|
33 | 33 |
|
34 | 34 | (defn- list-params [start end]
|
35 |
| - (for [i (range start end)] (str "$" i))) |
| 35 | + (str "(" (string/join ", " (for [i (range start end)] |
| 36 | + (str "$" i))) |
| 37 | + ")")) |
36 | 38 |
|
37 | 39 | (defn- list-params-seq [datas]
|
38 | 40 | (if (map? datas)
|
|
41 | 43 | max (inc (* (count datas) size))]
|
42 | 44 | (string/join ", " (map
|
43 | 45 | #(str "(" (string/join ", " %) ")")
|
44 |
| - (partition size (list-params 1 max))))))) |
| 46 | + (partition size (for [i (range 1 max)] |
| 47 | + (str "$" i)))))))) |
45 | 48 |
|
46 |
| -(defn create-insert-sql [{:keys [table returning]} datas] |
47 |
| - (str "INSERT INTO " table " (" |
48 |
| - (string/join ", " (list-columns datas)) |
49 |
| - ") VALUES " |
50 |
| - (list-params-seq datas) |
| 49 | +(defn create-insert-sql [{:keys [table returning]} data] |
| 50 | + (str "INSERT INTO " table |
| 51 | + (list-columns data) |
| 52 | + " VALUES " |
| 53 | + (list-params-seq data) |
51 | 54 | (when returning
|
52 | 55 | (str " RETURNING " returning))))
|
53 | 56 |
|
54 | 57 | (defn create-update-sql [{:keys [table returning where]} data]
|
55 | 58 | (str "UPDATE " table
|
56 |
| - " SET (" |
57 |
| - (string/join "," (list-columns data)) |
58 |
| - ")=(" |
59 |
| - (string/join "," (list-params (count where) (+ (count where) (count data)))) |
60 |
| - ") WHERE " (first where) |
| 59 | + "
5E65
SET " |
| 60 | + (list-columns data) |
| 61 | + " = " |
| 62 | + (list-params (count where) (+ (count where) (count data))) |
| 63 | + " WHERE " (first where) |
61 | 64 | (when returning
|
62 | 65 | (str " RETURNING " returning))))
|
63 | 66 |
|
|
0 commit comments