Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/planetscale/planetscale-go
Go client library to access the PlanetScale API
https://github.com/planetscale/planetscale-go
database go mysql planetscale vitess
Last synced: about 2 months ago
JSON representation
Go client library to access the PlanetScale API
- Host: GitHub
- URL: https://github.com/planetscale/planetscale-go
- Owner: planetscale
- License: apache-2.0
- Created: 2021-01-09T11:14:35.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T17:31:14.000Z (2 months ago)
- Last Synced: 2024-10-18T12:57:05.442Z (2 months ago)
- Topics: database, go, mysql, planetscale, vitess
- Language: Go
- Homepage: https://www.planetscale.com
- Size: 1.04 MB
- Stars: 123
- Watchers: 9
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# planetscale-go [![Go Reference](https://pkg.go.dev/badge/github.com/planetscale/planetscale-go/planetscale.svg)](https://pkg.go.dev/github.com/planetscale/planetscale-go/planetscale) [![Build status](https://badge.buildkite.com/82dafa9518fe94b3fed75db71bcfc3836faeec49816e400f2e.svg?branch=main)](https://buildkite.com/planetscale/planetscale-go)
Go package to access the PlanetScale API.
## Install
```
go get github.com/planetscale/planetscale-go/planetscale
```## Usage
Here is an example application using the PlanetScale Go client. You can create
and manage your service tokens via our [pscale
CLI](https://github.com/planetscale/cli) with the `pscale service-token`
subcommand.```go
package mainimport (
"context"
"log"
"os"
"time""github.com/planetscale/planetscale-go/planetscale"
)func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()// Create a new PlanetScale API client with the given service token.
client, err := planetscale.NewClient(
planetscale.WithServiceToken("token-id", os.Getenv("PLANETSCALE_TOKEN")),
)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}// Create a new database.
_, err = client.Databases.Create(ctx, &planetscale.CreateDatabaseRequest{
Organization: "my-org",
Name: "my-awesome-database",
Notes: "This is a test DB created via the planetscale-go API library",
})
if err != nil {
log.Fatalf("failed to create database: %v", err)
}// List all databases for the given organization.
databases, err := client.Databases.List(ctx, &planetscale.ListDatabasesRequest{
Organization: "my-org",
})
if err != nil {
log.Fatalf("failed to list databases: %v", err)
}log.Printf("found %d databases:", len(databases))
for _, db := range databases {
log.Printf(" - %q: %s", db.Name, db.Notes)
}// Delete a database.
_, err = client.Databases.Delete(ctx, &planetscale.DeleteDatabaseRequest{
Organization: "my-org",
Database: "my-awesome-database",
})
if err != nil {
log.Fatalf("failed to delete database: %v", err)
}
}
```