Import a Google spreadsheet into a MySQL table with docsql

There’s a lot of open-source software I’m not proud of; probably, though, nothing compares to docsql, as this rare piece of Golang qualifies as one of the weirdest of my creations.

At Namshi, we’ve been using spreadsheets as a mean of configuration for quite some time — you tell the stakeholder “hey, here’s a google doc, if you need to change one of the translations just edit the doc and wait 5 mins” and the bets are down.

Sometimes we actually need to import this data into MySQL (could be a una-tantum import as well as a scheduled job) and we traditionally did this manually, by pulling down a .tsv export from Google docs, amending it and running something such as LOAD DATA LOCAL INFILE.

One evening, I found myself wifeless and with a strong desire to try out cobra and viper, so I started to look into automating the process of importing a spreadsheet hosted on Google Docs into a MySQL table: the result was docsql, a small piece of weird software that simply:

and turns this:

into this:

Considering this was a funny experiment to try to automate a task I do quite infrequently1, I don’t think I’m going to spend a lot more time expanding it or adding random features2, but I’m happy to share the source code as I was pleasantly surprised with how straightforward it was to build such a small, isolated CLI tool.

Notes
  1. Even if infrequent, it’s still a pain
  2. Especially considering my good old love for the Unix philosophy of “do one thing and do it well…”

In the mood for some more reading?

...or check the archives.