Tables and Schema
The following are various examples of how to leverage the Metadata API to create and modify database tables including the schema and indexes included within them.
Get Workspaces
Browse the workspaces of the instance. This API endpoint does not require any parameters. Retrieving the workspaces gives you information on the workspace name and ID. The workspace ID is particularly important for use in other Metadata API endpoints.
Example response body:
Get Tables of a Workspace
Browse workspace tables. This API endpoint requires a workspace ID and will provide various information about each database table in a workspace, including database table ID, which is needed in various Metadata API endpoints.
Example response body:
Create Table and Add Schema One by One
First, create a new table in the desired workspace. The default request values suffice. In this example, first, we will create a table and then add schema individually. The Metadata API is capable of adding schema in bulk but that will be covered in another example.
Example response body:
Taking the newly created database table ID, we can add schema 1 by 1 to the table.
A text field called name.
Example response body:
Next, let's add an integer field called score with a default value of 30
As we execute these Metadata API calls, our new table in Xano is being created along with the new schema, one by one.
Create an Index
The Metadata API gives control over indexes on database tables. In this example, let's create a Unique Index on the name field of new table 123.
Example response body:
The API responds with the ID of the index. In Xano, we can see the index has been created:
Create Table with Schema and an Index in One Call
In this example, we will create a new database table along with schema and an index in the same API call. The Metadata API is flexible enough to accommodate this method.
Here's the example request body:
This creates a new table called "new stuff" with three fields: id, created_at, and name with an index on the name field.
For defining schema, the Metadata API needs a minimum of "name" and "type" but the other fields aren't required. If you are defining schema during table creation, the first field must be the ID field.
For Request body examples of schema and index, check out the PUT examples in Swagger for table/schema and table/index.
Browse Content
Browse table content is a simple method of getting content (database records) in a database table. It requires a workspace ID and table ID, while paging is optional.
Example response body:
Last updated