Detasheet: Google Sheets as a Database

Have you ever considered using Google Sheets as a database? You haven’t? Well you just did!

The Why

Google Sheets is free, provides a built-in method to visualize data (with charts and graphs), and allows you to export data in a variety of…


This content originally appeared on DEV Community and was authored by Nathan Pham

Have you ever considered using Google Sheets as a database? You haven't? Well you just did!

The Why

Google Sheets is free, provides a built-in method to visualize data (with charts and graphs), and allows you to export data in a variety of formats.

Obviously, Google Sheets was never intended to be a database. The API is verbose and would be difficult to reuse across new projects.

As a result, I created Detasheet! Detasheet is a wrapper around the official Google Sheets API, allowing you to intuitively create and manage databases.

The documentation is available on Github (give it a star!) or NPM.

It Works!

image
image

Lessons Learned

OAuth is an absolute nightmare to deal with. It also doesn't make much sense to request a refresh token when initializing and interacting with the database should be relatively permanent. I opted to create a service account instead, using a private key and client email to authenticate my Google Sheets client.

After creating the service client, I realized I could read spreadsheets but not write to them. I found out that you could actually share your documents to the service account, which enabled realtime editing.

image

Internally, I tried to use some bleeding-edge object-oriented JavaScript (Node v14+), like real private methods.

class Client {
  async #authorize(credentials) {
    return new Promise((resolve) => { resolve(credentials) })
  }
}

const client = new Client()
client.#authorize() // won't work!

I've also had experience publishing modules to NPM before, so it wasn't that difficult (literally just npm publish --access public).

Conclusion

Detasheets was definitely an interesting and fun experiment. If you actually build something with it, let me know!


This content originally appeared on DEV Community and was authored by Nathan Pham


Print Share Comment Cite Upload Translate Updates
APA

Nathan Pham | Sciencx (2021-10-05T18:01:54+00:00) Detasheet: Google Sheets as a Database. Retrieved from https://www.scien.cx/2021/10/05/detasheet-google-sheets-as-a-database/

MLA
" » Detasheet: Google Sheets as a Database." Nathan Pham | Sciencx - Tuesday October 5, 2021, https://www.scien.cx/2021/10/05/detasheet-google-sheets-as-a-database/
HARVARD
Nathan Pham | Sciencx Tuesday October 5, 2021 » Detasheet: Google Sheets as a Database., viewed ,<https://www.scien.cx/2021/10/05/detasheet-google-sheets-as-a-database/>
VANCOUVER
Nathan Pham | Sciencx - » Detasheet: Google Sheets as a Database. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/05/detasheet-google-sheets-as-a-database/
CHICAGO
" » Detasheet: Google Sheets as a Database." Nathan Pham | Sciencx - Accessed . https://www.scien.cx/2021/10/05/detasheet-google-sheets-as-a-database/
IEEE
" » Detasheet: Google Sheets as a Database." Nathan Pham | Sciencx [Online]. Available: https://www.scien.cx/2021/10/05/detasheet-google-sheets-as-a-database/. [Accessed: ]
rf:citation
» Detasheet: Google Sheets as a Database | Nathan Pham | Sciencx | https://www.scien.cx/2021/10/05/detasheet-google-sheets-as-a-database/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.