SmartMind table API

The table API from SmartMind — 7 operation(s) for table.

OpenAPI Specification

smartmind-table-api-openapi.yml Raw ↑
openapi: 3.0.2
info:
  title: THANOSQL api file table API
  description: THANOSQL TEST API documentation
  version: '1.0'
tags:
- name: table
paths:
  /api/v1/table/:
    get:
      tags:
      - table
      summary: Get Tables
      description: "Gets the paginated list of all the tables from the given schema. If no\nschema is provided then the function retreives all of the tables from\nall of the schemas. pg_catalog and information_schema related tables are\nexempted, unless specified. The API can only return 100 tables at a time,\nstarting from the offset number specified.\n\nParameters\n----------\n- schema : str, default None\n    The schema to retrieve the tables from. If None is\n    provided, refers to all schemas.\n- verbose: bool, default False\n    Whether to include only base information or verbose information on the tables.\n- offset: int, default 0\n    The offset position of where to select the tables from.\n- limit: int, default 100\n    The number of tables to retrieve. This value must range from 0 and 100.\n\nReturns\n-------\nA TablesResponse Pydantic object containing a List of\neither Table Pydantic or Base Table Pydantic models depending\non the verbose parameter."
      operationId: get_tables_api_v1_table__get
      parameters:
      - required: false
        schema:
          title: Schema
          type: string
        name: schema
        in: query
      - required: false
        schema:
          title: Verbose
          type: boolean
          default: false
        name: verbose
        in: query
      - required: false
        schema:
          title: Offset
          type: integer
          default: 0
        name: offset
        in: query
      - required: false
        schema:
          title: Limit
          type: integer
          default: 100
        name: limit
        in: query
      responses:
        '200':
          description: Successful Response (when verbose is set to True)
          content:
            application/json:
              schema: {}
              example:
                tables:
                - name: string
                  schema: string
                  columns:
                  - id: 0
                    default: string
                    is_nullable: true
                    type: string
                    name: string
                  constraints:
                    primary_key:
                      name: ''
                      columns: []
                    foreign_keys:
                    - name: string
                      reference_schema: public
                      reference_column: string
                      reference_table: string
                      column: string
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
  /api/v1/table/{table_name}:
    get:
      tags:
      - table
      summary: Get Table
      description: "Gets the Table object with the specified table_name and\nschema. If the schema is not specified, it automatically\ndefaults to public.\n\nParameters\n----------\ntable_name: str\nschema : str, default public\n    The schema to retrieve the tables from. If no parameter is\n    provided, assigned as public.\n\nReturns\n-------\nA TableResponse Pydantic object containing a Table Pydantic object."
      operationId: get_table_api_v1_table__table_name__get
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
    put:
      tags:
      - table
      summary: Update Table
      description: "Alters the table specified with the table_name and schema to the\nTable object specified in the body parameter.\n\nInstructions\n------------\nIn order to update an object, simply change the values of the Table objects\nin the request body. To delete, simply remove the object from the request body.\nTo add, add the desired object to the request body.\n\nThe query is built in the following order:\n\nDROP UNIQUE CONSTRAINT -> DROP PRIMARY KEY -> DROP FOREIGN KEY -> DROP COLUMN -> ADD COLUMN -> ALTER COLUMN ->\nRENAME COLUMN -> ADD UNIQUE CONSTRAINT -> ADD PRIMARY KEY -> ADD FOREIGN KEY -> RENAME TABLE -> SET SCHEMA\n\n### Caution:\nFor the columns, it is important to note that the id is the\nunique key used to identify the column. If you remove the column_id key\nfrom the Column object, it will be dropped from the database and be recreated.\n\nSince there is a given order for execution, if your alter requires to not follow the\norder above, make sure to separate the API calls.\n\n\nParameters\n----------\n- table_name: str,\n- schema : str, default \"public\"\n    The schema to retrieve the tables from. If no parameter is\n    provided, defaults to \"public\".\n- body: AlterTableRequest, default None\n\nReturns\n-------\nA Table Pydantic object."
      operationId: update_table_api_v1_table__table_name__put
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AlterTableRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
    post:
      tags:
      - table
      summary: Create Table
      description: "Creates the table in the database using the BaseTableObjects object\nprovided in the request body, the table_name, and schema.\n\n*Note*: When adding Column objects to the list of columns,\nthere is no need to specify the id since the id just refers\nto the ordinal position of the column. Additionally if\nthe table is created with an empty body, an empty table will\nbe created. If no table_name is specified, the table will be\ncreated with a random uuid string.\n\nParameters\n----------\n- table_name: str\n- schema : str, default \"public\"\n    The schema to retrieve the tables from. If no parameter is\n    provided, defaults to \"public\".\n- if_not_exists: bool, default False\n    Whether to throw an error if a table of the same name already\n    exists. When set to False, an error will be shown. When True,\n    the table will only be created if it does not exist already.\n    Otherwise, do nothing.\n- body: CreateTableRequest, default None\nReturns\n-------\nA Table Pydantic object."
      operationId: create_table_api_v1_table__table_name__post
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      - required: false
        schema:
          title: If Not Exists
          type: boolean
          default: false
        name: if_not_exists
        in: query
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTableRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
    delete:
      tags:
      - table
      summary: Delete Table
      description: "Deletes the table specified by the table_name and schema.\n\nParameters\n----------\n- table_name: str\n- schema : str, default \"public\"\n    The schema to retrieve the tables from. If no parameter is\n    provided, defaults to \"public\".\n\nReturns\n-------\nA TableMessage Pydantic object containing a success message and the table_name."
      operationId: delete_table_api_v1_table__table_name__delete
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableMessageResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
  /api/v1/table/{table_name}/records:
    get:
      tags:
      - table
      summary: Get Records
      description: "Returns the paginated records of the given table specified by the table_name and\nschema. The API can only return 100 records at a time, starting from the offset\nnumber specified.\n\nParameters\n----------\n- table_name: str\n- schema : str, default \"public\"\n    The schema to retrieve the tables from. If no parameter is\n    provided, defaults to \"public\".\n- offset: int, default 0\n    The offset position of where to select the records from.\n- limit: int, default 100\n    The number of records to retrieve. This value must range from\n    0 and 100.\n\nReturns\n-------\nA TableRecordsResponse Pydantic object containing\nthe records and total number of records."
      operationId: get_records_api_v1_table__table_name__records_get
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      - required: false
        schema:
          title: Offset
          type: integer
          default: 0
        name: offset
        in: query
      - required: false
        schema:
          title: Limit
          type: integer
          default: 100
        name: limit
        in: query
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableRecordsResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
    post:
      tags:
      - table
      summary: Insert Records
      description: "Inserts the records in the input body into a table in a specified schema.\n\nParameters\n----------\n- table_name: str\n- records: list[dict]\n    The list of key-value pairs to be inserted to the table\n- schema : str, default \"public\"\n    The schema to retrieve the tables from. If no parameter is provided, defaults to \"public\".\n- on_conflict: str, default \"fail\"\n    What to do in case (an) inserted value(s) generate(s) a conflict due to the target table's\n    unique constraint. Available options:\n      - \"fail\" -> gives an error, insertion is only possible if unique constraint(s)\n          is(are) not violated\n      - \"skip\" -> does nothing on conflicted record, doesn't perform the insertion for that\n          particular record but doesn't cancel the entire insertion process\n      - if user inputs anything other than these two, the server will throw an exception\n\nReturns\n-------\nA Table Pydantic object."
      operationId: insert_records_api_v1_table__table_name__records_post
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      - required: false
        schema:
          title: On Conflict
          type: string
          default: fail
        name: on_conflict
        in: query
      requestBody:
        content:
          application/json:
            schema:
              title: Records
              type: array
              items:
                type: object
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
  /api/v1/table/{table_name}/records/csv:
    get:
      tags:
      - table
      summary: Get records as a CSV file
      description: "Returns the csv of the given table specified by the table_name and\nschema.\n\nParameters\n----------\n- table_name: str\n- schema : str, default \"public\"\n    The schema to retrieve the tables from. If no parameter is\n    provided, defaults to \"public\".\n- timezone_offset: int\n    The timezone offset applied to the datetime formats. Defaults to 9 (KST).\n\nReturns\n-------\nA StreamingResponse Pydantic object that iterates through the csv.\nIf the table is empty, returns a Response object with code 204."
      operationId: get_records_as_csv_api_v1_table__table_name__records_csv_get
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      - required: false
        schema:
          title: Timezone Offset
          type: integer
          default: 9
        name: timezone_offset
        in: query
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
  /api/v1/table/{table_name}/upload/csv:
    post:
      tags:
      - table
      summary: Upload Table From Csv
      description: "Inserts records from a CSV file into a table previously created using create_table,\nor creates a new table from it.\n\nParameters\n----------\n- table_name: the name of the table created by create_table\n- schema: database schema, default \"public\"\n- if_exists: what to do if table of the same name already exists, default \"fail\". available options:\n  - \"fail\" -> creates a new table, only possible if no table of the same name exists (fails otherwise)\n  - \"append\" -> appends records into an existing table (columns must match in order to not generate an exception)\n  - \"replace\" -> deletes an existing table and creates a new one with the same name\n  - if user inputs anything other than these three, the server will throw an exception\n- file: .csv file to be inserted\n- body: the request body if table template columns were to be added manually, optional\n\nReturns\n-------\nA Table Pydantic object."
      operationId: upload_table_from_csv_api_v1_table__table_name__upload_csv_post
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      - required: false
        schema:
          title: If Exists
          type: string
          default: fail
        name: if_exists
        in: query
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_upload_table_from_csv_api_v1_table__table_name__upload_csv_post'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
  /api/v1/table/{table_name}/upload/excel:
    post:
      tags:
      - table
      summary: Upload Table From Excel
      description: "Inserts records from a type of Excel file into a table previously created using create_table,\nor creates a new table from it.\n\nParameters\n----------\n- table_name: the name of the table created by create_table\n- schema: database schema, default \"public\"\n- if_exists: what to do if table of the same name already exists, default \"fail\". available options:\n  - \"fail\" -> creates a new table, only possible if no table of the same name exists (fails otherwise)\n  - \"append\" -> appends records into an existing table (columns must match in order to not generate an exception)\n  - \"replace\" -> deletes an existing table and creates a new one with the same name\n  - if user inputs anything other than these three, the server will throw an exception\n- file: Excel file to be inserted\n- body: the request body if table schema columns were to be added manually, optional\n\nReturns\n-------\nA Table Pydantic object."
      operationId: upload_table_from_excel_api_v1_table__table_name__upload_excel_post
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      - required: false
        schema:
          title: If Exists
          type: string
          default: fail
        name: if_exists
        in: query
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_upload_table_from_excel_api_v1_table__table_name__upload_excel_post'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
  /api/v1/table/{table_name}/upload/json:
    post:
      tags:
      - table
      summary: Upload Table From Json
      description: "Inserts records from JSON into a table previously created using create_table,\nor creates a new table from it.\n\nParameters\n----------\n- table_name: the name of the table created by create_table\n- schema: database schema, default \"public\"\n- if_exists: what to do if table of the same name already exists, default \"fail\". available options:\n  - \"fail\" -> creates a new table, only possible if no table of the same name exists (fails otherwise)\n  - \"append\" -> appends records into an existing table (columns must match in order to not generate an exception)\n  - \"replace\" -> deletes an existing table and creates a new one with the same name\n  - if user inputs anything other than these three, the server will throw an exception\n- body:\n  - \"table\": optionally specify a table object is to be added manually.\n  - \"data\": where the json object with the records format (list of json objects) is specified.\n\nReturns\n-------\nA TableResponse Pydantic object."
      operationId: upload_table_from_json_api_v1_table__table_name__upload_json_post
      parameters:
      - required: true
        schema:
          title: Table Name
          type: string
        name: table_name
        in: path
      - required: false
        schema:
          title: Schema
          type: string
          default: public
        name: schema
        in: query
      - required: false
        schema:
          title: If Exists
          type: string
          default: fail
        name: if_exists
        in: query
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTableWithJSON'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
      - Bearer Auth: []
components:
  schemas:
    CreateTableRequest:
      title: CreateTableRequest
      required:
      - table
      type: object
      properties:
        table:
          $ref: '#/components/schemas/BaseTableObjects'
    TableMessageResponse:
      title: TableMessageResponse
      required:
      - message
      - table_name
      - schema
      type: object
      properties:
        message:
          title: Message
          type: string
        table_name:
          title: Table Name
          type: string
        schema:
          title: Schema
          type: string
    Body_upload_table_from_excel_api_v1_table__table_name__upload_excel_post:
      title: Body_upload_table_from_excel_api_v1_table__table_name__upload_excel_post
      required:
      - file
      type: object
      properties:
        file:
          title: File
          type: string
          format: binary
        body:
          $ref: '#/components/schemas/CreateTableWithFileRequest'
    HTTPValidationError:
      title: HTTPValidationError
      type: object
      properties:
        detail:
          title: Detail
          type: array
          items:
            $ref: '#/components/schemas/ValidationError'
    BaseColumn:
      title: BaseColumn
      required:
      - type
      - name
      type: object
      properties:
        default:
          title: Default
          type: string
        is_nullable:
          title: Is Nullable
          type: boolean
          default: true
        type:
          title: Type
          type: string
        name:
          title: Name
          type: string
    Column:
      title: Column
      required:
      - type
      - name
      type: object
      properties:
        id:
          title: Id
          type: integer
        default:
          title: Default
          type: string
        is_nullable:
          title: Is Nullable
          type: boolean
          default: true
        type:
          title: Type
          type: string
        name:
          title: Name
          type: string
    TableResponse:
      title: TableResponse
      required:
      - table
      type: object
      properties:
        table:
          $ref: '#/components/schemas/Table'
    Body_upload_table_from_csv_api_v1_table__table_name__upload_csv_post:
      title: Body_upload_table_from_csv_api_v1_table__table_name__upload_csv_post
      required:
      - file
      type: object
      properties:
        file:
          title: File
          type: string
          format: binary
        body:
          $ref: '#/components/schemas/CreateTableWithFileRequest'
    ValidationError:
      title: ValidationError
      required:
      - loc
      - msg
      - type
      type: object
      properties:
        loc:
          title: Location
          type: array
          items:
            anyOf:
            - type: string
            - type: integer
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
    CreateTableWithJSON:
      title: CreateTableWithJSON
      type: object
      properties:
        table:
          $ref: '#/components/schemas/BaseTableObjects'
        data:
          title: Data
          type: array
          items:
            type: object
          default: []
    CreateTableWithFileRequest:
      title: CreateTableWithFileRequest
      required:
      - table
      type: object
      properties:
        table:
          $ref: '#/components/schemas/BaseTableObjects'
    PrimaryKey:
      title: PrimaryKey
      type: object
      properties:
        name:
          title: Name
          type: string
          default: ''
        columns:
          title: Columns
          type: array
          items:
            type: string
          default: []
    BaseTableObjects:
      title: BaseTableObjects
      type: object
      properties:
        columns:
          title: Columns
          type: array
          items:
            $ref: '#/components/schemas/BaseColumn'
        constraints:
          $ref: '#/components/schemas/Constraints'
    AlterTableRequest:
      title: AlterTableRequest
      required:
      - table
      type: object
      properties:
        table:
          $ref: '#/components/schemas/Table'
    ForeignKey:
      title: ForeignKey
      required:
      - reference_column
      - reference_table
      - column
      type: object
      properties:
        name:
          title: Name
          type: string
        reference_schema:
          title: Reference Schema
          type: string
          default: public
        reference_column:
          title: Reference Column
          type: string
        reference_table:
          title: Reference Table
          type: string
        column:
          title: Column
          type: string
    Unique:
      title: Unique
      type: object
      properties:
        name:
          title: Name
          type: string
          default: ''
        columns:
          title: Columns
          type: array
          items:
            type: string
          default: []
    Table:
      title: Table
      type: object
      properties:
        name:
          title: Name
          type: string
        schema:
          title: Schema
          type: string
        columns:
          title: Columns
          type: array
          items:
            $ref: '#/components/schemas/Column'
        constraints:
          $ref: '#/components/schemas/Constraints'
    TableRecordsResponse:
      title: TableRecordsResponse
      required:
      - total
      type: object
      properties:
        records:
          title: Records
          type: array
          items:
            type: object
        total:
          title: Total
          type: integer
    Constraints:
      title: Constraints
      type: object
      properties:
        unique:
          title: Unique
          type: array
          items:
            $ref: '#/components/schemas/Unique'
        primary_key:
          $ref: '#/components/schemas/PrimaryKey'
        foreign_keys:
          title: Foreign Keys
          type: array
          items:
            $ref: '#/components/schemas/ForeignKey'
  securitySchemes:
    Bearer Auth:
      type: apiKey
      in: header
      name: Authorization
      description: 'Enter: **''Bearer <JWT>''**, where JWT is the access token. Example: Bearer access_token_comes_here'