Skip to main content

API Reference

Complete reference for all auto-generated REST API endpoints and the Connector class methods.

Base Configuration

All API endpoints are mounted at /dbmanager by default.

Base URL: http://localhost:4000/dbmanager

Authentication Header:
auth: your-secret-key

System Endpoints

Health Check

GET /dbmanager/

Response:
{
  "message": "Connector API is running"
}

Ping

GET /dbmanager/ping

Response:
{
  "message": "pong"
}

Validate Secret Key

POST /dbmanager/validate

Headers:
auth: your-secret-key

Response:
{
  "valid": true
}

Get Schema

GET /dbmanager/getSchema

Headers:
auth: your-secret-key

Response:
{
  "tables": [
    {
      "name": "users",
      "customization": {
        "rename": "System Users",
        "allowCreate": true,
        "allowEdit": true,
        "allowDelete": true,
        "isVisible": true
      },
      "columns": [...],
      "indexes": [...],
      "constraints": [...]
    }
  ]
}

Table Endpoints

For each table in your database, these endpoints are automatically generated:

Get Table Columns

GET /dbmanager/{tableName}/getColumns

Headers:
auth: your-secret-key

Response:
{
  "columns": [
    {
      "name": "id",
      "type": "integer",
      "nullable": false,
      "primary_key": true
    },
    {
      "name": "email",
      "type": "varchar",
      "nullable": false
    }
  ]
}

Get Table Data (List with Pagination)

POST /dbmanager/{tableName}/getData

Headers:
auth: your-secret-key

Body:
{
  "limit": 20,              // Max 1000, default 20
  "offset": 0,              // Default 0
  "orderBy": "id",          // Column to sort by
  "orderDirection": "desc", // "asc" or "desc"
  "search": "john",         // Search string
  "searchColumns": ["name", "email"], // Columns to search
  "where": {                // Filter conditions
    "isActive": true,
    "role": "admin"
  },
  "columns": ["id", "name", "email"] // Columns to select
}

Response:
{
  "rows": [
    { "id": 1, "name": "John", "email": "john@example.com" },
    { "id": 2, "name": "Jane", "email": "jane@example.com" }
  ],
  "total": 150
}

Get Single Record

POST /dbmanager/{tableName}/getSingleData

Headers:
auth: your-secret-key

Body:
{
  "where": {
    "id": 1
  }
}

Response:
{
  "id": 1,
  "name": "John Doe",
  "email": "john@example.com",
  "created_at": "2024-01-01T00:00:00Z"
}

Create Record

POST /dbmanager/{tableName}/insert

Headers:
auth: your-secret-key

Body:
{
  "name": "John Doe",
  "email": "john@example.com",
  "age": 30
}

Response:
{
  "id": 123,
  "name": "John Doe",
  "email": "john@example.com",
  "age": 30,
  "created_at": "2024-01-01T00:00:00Z"
}

Update Records

POST /dbmanager/{tableName}/update

Headers:
auth: your-secret-key

Body:
{
  "where": {
    "id": 1
  },
  "patch": {
    "name": "Jane Doe",
    "age": 31
  }
}

Response:
{
  "rows": [
    {
      "id": 1,
      "name": "Jane Doe",
      "email": "john@example.com",
      "age": 31
    }
  ]
}

Delete Records

POST /dbmanager/{tableName}/delete

Headers:
auth: your-secret-key

Body:
{
  "where": {
    "id": 1
  },
  "single": true  // Delete only one record
}

Response:
{
  "deleted": 1
}

Execute Table Action

POST /dbmanager/{tableName}/table-action

Headers:
auth: your-secret-key

Body:
{
  "actionId": "export-csv",
  "records": [
    { "id": 1, "name": "John" },
    { "id": 2, "name": "Jane" }
  ]
}

Response:
{
  "success": true,
  "data": "id,name\n1,John\n2,Jane",
  "filename": "export.csv"
}

Execute Record Action

POST /dbmanager/{tableName}/record-action

Headers:
auth: your-secret-key

Body:
{
  "actionId": "send-welcome-email",
  "record": {
    "id": 1,
    "email": "john@example.com",
    "name": "John Doe"
  }
}

Response:
{
  "success": true,
  "message": "Email sent successfully"
}

Connector Class Methods

Constructor

new Connector(config: ConnectorConfig)

interface ConnectorConfig {
  secretKey: string;
  authKey?: string;
  db: DBConfig;
  apiUrl?: string;
}

setDatabaseHandler()

async setDatabaseHandler(handler: DatabaseHandler): Promise<void>

// Example
await connector.setDatabaseHandler(new ConnectorHelperSql());

start()

async start(): Promise<void>

// Example
await connector.start(); // Introspects database schema

customize()

customize<T extends TableName>(
  customizer: () => ModelCustomizer<T>
): this

// Example
connector.customize(() => {
  const c = new ModelCustomizer("users");
  c.rename("System Users");
  return c;
});

use()

use<T>(id: string, integration: T): this

// Example
connector.use('s3', new S3Integration(config));

using()

using<T>(id: string): T | undefined

// Example
const s3 = connector.using<S3Integration>('s3');
if (s3) {
  await s3.prepareUpload({...});
}

mountOnNestJs()

mountOnNestJs(app: INestApplication): void

// Example
const app = await NestFactory.create(AppModule);
connector.mountOnNestJs(app);
await app.listen(4000);

mountOnExpress()

mountOnExpress(app: Express): void

// Example
const app = express();
connector.mountOnExpress(app);
app.listen(4000);

mountOnFastify()

mountOnFastify(app: FastifyInstance): void

// Example
const app = fastify();
connector.mountOnFastify(app);
await app.listen({ port: 4000 });

startStandaloneServer()

startStandaloneServer(options: { port: number }): void

// Example
connector.startStandaloneServer({ port: 4000 });

DatabaseHandler Interface

connect()

async connect({ config }: { config: DBConfig }): Promise<void>

disconnect()

async disconnect(): Promise<void>

getSchemaDetails()

async getSchemaDetails(): Promise<SchemaDetails>

get()

async get(params: {
  table: string;
  where?: any;
  limit?: number;
  offset?: number;
  orderBy?: string;
  orderDirection?: "asc" | "desc";
  search?: string;
  searchColumns?: string[];
  columns?: string[];
}): Promise<{ rows: any[]; total: number }>

getSingle()

async getSingle(params: {
  table: TableName;
  where?: Record<string, any>;
}): Promise<any>

insert()

async insert(params: {
  table: TableName;
  data: Record<string, any>;
}): Promise<any>

update()

async update(params: {
  table: TableName;
  data: Record<string, any>;
  where: Record<string, any>;
}): Promise<{ rows: any[] }>

delete()

async delete(params: {
  table: TableName;
  where: Record<string, any>;
  single: boolean;
}): Promise<{ deleted: number }>

count()

async count(params: {
  table: TableName;
  where?: any;
  search?: string;
  searchColumns?: string[];
}): Promise<number>

Error Responses

API errors return standard HTTP status codes with error messages:

// 400 Bad Request
{
  "error": "Invalid request parameters",
  "details": "..."
}

// 401 Unauthorized
{
  "error": "Invalid authentication key"
}

// 404 Not Found
{
  "error": "Table 'invalid_table' not found"
}

// 500 Internal Server Error
{
  "error": "Internal server error",
  "message": "..."
}
Next Steps: Learn about Integrations to extend functionality with external services.