List table metadata
Tables with the Data API are currently in public preview. Development is ongoing, and the features and functionality are subject to change. Hyper-Converged Database (HCD), and the use of such, is subject to the DataStax Preview Terms. |
Gets information about the tables in a keyspace.
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
-
Python
-
TypeScript
-
Java
-
curl
Returns an unordered list of ListTableDescriptor
objects that describe each table.
Example response:
[
BaseTableDescriptor(
name='fighters',
definition=BaseTableDefinition(
columns=[fighter_id,age,name,nationality,skill_levels],
primary_key=TablePrimaryKeyDescriptor[(fighter_id)]
),
raw_descriptor=...
),
BaseTableDescriptor(
name='games',
definition=BaseTableDefinition(
columns=[match_id,round,fighters,m_vector,score,when,winner],
primary_key=TablePrimaryKeyDescriptor[(match_id)round:a]
),
raw_descriptor=...
)
]
Returns a promise that resolves to an unordered list of FullTableInfo
objects that describe each table.
Example resolved response:
[
{
name: 'games',
definition: {
columns: {
matchId: { type: 'text' },
round: { type: 'tinyint' },
fighters: { type: 'set', valueType: 'uuid' },
mVector: { type: 'vector', dimension: 3 },
score: { type: 'int' },
when: { type: 'timestamp' },
winner: { type: 'text' }
},
primaryKey: {
partitionBy: [ 'matchId' ],
partitionSort: { round: 1 }
}
}
}
]
Returns an unordered list of TableDescriptor
objects that describe each table.
The status.tables
field in the response describes each table.
Example response:
{
"status": {
"tables": [
{
"name": "customers",
"definition": {
"columns": {
"order_date": {
"type": "timestamp"
},
"preferences": {
"type": "map",
"keyType": "text",
"valueType": "text"
},
"is_active": {
"type": "boolean"
},
"user_id": {
"type": "uuid"
},
"name": {
"type": "text"
},
"login_attempts": {
"type": "set",
"valueType": "int"
},
"photo": {
"type": "blob"
},
"salary": {
"type": "decimal"
},
"order_id": {
"type": "uuid"
},
"age": {
"type": "int"
},
"tags": {
"type": "list",
"valueType": "text"
}
},
"primaryKey": {
"partitionBy": [
"user_id"
],
"partitionSort": {
"order_id": 1,
"order_date": -1
}
}
}
}
]
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
curl
Use the list_tables
method, which belongs to the astrapy.Database
class.
Method signature
list_tables(
*,
keyspace: str,
table_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> list[ListTableDescriptor]
Name | Type | Summary |
---|---|---|
|
|
Optional if you specified a keyspace when instantiating the Default: The database’s working keyspace. |
|
|
A timeout, in milliseconds, for the underlying HTTP request.
If not provided, the |
Use the listTables
method, which belongs to the Db
class.
Method signature
async listTables(
options?: {
nameOnly?: false,
keyspace?: string,
timeout?: number | TimeoutDescriptor,
},
): TableDescriptor[]
Name | Type | Summary |
---|---|---|
|
|
The options for this operation. |
Options (ListTablesOptions
):
Name | Type | Summary |
---|---|---|
|
|
If false or undefined, the response includes table names and metadata. If true, the response includes only table names. |
|
|
Optional if you specified a keyspace when instantiating the Default: The database’s working keyspace. |
|
|
The client-side timeout for this operation. |
Use the listTables
method, which belongs to the com.datastax.astra.client.databases.Database
class.
Method signature
List<TableDescriptor> listTables()
List<TableDescriptor> listTables(ListTablesOptions listTableOptions)
Name | Type | Summary |
---|---|---|
|
Specialization of the operation, including |
Use the listTables
command.
Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"listTables": {
"options": {
"explain": true
}
}
}'
Name | Type | Summary |
---|---|---|
|
|
The Data API command to get a list of tables in a keyspace in a database. |
|
|
Whether to include table metadata in addition to table names in the response. |
Examples
The following examples demonstrate how to list table metadata.
List table metadata
-
Python
-
TypeScript
-
Java
-
curl
from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment
# Get a database
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
"API_ENDPOINT",
token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
)
# List table metadata
result = database.list_tables(keyspace="KEYSPACE_NAME")
print(result)
import {
DataAPIClient,
UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";
// Get a database
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
});
// List table metadata
(async function () {
const result = await database.listTables({ keyspace: "KEYSPACE_NAME" });
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.definition.TableDescriptor;
import java.util.List;
public class Example {
public static void main(String[] args) {
// Get a database
DataAPIClient client = DataAPIClients.clientHCD("USERNAME", "PASSWORD");
Database database = client.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");
// List table metadata
List<TableDescriptor> result = database.listTables();
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"listTables": {
"options": {
"explain": true
}
}
}'
Client reference
-
Python
-
TypeScript
-
Java
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.