dbaas
Version:
Database as a service. Expose db to REST and GraphQL.
99 lines (71 loc) • 2.14 kB
Markdown
> Database as a service. Expose db to REST and GraphQL.
Provide wrapper, tooling and configuration to ease Node.js development with auto generated API for database and highly customizable extensions.
Simply create table and column to generate the API and add custom extension whenever required.
- Common configuration like tsconfig, gulpfile and eslintrc
- Fully TypeScript support for custom extensions
- Auto restart for every file save
- Graceful shutdown and close database connection
```sh
npm i -S dbaas
yarn add dbaas
```
```ts
interface Post {
id: number
title: string
content: string
}
declare module "dbaas" {
interface Models {
posts: Post
// add all models here
}
}
```
```ts
import { RegisterEndpoint } from "dbaas"
const registerEndpoint: RegisterEndpoint = (router, ctx) => {
/** GET /post/ */
router.get("/", (_, res) => {
res.send("ok")
})
}
export default registerEndpoint
```
```ts
import { RegisterHook } from "dbaas"
const registerHook: RegisterHook = function ({ filter, action }, ctx) {
// The `posts` string below is type checked so no mistake and better suggestions
filter("posts.items.update", async (input) => {
// prevent from update fields when status changed to review
return input
})
action("posts.items.update", async (input) => {
// or capture dateApproved when status change to approved
})
}
export default registerHook
```
```js
const defaultGulpFile = require("./node_modules/dbaas/dist/gulpfile.js")
module.exports = {
...defaultGulpFile,
}
```
Then simply run like this `yarn gulp start`
Create table and column from database first. All REST and GraphQL API auto generated from the table and column.
Follow the example.env and create .env that will be loaded by `dotenv` to connect to the database.
- Custom workflow for hooks and automation