diff --git a/README.md b/README.md index 9692f4a..c2f98c4 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/project.clj b/project.clj index 59a95d3..c495cc1 100644 --- a/project.clj +++ b/project.clj @@ -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" @@ -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"] diff --git a/src/googlesheets_sql_sync/db.clj b/src/googlesheets_sql_sync/db.clj index 04181b0..33fe79c 100644 --- a/src/googlesheets_sql_sync/db.clj +++ b/src/googlesheets_sql_sync/db.clj @@ -7,6 +7,7 @@ (def identifier-quoting-map {:postgresql "\"" + :sqlite "\"" :mysql "`"}) (defn- escape @@ -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))) @@ -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") @@ -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