KAI
  • Overview
  • Documentation
    • Services
      • Business Glossary Services
      • Database Connection Services
      • Context Store Services
      • Instruction Services
      • NL Generation Services
      • Prompt Services
      • RAG Services
      • SQL Generation Services
      • Table Description Service
    • APIs
      • Business Glossary API
      • Context Store API
      • Database Connection API
      • Instruction API
      • NL Generation API
      • Prompt API
      • RAGs API
      • SQL Generation API
      • Table Description API
Powered by GitBook
On this page
  • Endpoints
  • Example Usage
  • Error Handling
  1. Documentation
  2. APIs

Database Connection API

The Database Connection API provides endpoints to manage database connections, including creating, listing, updating, and retrieving database connection details. Below is a guide on how to use these endpoints effectively.

Endpoints

1. Create a Database Connection

Endpoint: /api/v1/database-connections Method: POST Request Body:

{
    "alias": "string",
    "connection_uri": "string",
    "schemas": ["string"],
    "metadata": {"key": "value"}
}

Description: Creates a new database connection with the provided details.

Response:

{
    "id": "string",
    "alias": "string",
    "connection_uri": "string",
    "schemas": ["string"],
    "metadata": {"key": "value"},
    "created_at": "string"
}

2. List Database Connections

Endpoint: /api/v1/database-connections Method: GET Description: Retrieves a list of all database connections.

Response:

[
    {
        "id": "string",
        "alias": "string",
        "connection_uri": "string",
        "schemas": ["string"],
        "metadata": {"key": "value"},
        "created_at": "string"
    }
]

3. Update a Database Connection

Endpoint: /api/v1/database-connections/{db_connection_id} Method: PUT Request Body:

{
    "alias": "string",
    "connection_uri": "string",
    "schemas": ["string"],
    "metadata": {"key": "value"}
}

Description: Updates the details of a specific database connection identified by db_connection_id.

Response:

{
    "id": "string",
    "alias": "string",
    "connection_uri": "string",
    "schemas": ["string"],
    "metadata": {"key": "value"},
    "created_at": "string"
}

4. Delete a Database Connection

Endpoint: /api/v1/database-connections/{db_connection_id} Method: DELETE Description: Delete an existing database connection that was identified by db_connection_id.

Response:

{
    "id": "string",
    "alias": "string",
    "connection_uri": "string",
    "schemas": ["string"],
    "metadata": {"key": "value"},
    "created_at": "string"
}

Example Usage

Creating a Database Connection

To create a new database connection, send a POST request to /api/v1/database-connections with the required body. For example:

Request:

POST /api/v1/database-connections
Content-Type: application/json

{
    "alias": "my_database",
    "connection_uri": "postgresql://user:password@localhost/dbname",
    "schemas": ["public"],
    "metadata": {"type": "postgres"}
}

Response:

{
    "id": "12345",
    "alias": "my_database",
    "connection_uri": "postgresql://user:password@localhost/dbname",
    "schemas": ["public"],
    "metadata": {"type": "postgres"},
    "created_at": "2024-09-09T12:34:56Z"
}

Listing Database Connections

To retrieve a list of all database connections, send a GET request to /api/v1/database-connections:

Request:

GET /api/v1/database-connections

Response:

[
    {
        "id": "12345",
        "alias": "my_database",
        "connection_uri": "postgresql://user:password@localhost/dbname",
        "schemas": ["public"],
        "metadata": {"type": "postgres"},
        "created_at": "2024-09-09T12:34:56Z"
    }
]

Updating a Database Connection

To update an existing database connection, send a PUT request to /api/v1/database-connections/{db_connection_id} with the updated details:

Request:

PUT /api/v1/database-connections/12345
Content-Type: application/json

{
    "alias": "updated_database",
    "connection_uri": "postgresql://user:password@localhost/updated_dbname",
    "schemas": ["public"],
    "metadata": {"type": "postgres", "version": "12"}
}

Response:

{
    "id": "12345",
    "alias": "updated_database",
    "connection_uri": "postgresql://user:password@localhost/updated_dbname",
    "schemas": ["public"],
    "metadata": {"type": "postgres", "version": "12"},
    "created_at": "2024-09-09T12:34:56Z"
}

Deleting a Database Connection

To delete an existing database connection, send a DELETE request to /api/v1/database-connections/{db_connection_id}:

Request:

DELETE /api/v1/database-connections/12345
Content-Type: application/json

Response:

{
    "id": "12345",
    "alias": "deleted_database",
    "connection_uri": "postgresql://user:password@localhost/updated_dbname",
    "schemas": ["public"],
    "metadata": {"type": "postgres", "version": "12"},
    "created_at": "2024-09-09T12:34:56Z"
}

Error Handling

  • 400 Bad Request: The request body is invalid or missing required fields.

  • 404 Not Found: The specified db_connection_id does not exist.

  • 500 Internal Server Error: An unexpected error occurred on the server.

PreviousContext Store APINextInstruction API

Last updated 4 months ago