Table Template APIs¶
You can use the ThanoSQL Table Template REST API for several CRUD operations on your table templates.
Table Template Object
A table template object consists of five main componenets:
- name: The name of the table template
- table_template: The body of the table template, consisting of columns and constraints (see the documentation on the table object for more details)
- version: The version of the table template (currently, this value is immutable)
- compatibility: The compatibility of the table template (one of- backward,- forward,- full, or- none)
- created_at: The date of creation of the table template
GET /table_template¶
Retrieves a list of all of available table templates in a certain order. Optionally can include search keywords as well.
import requests
import json
api_token = "Issued_API_TOKEN"
base_url="https://{your-engine-url}/api/v1/table_template/"
search = "Search keyword(s)"
order_by = "Order by"
latest = {Latest}
api_url = f"{base_url}?search={search}&order_by={order_by}&latest={latest}"
header = {
    "Authorization": f"Bearer {api_token}"
}
r = requests.get(api_url, headers=header):
r.raise_for_status()
r.json()
  curl -X 'GET' \
  'https://{your-engine-url}/api/v1/table_template/?search={search}&order_by={order_by}&latest={latest}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN'
Parameters¶
- search: Word(s) that the table templates' name must contain (defaults to empty string).
- order_by: How the query results should be ordered, there are three possible values: 'recent', based on date of creation from latest to oldest, 'name_asc', based on name from A to Z, and 'name_desc', based on name from Z to A (defaults to 'recent').
- latest: A boolean value that can be set to- Trueif you only want to return the latest version of each table template. Otherwise, it returns all available versions (default:- False).
GET /table_template/{table_template_name}¶
Retrieves the table template object with the given name. If needed, a specific or latest version can also be added to the request.
import requests
import json
api_token = "Issued_API_TOKEN"
base_url = "https://{your-engine-url}/api/v1/table_template"
table_template_name = "Table template name"
version = "A specific version, or 'latest' to request the latest table template"
api_url = f"{base_url}/{table_template_name}?version={version}"
header = {
    "Authorization": f"Bearer {api_token}"
}
r = requests.get(api_url, headers=header):
r.raise_for_status()
r.json()
  curl -X 'GET' \
  'https://{your-engine-url}/api/v1/table_template/{table_template_name}?version={version}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN'
Response¶
The API response has the following structure:
{
  "table_templates": ["list of all table templates with the requested name, or one table template if version is not empty"]
  "versions": ["list of all available versions"]
}
POST /table_template/{table_template_name}¶
Creates a new table template.
import requests
import json
api_token = "Issued_API_TOKEN"
base_url="https://{your-engine-url}/api/v1/table_template/"
table_template_name = "Table template name"
data = {
"table_template": {
    "columns": [
    {
        "default": "nextval('accounts_user_id_seq'::regclass)",
        "is_nullable": False,
        "type": "integer",
        "name": "id"
    },
    {
        "default": None,
        "is_nullable": True,
        "type": "character varying",
        "name": "username"
    },
    {
        "default": None,
        "is_nullable": False,
        "type": "character varying",
        "name": "password"
    },
    {
        "default": None,
        "is_nullable": True,
        "type": "character varying",
        "name": "role_id"
    }
    ],
    "constraints": {
    "primary_key": {
        "name": "user_id_pkey",
        "columns": ["id"]
    },
    "foreign_keys": [
        {
            "name": "user_role_id_fkey",
            "reference_schema": "public",
            "reference_column": "role_id",
            "reference_table": "roles",
            "column": "role_id"
        }
    ]
    }
},
"version": "string",
"compatibility": "string"
}
api_url = f"{base_url}/{table_template_name}"
header = {
    "Authorization": f"Bearer {api_token}"
}
r = requests.post(api_url, headers=header, body=data):
r.raise_for_status()
r.json()
  curl -X 'POST' \
'https://{your-engine-url}/api/v1/table_template/{table_template_name}' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
    "table_template": {
        "columns": [
        {
            "default": "nextval('accounts_user_id_seq'::regclass)",
            "is_nullable": False,
            "type": "integer",
            "name": "id"
        },
        {
            "default": None,
            "is_nullable": True,
            "type": "character varying",
            "name": "username"
        },
        {
            "default": None,
            "is_nullable": False,
            "type": "character varying",
            "name": "password"
        },
        {
            "default": None,
            "is_nullable": True,
            "type": "character varying",
            "name": "role_id"
        }
        ],
        "constraints": {
        "primary_key": {
            "name": "user_id_pkey",
            "columns": ["id"]
        },
        "foreign_keys": [
            {
                "name": "user_role_id_fkey",
                "reference_schema": "public",
                "reference_column": "role_id",
                "reference_table": "roles",
                "column": "role_id"
            }
        ]
        }
    },
    "version": "string",
    "compatibility": "string"
    }'
DELETE /table_template/{table_template_name}¶
Deletes table templates with the given name. If needed, it is also possible to delete only a specific version.
import requests
import json
api_token = "Issued_API_TOKEN"
base_url = "https://{your-engine-url}/api/v1/table_template"
table_template_name = "Table template name"
version = "A specific version of the table template"
api_url = f"{base_url}/{table_template_name}?version={version}"
header = {
    "Authorization": f"Bearer {api_token}"
}
r = requests.delete(api_url, headers=header):
r.raise_for_status()
r.json()
  curl -X 'DELETE' \
  'https://{your-engine-url}/api/v1/table_template/{table_template_name}?version={version}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN'
  
    
      Last update:
      2023-12-14