Table Management API Reference

This section details the API endpoints for managing tables within your SQL database.

Create Table

Creates a new table in the database with the specified schema.

POST /api/v1/tables

Request Body (JSON)

{
    "tableName": "string",
    "columns": [
        {
            "name": "string",
            "type": "string",
            "nullable": "boolean",
            "default": "any",
            "primaryKey": "boolean",
            "autoIncrement": "boolean",
            "unique": "boolean"
        }
    ],
    "indexes": [
        {
            "name": "string",
            "columns": ["string"],
            "unique": "boolean"
        }
    ]
}

Parameters

Response (Success)

{
    "message": "Table 'users' created successfully."
}

Response (Error)

{
    "error": "Table 'users' already exists."
}

Get Table Schema

Retrieves the schema definition for a specific table.

GET /api/v1/tables/:tableName

Path Parameters

Response (Success)

{
    "tableName": "users",
    "columns": [
        {
            "name": "id",
            "type": "INT",
            "nullable": false,
            "primaryKey": true,
            "autoIncrement": true
        },
        {
            "name": "username",
            "type": "VARCHAR(50)",
            "nullable": false,
            "unique": true
        },
        {
            "name": "email",
            "type": "VARCHAR(100)",
            "nullable": true
        }
    ],
    "indexes": [
        {
            "name": "idx_users_username",
            "columns": ["username"],
            "unique": true
        }
    ]
}

Response (Error)

{
    "error": "Table 'nonexistent_table' not found."
}

List All Tables

Retrieves a list of all tables in the database.

GET /api/v1/tables

Response (Success)

[
    "users",
    "products",
    "orders",
    "categories"
]

Delete Table

Deletes a specified table from the database.

DELETE /api/v1/tables/:tableName

Path Parameters

Response (Success)

{
    "message": "Table 'products' deleted successfully."
}

Response (Error)

{
    "error": "Table 'nonexistent_table' not found."
}

Alter Table

Modifies an existing table by adding, removing, or modifying columns and indexes.

PATCH /api/v1/tables/:tableName

Path Parameters

Request Body (JSON)

The request body can contain any of the following keys:

{
    "addColumn": {
        "name": "string",
        "type": "string",
        "nullable": "boolean",
        "default": "any",
        "primaryKey": "boolean",
        "autoIncrement": "boolean",
        "unique": "boolean"
    },
    "dropColumn": "string",
    "modifyColumn": {
        "name": "string",
        "newDefinition": { ... column definition ... }
    },
    "addIndex": { ... index definition ... },
    "dropIndex": "string"
}

Parameters

You can specify one or more actions within a single request. For example, to add a column and drop an index:

{
    "addColumn": {
        "name": "last_login",
        "type": "DATETIME",
        "nullable": true
    },
    "dropIndex": "idx_users_email"
}

Response (Success)

{
    "message": "Table 'users' altered successfully."
}

Response (Error)

{
    "error": "Column 'id' cannot be dropped."
}