Package Exports
- @sheetbase/database
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sheetbase/database) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@sheetbase/database
Using Google Sheets as a database.
Installation
Install:
npm install --save @sheetbase/databaseUsage:
// 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?)
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 /database/contentGet doc content
Request query
| Name | Type | Description |
|---|---|---|
| docId | string |
|
| style? | DocsContentStyles |
Response
object
DELETE /database
DELETE /databaseDISABLED 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
GET /databaseDISABLED 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
PATCH /databaseDISABLED 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
POST /databaseDISABLED 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
PUT /databaseDISABLED 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
License
@sheetbase/database is released under the MIT license.