better-supabase-types
v2.7.6
Published
A CLI tool to add exports for your supabase tables
Downloads
1,620
Maintainers
Readme
Better Supabase Types
A CLI tool to add exports for your supabase tables. It will add type exports at the bottom of a new typescript file of every table you have. This tool can help remove the need to make a type for their rows manually.
Before 📉
import { Database } from './src/schema.ts';
type Todo = Database['public']['Tables']['Todo']['Row'];
const todos: Todo[] = [];
After 📈
import { Todo } from './src/newSchema.ts';
const todos: Todo[] = [];
Usage 🔨
- First have your supabase typescript file generated Supabase Docs
npx supabase gen types typescript --linked --schema public > ./src/schema.ts
- Run the
better-supabase-types
command (you can also use a config file):
npx better-supabase-types -i ./src/schema.ts -o ./src/newSchema.ts
Commands 💻
Options:
--version Show version number [boolean]
--help Show help [boolean]
-i, --input Path to the input file [string] [required]
-o, --output Path to the output file [string]
-p, --prettier Path to the prettier config file
[string] [default: ".prettierrc"]
-f, --force Force the overwrite of the input file [boolean]
-s, --singular Convert table names to singular form instead of plural form
[boolean] [default: false]
--enumAsType Have converted enums defined as types and not enums
[boolean] [default: false]
--enumPascalCase Enums format to pascal case [boolean] [default: false]
Config file ⚙
You can also use a config named .betterrc.json
:
{
"input": "./src/schema.ts",
"force": true,
"singular": true
}
package.json 📦
You can also put your config file in your package.json
file:
{
"name": "better-supabase-types",
"...": "...",
"betterConfig": {
"input": "./schema.ts",
"output": "./newSchema.ts"
}
}
Contributions ➕
Please contribute to this if you find any bugs or want any additions. This is my first public package so please bear with me if there are any issues.
Thanks 🙏
Big thanks to Barry for making the Supabase React Query Codegen tool to help me understand on how to read the supabase type file.