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

supabase-tanstack-query-codegen

v1.1.3

Published

A CLI tool to automatically generate TanStack Query hooks and TypeScript types for your Supabase Database, streamlining data fetching and enhancing developer productivity.

Downloads

6

Readme

npm version npm Known Vulnerabilities License: MIT

Supabase React Query Codegen 🚀

A CLI tool to automatically generate React Query hooks and TypeScript types for your Supabase Database, streamlining data fetching and enhancing developer productivity.

Table of Contents 📚

Features ⭐️

  • Automatically generates TypeScript types and React Query hooks for your Supabase database.
  • Reduces manual work and the likelihood of errors.
  • Increases developer productivity by providing ready-to-use hooks for fetching data.

Installation 📥

Install the package globally using npm:

npm install -g supabase-react-query-codegen

Or with Yarn:

yarn global add supabase-react-query-codegen

Usage 🛠️

  1. First, generate a TypeScript types file for your Supabase database (if you haven't already):
supabase gen types typescript --project-id "<your-project-id>" --schema public > path/to/types.ts
  1. Create a supabase-react-query-codegen.config.json file with the following properties:
{
  // required
  "outputPath": "src/generated.ts", // path where generated code will go
  "typesPath": "src/types.ts", // path to your types file generated in step 1

  // optional
  "prettierConfigPath": ".prettierrc", // path to your .prettierrc file
  "relativeSupabasePath": "./supabase", // where your supabase client is relative to your generated file
  "supabaseExportName": "supabase", // if not supplied, default will be imported in your generated file
}
  1. Run the generate command, passing in the required arguments:
npx supabase-react-query-codegen generate supabase-react-query-codegen.config.json

Generated Types 🚧

For convenience this tool also generates types from your Database schema. The following types will be generated for each table in your database, if you have a table called todo_items then you will get these types:

  • TodoItem
  • AddTodoItemRequest
  • UpdateTodoItemRequest

Alternatives 🔄

This project has been developed in collaboration with the Better Supabase Types CLI tool made by FroggyPanda. If you don't use React Query but like the types generation part of this tool, it may be worth checking them out! ❤️

Generated Hooks 🔍

The following hooks will be generated for each table in your database, if you have a table called todo_items then you will get these hooks:

  • useGetTodoItem: Fetch a single row by its ID.
  • useGetAllTodoItems: Fetch all rows in the table.
  • useAddTodoItem: Add a new row to the table.
  • useUpdateTodoItem: Update an existing row in the table.
  • useDeleteTodoItem: Delete a row from the table by its ID.

Note that todo_items is converted to PascalCase in the hook names.

Contributing 🤝

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository. If you'd like to contribute code, feel free to fork the repository and submit a pull request.

Contributors 👥

Get yourself added to this list by helping me out wherever you can!

License 📜

MIT