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
- tableName: string (required) - The name of the table to create.
- columns: array of objects (required) - An array defining the columns of the table. Each column object can have:
- name: string (required) - Column name.
- type: string (required) - Data type (e.g., 'INT', 'VARCHAR(255)', 'BOOLEAN', 'DATETIME').
- nullable: boolean (optional, defaults to false) - Whether the column can contain NULL values.
- default: any (optional) - Default value for the column.
- primaryKey: boolean (optional, defaults to false) - If this column is part of the primary key.
- autoIncrement: boolean (optional, defaults to false) - If the column should auto-increment.
- unique: boolean (optional, defaults to false) - If values in this column must be unique.
- indexes: array of objects (optional) - An array defining indexes for the table. Each index object can have:
- name: string (optional) - Name of the index.
- columns: array of strings (required) - Names of the columns to include in the index.
- unique: boolean (optional, defaults to false) - If the index should enforce uniqueness.
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
- :tableName: string (required) - The name of the table to retrieve the schema for.
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
- :tableName: string (required) - The name of the table to delete.
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
- :tableName: string (required) - The name of the table to alter.
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."
}