Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Commit 44aa690

Browse files
committed
Improve unicode support for MySQL
1 parent 79a2ac6 commit 44aa690

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Let users manually insert data using Google Sheets while having the power of all
1010

1111
googlesheets-sql-sync uses [JDBC](https://github.com/clojure/java.jdbc) and bundles the PostgreSQL and MySQL drivers.
1212
Additional drivers can be added any time.
13-
If you would like to add support for SQLite or any other SQL database, open an issue and it can probably be added in no time.
13+
If you also would like to have support for SQLite, open an issue and it can probably be added in no time.
1414

1515

1616
## Assumptions and simplifications

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject googlesheets-sql-sync "0.6.0"
1+
(defproject googlesheets-sql-sync "0.6.1"
22
:description "Keep your SQL database in sync with Google Sheets"
33
:url "https://github.com/jorinvo/googlesheets-sql-sync"
44
:license {:name "MIT"

src/googlesheets_sql_sync/db.clj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
(comment
1818
(escape "hey \"you\"!" "\""))
1919

20-
(defn- create-table [db headers table]
20+
(defn- create-table [db headers table is-mysql]
2121
(log/info "Creating table")
2222
(let [cols (->> headers
2323
(map #(str % " text"))
2424
(string/join ", "))
25-
s (str "create table " table " ( " cols " )")]
25+
s (str "create table " table " ( " cols " )" (when is-mysql " character set=utf8mb4"))]
2626
(jdbc/execute! db s)))
2727

2828
(defn- get-headers-or-drop
@@ -85,10 +85,20 @@
8585
(log/info "Writing" (count rows) "rows to table")
8686
(jdbc/insert-multi! db table headers rows))
8787

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+
8897
(defn update-table [config sheet]
8998
(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)
92102
table (-> sheet :sheet :table)
93103
rows (:rows sheet)
94104
headers (->> rows
@@ -106,7 +116,7 @@
106116
(do
107117
(check-header-conflicts headers old-headers)
108118
(clear-table db table))
109-
(create-table db escaped-headers table))
119+
(create-table db escaped-headers table (= dbtype :mysql)))
110120
(write-rows db table escaped-headers data)
111121
(catch Exception e (throw-db-err target table e))))
112122
sheet)

0 commit comments

Comments
 (0)