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

Commit

Permalink
Add SQLite support
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
jorinvo committed Jul 2, 2020
1 parent 44aa690 commit 4941f22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ java -jar googlesheets-sql-sync.jar --init
2. Now fill out the missing information in the config file.
1. Use your Google credentials from above.
2. Specify at least one target and one sheet using that target.
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).
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).
4. Name the `table` as you wish for it to appear in your database.
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.
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`.
Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject googlesheets-sql-sync "0.6.1"
(defproject googlesheets-sql-sync "0.7.0"
:description "Keep your SQL database in sync with Google Sheets"
:url "https://github.com/jorinvo/googlesheets-sql-sync"
:license {:name "MIT"
Expand All @@ -8,6 +8,7 @@
[org.clojure/java.jdbc "0.7.8"]
[org.postgresql/postgresql "42.2.4"]
[mysql/mysql-connector-java "8.0.18"]
[org.xerial/sqlite-jdbc "3.32.3"]
[org.clojure/tools.cli "0.3.7"]
[http-kit "2.3.0"]
[metosin/jsonista "0.2.0"]
Expand Down
18 changes: 10 additions & 8 deletions src/googlesheets_sql_sync/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

(def identifier-quoting-map
{:postgresql "\""
:sqlite "\""
:mysql "`"})

(defn- escape
Expand Down Expand Up @@ -46,11 +47,10 @@
(catch java.sql.SQLException _))))

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

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

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

(defn- write-rows [db table headers rows]
(log/info "Writing" (count rows) "rows to table")
Expand All @@ -97,8 +97,10 @@
(defn update-table [config sheet]
(let [target (-> sheet :sheet :target)
db (get-db-config config target)
dbtype (keyword (:dbtype db))
identifier-quoting (identifier-quoting-map dbtype)
a (println (:connection-uri db))
dbtype (keyword (or (:dbtype db)
(string/split (:connection-uri db) #":" 3)))
identifier-quoting (identifier-quoting-map :sqlite)
table (-> sheet :sheet :table)
rows (:rows sheet)
headers (->> rows
Expand Down

0 comments on commit 4941f22

Please sign in to comment.