Get a table (Go)
|
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 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 if you specified a working keyspace when you created the Default: The working keyspace set when you created the |
|
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(
options.API().SetEnvironment(options.EnvironmentHCD),
)
database := client.Database(
"API_ENDPOINT",
options.API().
SetUsernamePasswordTokenProvider(
"USERNAME",
"PASSWORD",
).
SetKeyspace("KEYSPACE_NAME"),
)
// Get a table
database.Table("TABLE_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.