Backend

wavebinder-autodb-back

Node.js backend that generates CRUD endpoints from JSON configuration to expose database tables via API.

What it is for

  • Expose DB tables without writing route handlers one by one.
  • Manage read/write behavior through configuration files.
  • Provide a quick backend to integrate in WaveBinder projects.

Official repository

GitHub: wavebinder/wavebinder-autodb-back

1) Installation

Show example
npm install /path/to/wavebinder-autodb-back-0.0.2.tgz

2) Configure JSON file

Before startup, prepare config.json: it defines port, DB connection, exposed tables, read/write policy, and security options.

Backend reads file from CONFIG_PATH (default: ./config.json).

Basic example

Show example
{
  "useApiKey": "NO",
  "apiKey": "nothing",
  "port": 3001,
  "defaultLimit": 100,
  "databases": [
    {
      "name": "main",
      "client": "sqlite3",
      "connection": { "filename": "./restaurant.sqlite" },
      "useNullAsDefault": true,
      "schemas": [
        {
          "name": "main",
          "tables": [
            {
              "name": "restaurants",
              "primaryKey": "id",
              "readOnly": false
            }
          ]
        }
      ]
    }
  ]
}

Field policies

  • readOnly: if false it allows write/read, otherwise it blocks writes (defaults to false).

Example without write access

Show example
{
  "name": "restaurants",
  "primaryKey": "id",
  "readOnly": true
}

3) Start backend

Show example
# PowerShell
$env:CONFIG_PATH = ".\\config.json"
npx wavebinder-autodb-back
Alternatively, if you are running backend project directly: npm start

4) Generated endpoints

Each entry in schemas[].tables[] generates CRUD endpoints under /api/{schema}/{table}.

Exposed endpoints depend on table readOnly value: with readOnly: true, only read operations are allowed, so only GET endpoints are visible; with readOnly: false, write endpoints are available as well.
  • GET /api/main/restaurants (filters/sort/pagination)
  • GET /api/main/restaurants/:id
  • POST /api/main/restaurants
  • PUT /api/main/restaurants/:id
  • DELETE /api/main/restaurants/:id

5) Usage inside WaveBinder project

Configure external service (example extapi.json):

Show example
{
  "target": "http://localhost:3001/api",
  "secure": false,
  "authorization": null
}

serviceName mapping (important)

The serviceName value in nodes must match the key registered in the service map passed to new WaveBinder(...).

Show example
const extApis = new Map();
extApis.set("api", EXT_API_CONFIG);

const wb = new WaveBinder(
  LICENSE,
  PROTO_NODES,
  extApis,
  customFunctions
);
  • With extApis.set("api", ...), nodes must use serviceName: "api".
  • With target: "http://localhost:3001/api" and la.addr: "/main/restaurants", final request is http://localhost:3001/api/main/restaurants.

Authentication

  • If useApiKey = "YES", backend requires x-api-key header.
  • If useApiKey = "NO", endpoints are public.