# prisma-supabase

> Prisma generator for creating types for supabase-js/postgrest-js, without requiring a database, for faster generation times. Ideal for PostgREST-only projects.

Latest version **0.0.3** (published 2024-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install prisma-supabase
pnpm add prisma-supabase
yarn add prisma-supabase
bun add prisma-supabase
```

Provides the command `prisma-supabase`.

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2024-11-08 |
| First published | 2024-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 28.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Nurul Huda |
| Maintainers | nurulhudaapon |
| Keywords | prisma, prisma-generator, prisma-supabase, supabase-types, postgrest-types, postgrest, supabase, code-generation, typescript |

## Links

- npm: https://www.npmjs.com/package/prisma-supabase
- Repository: https://github.com/nurulhudaapon/prisma-generator-supabase
- Issues: https://github.com/nurulhudaapon/prisma-generator-supabase/issues
- npm.io page: https://npm.io/package/prisma-supabase

## Dependencies (2)

- [prettier](https://npm.io/package/prettier.md) ^3.3.3
- [@prisma/generator-helper](https://npm.io/package/@prisma/generator-helper.md) ^5.21.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2024-11-08
- 0.0.2 — 2024-11-06
- 0.0.1 — 2024-10-19
- 0.0.1-beta.5 — 2024-10-19
- 0.0.1-beta.4 — 2024-10-19
- 0.0.1-beta.3 — 2024-10-19
- 0.0.1-beta.2 — 2024-10-19
- 0.0.1-beta.1 — 2024-10-19
- 0.0.1-beta.0 — 2024-10-19
- 0.0.1-alpha.2 — 2024-10-19
- 0.0.1-alpha.1 — 2024-10-19
- 0.0.1-alpha.0 — 2024-10-19

## README

# Prisma Supabase Generator

A Prisma generator that creates types for the [@supabase/supabase-js](https://github.com/supabase/supabase-js) or [@supabase/postgrest-js](https://github.com/supabase/postgrest-js) client without the need for an online or dockerized database, resulting in faster generation times. This is particularly useful for projects that only use PostgREST.

## Demonstration

![Demo GIF](https://raw.githubusercontent.com/nurulhudaapon/prisma-supabase/main/assets/prisma-supabase-demo-1.gif)

## Installation

To use this generator, add it to your Prisma project. First, install the package:

NPM
```sh
npm i -D prisma-supabase
```

Yarn
```sh
yarn add -D prisma-supabase
```

PNPM
```sh
pnpm add -D prisma-supabase
```

Deno 2.x
```sh
deno add -D prisma-supabase
```

Bun
```sh
bun add -D prisma-supabase
```

## Usage

1. Add the generator to your `schema.prisma` file:

```prisma
generator supabase {
  provider = "prisma-supabase"
  output   = "./database.ts" // Optional: Defaults to ./database.ts which would store in ./prisma/database.ts
  enableDocumentation = true // Optional: Defaults to true
}
```

2. Run Prisma generate to create the Supabase types:

```bash
npx prisma generate
```

This will generate a `database.ts` file (or whatever you specified in the `output` option) in your Prisma output directory (usually `prisma/`).

### Configuration Options

- `output`: Specifies the output file for the generated types. Defaults to `./prisma/database.ts`.
- `enableDocumentation`: Enables or disables the generation of JSDoc comments from Prisma schema comments. Defaults to `true`.

## Example Usage

Here's an example of how to use the generated types with Supabase:

```typescript
import { createClient } from "@supabase/supabase-js";
import { type Database } from "./prisma/database";

// Supabase Example
const supabase = createClient<Database>('', '');

supabase.from('User').select('*').limit(1).single().then((res) => {
  console.log(res.data?.id);
});

supabase.from('User').select('*, Post(*)').limit(1).single().then((res) => {
  console.log(res.data?.Post[0].content);
});

```

Or using [PostgREST](https://postgrest.org/):

```typescript
import { PostgrestClient } from "@supabase/postgrest-js";
import { type Database } from "./prisma/database";

// PostgREST Example
const postgrest = new PostgrestClient<Database>('');

postgrest.from('User').select('*').limit(1).single().then((res) => {
  console.log(res.data?.id);
});

postgrest.from('User').select('*, Post(*)').limit(1).single().then((res) => {
  console.log(res.data?.Post[0].content);
});

```

In these examples, the `Database` type is imported from the generated `database.ts` file, providing type safety for your Supabase or PostgREST queries based on your Prisma schema.

## Example Output
**Schema**: [example/prisma/schema.prisma](./example/prisma/schema.prisma)

**Output**: [example/prisma/database.ts](./example/prisma/database.ts)

## Features

- [x] Table Types
- [x] Table Relationships
- [x] Enum Types
- [x] JSDoc from Prisma schema comments
- [x] View Types (included within Table Types)
- [ ] Multiple Schemas (in progress)
- [ ] Composite Types (not supported by Prisma yet)
- [ ] Function Types (not supported by Prisma yet)

## Benefits

- Generate [Supabase](https://supabase.com/) types from your [Prisma](https://www.prisma.io/) schema without an online or dockerized database
- Useful for projects that only use [PostgREST](https://postgrest.org/)
- Faster type generation process
- Optional JSDoc comments for better code documentation

## Requirements

- Prisma 2.x or higher

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue.

## License

This project is licensed under the MIT License.

---
_Source: https://npm.io/package/prisma-supabase · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
