Get a table (Go)
Gets a reference to a table for use with the Data API clients.
|
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 a Table object that corresponds to the specified table name.
This method returns a Table object even for collections that don’t exist.
Parameters
Use the Table method, which belongs to the Db type.
Method signature
func (d *Db) Table(
name string,
opts ...options.GetTableOption
) *Table
| Name | Type | Summary |
|---|---|---|
|
|
The name of the table. |
|
|
Optional. The options for this method. See Methods of the |
| Method | Summary |
|---|---|
|
Optional. The keyspace containing the table. For an example, see Get a table and specify the keyspace. Default: The working keyspace for the database.
This is |
|
Optional. This only applies to tables that have a vector column with a vectorize embedding provider integration. Use this option to provide the embedding provider API key directly with headers instead of using an API key in the Astra DB KMS. The API key is sent to the Data API for every operation on the table. It is useful when a vectorize integration is configured but no credentials are stored, or when you want to override the stored credentials. For more information, see Manage embedding provider integrations for vectorize. You can use this authentication method only if all affected columns use the same embedding provider. If you use an AWS embedding provider, you must use |
|
Optional. General API options for this operation, including the timeout. |
Examples
The following examples demonstrate how to get a table.
Get a table
package main
import (
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// Get a table
database.Table("TABLE_NAME")
}
Get a table 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 (
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// Get a table
database.Table(
"TABLE_NAME",
options.GetTable().SetKeyspace("KEYSPACE_NAME"),
)
}
Get a table and specify typing
The Go client doesn’t support typing when you instantiate a Table object.
Instead, you specify the row type when you perform operations like inserting or finding rows.
Client reference
For more information, see the client reference.