List table names (Go)
Gets the names of 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
Returns the table names as an unordered slice of strings.
Signature
Use the ListTableNames method, which belongs to the Db type.
func (d *Db) ListTableNames(
ctx context.Context,
opts ...options.ListTablesOption
) ([]string, error)
Parameters
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional. The keyspace to inspect. For an example, see List table names and specify the keyspace. Default: The working keyspace for the database.
This is |
|
Optional. General API options for this operation, including the timeout. |
Examples
The following examples demonstrate how to list table names.
List table names
package main
import (
"context"
"fmt"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// List table names
names, err := database.ListTableNames(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(names)
}
List table names and specify the keyspace
By default, this method uses the working keyspace of your database. If you want to use a different keyspace, you must specify the keyspace.
package main
import (
"context"
"fmt"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// List table names
names, err := database.ListTableNames(
ctx,
options.ListTables().SetKeyspace("KEYSPACE_NAME"),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(names)
}
Errors
For a full list of Data API error codes and their corresponding messages, see Data API errors and error codes.
For more information about how the client handles underlying Data API errors, see Go client error handling.
Client reference
For more information, see the client reference.