@distilled.cloud/planetscale
v0.5.1
Published
Effect-native PlanetScale SDK generated from the [PlanetScale OpenAPI specification](https://api-docs.planetscale.com/). Manage MySQL and PostgreSQL databases, branches, deploy requests, passwords, and more with exhaustive error typing.
Downloads
633
Readme
@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 effectQuick 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* 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-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.
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
