Get a database admin (Go)
The Data API clients use the Database Admin class to perform administrative operations, like managing keyspaces, within a specific database.
The Database Admin class name varies by client.
The Go client uses DataAPIDatabaseAdmin.
Result
Returns a DataAPIDatabaseAdmin struct that can perform administrative actions on the specified database.
Signature
Use the DatabaseAdmin method, which belongs to the Db type.
func (d *Db) DatabaseAdmin() (DataAPIDatabaseAdmin, error)
Parameters
This method does not accept any parameters.
Examples
The following examples demonstrate how to get a database admin object.
Get a database admin from a database
package main
import (
"log"
"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 database admin
_, err := database.DatabaseAdmin()
if err != nil {
log.Fatal(err)
}
}
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.