Skip to content
Proyek

Tentang

Go client library to access the PlanetScale API

Data dan analisis

Cara angka ini diukur

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
0
dalam 15 hari
0
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

planetscale-go Go Reference CI

Go package to access the PlanetScale API.

[!NOTE] This repository is a read-only mirror. The client is developed in the pscale CLI repository at internal/planetscale/ and synced here automatically, so external users of this module keep getting updates through the usual tagged releases.

The module remains fully supported: keep importing github.com/planetscale/planetscale-go/planetscale as before. However, please do not open pull requests that change the client code here, since the next sync would overwrite them. Code contributions belong in the cli repository.

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 with the pscale service-token subcommand.

package main

import (
	"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)
	}
}