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.
npm install @distilled.cloud/planetscale effectimport { 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);Set the following environment variables:
PLANETSCALE_API_TOKEN=your-service-token
PLANETSCALE_ORGANIZATION=my-org-nameCreate 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.
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}`)),
}),
);MIT