npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prisma-supabase

v0.0.3

Published

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

Downloads

487

Readme

Prisma Supabase Generator

A Prisma generator that creates types for the @supabase/supabase-js or @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

Installation

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

NPM

npm i -D prisma-supabase

Yarn

yarn add -D prisma-supabase

PNPM

pnpm add -D prisma-supabase

Deno 2.x

deno add -D prisma-supabase

Bun

bun add -D prisma-supabase

Usage

  1. Add the generator to your schema.prisma file:
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
}
  1. Run Prisma generate to create the Supabase types:
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:

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:

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

Output: 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 types from your Prisma schema without an online or dockerized database
  • Useful for projects that only use PostgREST
  • 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.