Using Google Sheets as a database.
Installation
Install: npm install --save @sheetbase/database
Usage:
// 1. import module
import { DatabaseModule } from "@sheetbase/database";
// 2. create an instance
export class App {
  // the object
  databaseModule: DatabaseModule;
  // initiate the instance
  constructor() {
    this.databaseModule = new DatabaseModule(/* options */);
  }
}
				Options
| Name | Type | Description | 
|---|---|---|
| databaseId | string | 
								|
| keyFields? | undefined | object | 
								|
| security? | boolean | object | 
								|
| securityHelpers? | SecurityHelpers | 
								
Lib
The Lib class.
Lib properties
Lib methods
| Function | Returns type | Description | 
|---|---|---|
| registerRoutes(routeEnabling?, middlewares?) | RouterService<> | 
								Expose the module routes | 
registerRoutes(routeEnabling?, middlewares?)
Expose the module routes
Parameters
| Param | Type | Description | 
|---|---|---|
| routeEnabling | true | DisabledRoutes | 
								|
| middlewares | Middlewares | RouteMiddlewares | 
								
Returns
RouterService<>
Routing
DatabaseModule provides REST API endpoints allowing clients to access server resources. Theses enpoints are not exposed by default, to expose the endpoints:
DatabaseModule.registerRoutes(routeEnabling?);
					Errors
DatabaseModule returns these routing errors, you may use the error code to customize the message:
database/content-no-id: No doc id.database/no-input: No path/table/sheet.Routes
Routes overview
| Route | Method | Disabled | Description | 
|---|---|---|---|
| /database/content | GET | 
								Get doc content | |
| /database | DELETE | 
								true | 
								Delete an item from the database (proxy to: post /database) | 
| /database | GET | 
								true | 
								Get data from the database | 
| /database | PATCH | 
								true | 
								Update an item from the database (proxy to: post /database) | 
| /database | POST | 
								true | 
								Add/update/delete data from database | 
| /database | PUT | 
								true | 
								Add a new item do the database (proxy to: post /database) | 
Routes detail
GET /database/content
Get doc content
Request query
| Name | Type | Description | 
|---|---|---|
| docId | string | 
								|
| style? | DocsContentStyles | 
								
Response
object
DELETE /database
DISABLED Delete an item from the database (proxy to: post /database)
Request body
| Name | Type | Description | 
|---|---|---|
| path | string | 
								|
| table? | string | 
								|
| sheet? | string | 
								|
| id? | string | 
								|
| key? | string | 
								
Response
void
GET /database
DISABLED Get data from the database
Request query
| Name | Type | Description | 
|---|---|---|
| path? | string | 
								|
| table? | string | 
								|
| sheet? | string | 
								|
| id? | string | 
								|
| key? | string | 
								|
| type? | 'object'  | 
								|
| query? | string | 
								|
| segment? | string | 
								|
| order? | string | 
								|
| orderBy? | string | 
								|
| limit? | number | 
								|
| offset? | number | 
								
Response
Record<string, unknown> | unknown[]
PATCH /database
DISABLED Update an item from the database (proxy to: post /database)
Request body
| Name | Type | Description | 
|---|---|---|
| path | string | 
								|
| table? | string | 
								|
| sheet? | string | 
								|
| id? | string | 
								|
| key? | string | 
								|
| data? | unknown | 
								
Response
void
POST /database
DISABLED Add/update/delete data from database
Request body
| Name | Type | Description | 
|---|---|---|
| path | string | 
								|
| table? | string | 
								|
| sheet? | string | 
								|
| id? | string | 
								|
| key? | string | 
								|
| data? | unknown | 
								|
| increasing? | Record | 
								|
| clean? | boolean | 
								
Response
void
PUT /database
DISABLED Add a new item do the database (proxy to: post /database)
Request body
| Name | Type | Description | 
|---|---|---|
| path | string | 
								|
| table? | string | 
								|
| sheet? | string | 
								|
| id? | string | 
								|
| key? | string | 
								|
| data? | unknown | 
								
Response
void
@sheetbase/database is released under the MIT license.
Generated using TypeDoc