|
17 | 17 | (comment |
18 | 18 | (escape "hey \"you\"!" "\"")) |
19 | 19 |
|
20 | | -(defn- create-table [db headers table] |
| 20 | +(defn- create-table [db headers table is-mysql] |
21 | 21 | (log/info "Creating table") |
22 | 22 | (let [cols (->> headers |
23 | 23 | (map #(str % " text")) |
24 | 24 | (string/join ", ")) |
25 | | - s (str "create table " table " ( " cols " )")] |
| 25 | + s (str "create table " table " ( " cols " )" (when is-mysql " character set=utf8mb4"))] |
26 | 26 | (jdbc/execute! db s))) |
27 | 27 |
|
28 | 28 | (defn- get-headers-or-drop |
|
85 | 85 | (log/info "Writing" (count rows) "rows to table") |
86 | 86 | (jdbc/insert-multi! db table headers rows)) |
87 | 87 |
|
| 88 | +(defn- get-db-config [config target] |
| 89 | + (let [db (get-in config [:targets (keyword target)]) |
| 90 | + dbtype (keyword (:dbtype db))] |
| 91 | + (if (= dbtype :mysql) |
| 92 | + (merge {"useUnicode" "yes" |
| 93 | + "characterEncoding" "UTF-8"} |
| 94 | + db) |
| 95 | + db))) |
| 96 | + |
88 | 97 | (defn update-table [config sheet] |
89 | 98 | (let [target (-> sheet :sheet :target) |
90 | | - db (get-in config [:targets (keyword target)]) |
91 | | - identifier-quoting (identifier-quoting-map (keyword (:dbtype db))) |
| 99 | + db (get-db-config config target) |
| 100 | + dbtype (keyword (:dbtype db)) |
| 101 | + identifier-quoting (identifier-quoting-map dbtype) |
92 | 102 | table (-> sheet :sheet :table) |
93 | 103 | rows (:rows sheet) |
94 | 104 | headers (->> rows |
|
106 | 116 | (do |
107 | 117 | (check-header-conflicts headers old-headers) |
108 | 118 | (clear-table db table)) |
109 | | - (create-table db escaped-headers table)) |
| 119 | + (create-table db escaped-headers table (= dbtype :mysql))) |
110 | 120 | (write-rows db table escaped-headers data) |
111 | 121 | (catch Exception e (throw-db-err target table e)))) |
112 | 122 | sheet) |
0 commit comments