Class Documentation
This class represents the entire Database object
It act as the main gateway to interact with the tables and table entries in the Database.
new SheetDatabase(sheetId);
| Param | Type | Description |
|---|---|---|
sheetId |
string | Document ID for the Google Sheet Document |
Once initialized the Database with a Google Sheet, call db.sync() to actually connect with the Google Sheet Document and fetch the data in memory. Once the data has been loaded the following readonly properties can then be accessed.
| Property | Type | Description |
|---|---|---|
sheetId |
string | Sheet ID of the Google Sheet unique id for sheet, not editable |
title |
string | Title of the Google Sheet |
tables |
Record<string, Table> | Tables of database, keyed by their title |
tablesByIndex |
Array.<Table> | Array of tables, ordered by their index The index is the position of individual sheet in the Document |
Set API-key to use for auth - only allows read-only access to public docs.
| Param | Type | Required | Description |
|---|---|---|---|
key |
string | ✅ | API key for your google project |
- ✨ Side effects - all requests will now authenticate using this api key only
See Getting Started > Authentication > API Key for more details
Initialize JWT-style auth for google service account
| Param | Type | Required | Description |
|---|---|---|---|
creds |
Object | ✅ | Object containing credendtials from google for your service account usually just require the json file google gives you |
creds.client_email |
String |
✅ | The email of your service account |
creds.private_key |
String | ✅ | The private key for your service account |
- ✨ Side effects - all requests will now authenticate using these credentials
See Getting Started > Authentication > Service Account for more details
Use Google's OAuth2Client to authenticate on behalf of a user
| Param | Type | Required | Description |
|---|---|---|---|
oAuth2Client |
OAuth2Client | ✅ | Configured OAuth2Client |
- ✨ Side effects - requests will use oauth access token to authenticate requests. New access token will be generated if token is expired.
See Getting Started > Authentication > OAuth Login for more details
Set access token to use for auth
| Param | Type | Required | Description |
|---|---|---|---|
token |
string | ✅ | Oauth token to use |
- ✨ Side effects - all requests will now authenticate using this OAuth Token
!> This assumes you are creating and managing/refreshing the token yourself.
See Getting Started > Authentication > Access Token for more details
Loads all the tables and its entries into memory
| Param | Type | Required | Description |
|---|---|---|---|
syncTableEntries |
boolean | - | Whether to also load the entries of tables default = true |
- ✨ Side effects - all tables and their headers are fetched.
returns the table with the given table name
| Param | Type | Required | Description |
|---|---|---|---|
tableName |
string | ✅ | name of the table |
- ↩️ Returns - Table in database with the given name
!> If no table with given table name if found it throws an error
adds a table to database (by adding a new sheet to the Document)
| Param | Type | Required | Description |
|---|---|---|---|
tableName |
string | ✅ | name of the added table |
columnNames |
Array.< string > | ✅ | list of column names in the new table |
- ↩️ Returns - Promise.<Table> (reference to the added table)
- ✨ Side effects - table is accessible via (
db.tablesByIndex,db.tables,db.getTable())
drop the table with the given name
| Param | Type | Required | Description |
|---|---|---|---|
tableName |
string | ✅ | name of the table to delete |
- ✨ Side effects - table is no longer accessible via (
db.tablesByIndex,db.tables,db.getTable())
!> If no table with given table name if found it throws an error
rename the table with the given name
| Param | Type | Required | Description |
|---|---|---|---|
tableName |
string | ✅ | name of the table to rename |
newTableName |
string | ✅ | new name of the table |
- ✨ Side effects - table is no longer accessible via its old name.
!> If no table with given table name if found it throws an error