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

Commit 4941f22

Browse files
committed
Add SQLite support
Fixes #23
1 parent 44aa690 commit 4941f22

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ java -jar googlesheets-sql-sync.jar --init
6262
2. Now fill out the missing information in the config file.
6363
1. Use your Google credentials from above.
6464
2. Specify at least one target and one sheet using that target.
65-
3. You can find more DB options in the JDBC docs for [PostgreSQL](https://jdbc.postgresql.org/documentation/head/connect.html) or [MySQL](https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html).
65+
3. You can find more DB options in the JDBC docs for [PostgreSQL](https://jdbc.postgresql.org/documentation/head/connect.html), [MySQL](https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html) or [SQLite](https://github.com/xerial/sqlite-jdbc#how-to-specify-database-files).
6666
4. Name the `table` as you wish for it to appear in your database.
6767
5. To get a `spreadsheet_id`, open one of [your Google Sheets](https://docs.google.com/spreadsheets) and copy the part between `/d/` and `/edit` from the URL bar in your Browser.
6868
6. Specify the `range` using the `A1:Z10`. Skip the number to select all rows - like `A:ZZ`. You can also specify a _sheet_ if your spreadsheet contains multiple sheets by prefixing th range like `SomeSheet!A:ZZ`.

project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject googlesheets-sql-sync "0.6.1"
1+
(defproject googlesheets-sql-sync "0.7.0"
22
:description "Keep your SQL database in sync with Google Sheets"
33
:url "https://github.com/jorinvo/googlesheets-sql-sync"
44
:license {:name "MIT"
@@ -8,6 +8,7 @@
88
[org.clojure/java.jdbc "0.7.8"]
99
[org.postgresql/postgresql "42.2.4"]
1010
[mysql/mysql-connector-java "8.0.18"]
11+
[org.xerial/sqlite-jdbc "3.32.3"]
1112
[org.clojure/tools.cli "0.3.7"]
1213
[http-kit "2.3.0"]
1314
[metosin/jsonista "0.2.0"]

src/googlesheets_sql_sync/db.clj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
(def identifier-quoting-map
99
{:postgresql "\""
10+
:sqlite "\""
1011
:mysql "`"})
1112

1213
(defn- escape
@@ -46,11 +47,10 @@
4647
(catch java.sql.SQLException _))))
4748

4849
(comment
49-
(let [db {:dbtype "postgresql"
50-
:dbname "bi"
51-
:host "localhost"
52-
:user "bi"}]
53-
(get-headers db "hi")))
50+
(let [db {:connection-uri "jdbc:sqlite:testing-sqlite.db"}]
51+
(jdbc/execute! db "create table a (a text, b text)"
52+
{:identifiers identity
53+
:keywordize? false})))
5454

5555
(defn- throw-db-err [target table e]
5656
(fail "There was a problem with table \"" table "\" on target \"" target "\": " (.getMessage e)))
@@ -79,7 +79,7 @@
7979

8080
(defn- clear-table [db table]
8181
(log/info "Clearing table")
82-
(jdbc/execute! db (str "truncate table " table)))
82+
(jdbc/execute! db (str "delete from " table)))
8383

8484
(defn- write-rows [db table headers rows]
8585
(log/info "Writing" (count rows) "rows to table")
@@ -97,8 +97,10 @@
9797
(defn update-table [config sheet]
9898
(let [target (-> sheet :sheet :target)
9999
db (get-db-config config target)
100-
dbtype (keyword (:dbtype db))
101-
identifier-quoting (identifier-quoting-map dbtype)
100+
a (println (:connection-uri db))
101+
dbtype (keyword (or (:dbtype db)
102+
(string/split (:connection-uri db) #":" 3)))
103+
identifier-quoting (identifier-quoting-map :sqlite)
102104
table (-> sheet :sheet :table)
103105
rows (:rows sheet)
104106
headers (->> rows

0 commit comments

Comments
 (0)