Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@distilled.cloud/planetscale

Effect-native PlanetScale SDK generated from the PlanetScale OpenAPI specification. Manage MySQL and PostgreSQL databases, branches, deploy requests, passwords, and more with exhaustive error typing.

Installation

npm install @distilled.cloud/planetscale effect

Quick Start

import { Effect, Layer } from "effect";
import * as Stream from "effect/Stream";
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
import { listDatabases } from "@distilled.cloud/planetscale/Operations";
import { CredentialsFromEnv, Credentials } from "@distilled.cloud/planetscale";

const program = Effect.gen(function* () {
  const { organization } = yield* yield* Credentials;
  const databases = yield* listDatabases({ organization });
  return databases.data;
});

const PlanetScaleLive = Layer.mergeAll(FetchHttpClient.layer, CredentialsFromEnv);

program.pipe(Effect.provide(PlanetScaleLive), Effect.runPromise);

Configuration

Set the following environment variables:

PLANETSCALE_API_TOKEN=your-service-token
PLANETSCALE_ORGANIZATION=my-org-name

Create a service token in the PlanetScale dashboard under Settings > Service tokens. Grant the token access to the databases and permissions it needs. PLANETSCALE_ORGANIZATION is your organization's URL slug.

Error Handling

import { getDatabase } from "@distilled.cloud/planetscale/Operations";

getDatabase({ organization: "my-org", database: "missing" }).pipe(
  Effect.catchTags({
    NotFound: () => Effect.succeed(null),
    UnknownPlanetScaleError: (e) => Effect.fail(new Error(`Unknown: ${e.message}`)),
  }),
);

License

MIT