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.
Parameters
Use the DatabaseAdmin method, which belongs to the Db type.
Method signature
func (d *Db) DatabaseAdmin() (DataAPIDatabaseAdmin, error)
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)
}
}
Client reference
For more information, see the client reference.