https://github.com/guerrerocarlos/db-google-spreadsheets
💻 Use Google Drive's Spreadsheets as your Database and Worksheets as your tables
https://github.com/guerrerocarlos/db-google-spreadsheets
Last synced: 4 months ago
JSON representation
💻 Use Google Drive's Spreadsheets as your Database and Worksheets as your tables
- Host: GitHub
- URL: https://github.com/guerrerocarlos/db-google-spreadsheets
- Owner: guerrerocarlos
- Created: 2019-10-20T15:49:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T10:07:45.000Z (over 2 years ago)
- Last Synced: 2025-02-09T20:39:28.366Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Google Spreadsheet as DB (db-google-spreadsheet)
Use Google Spreadsheet as DB and Worksheets as Tables:
## Setup
Create `oauth2.keys.json` file with your _Google App_ *id* and *secret* as shown in `example_oauth2.keys.json`
You may need a CLIENT_ID, CLIENT_SECRET and REDIRECT_URL. You can find these pieces of information by going to the [Developer Console](https://console.developers.google.com/), clicking `your project --> APIs & auth --> credentials`.
Then execute `quickstart.js` file to get the `oauth2.token.json` file and use the module.
## How to use
### Open the Spreadsheet
```js
var params = {
spreadsheetId: "189ubij3PIK7ujsoSXXXXr3hsZqap_4w",
worksheetName: "Users"
};
var sheet = Spreadsheet(params);
```Example Spreadsheet Data:

### Get Rows as Objects:
```js
var rows = await sheet();
console.log(rows)
```_Console output:_
```sh
[ Row { email: '[email protected]', useCount: '0' },
Row { email: '[email protected]', useCount: '0' },
Row { email: '[email protected]', useCount: '0' } ]
```### Update Data:
```js
var editRow = rows.filter((row) => row.email === '[email protected]')[0]
editRow.useCount++;
editRow.date = '20/10/2019'
editRow.save()
```Updated Spreadsheet:

Note that it automatically added the new *Date* column
### Add new Row to Spreadsheet:
```js
var newRow = sheet({
email: "[email protected]",
useCount: 19
});
await newRow.save();
```Updated Spreadsheet:

Note that it automatically added the new *Date* column
### Check Rows as Objects:
```js
var rows = await sheet();
console.log(rows)
```_Console output:_
```sh
[ Row { email: '[email protected]', useCount: '0' },
Row { email: '[email protected]', useCount: '1', date: '20/10/2019' },
Row { email: '[email protected]', useCount: '0' },
Row { email: '[email protected]', useCount: '19' } ]
```## Column Attribute Mapping
The first row is reserved for the column names, so that order of columns and row two is used for human-friendly names that can be modified without affecting the DB.

This first row can be hidden for better visualization with `right-click -> hide Row`:
