supabase-community / supabase-go

A Go Client library for Supabase
MIT License
197 stars 17 forks source link

Generate Go structs from Supabase tables #15

Closed mmvergara closed 3 months ago

mmvergara commented 3 months ago

Feature request

Problem

The problem arised for us (in my job) always messes up the tables whenever we make a change and our codebase is large using this supabase go client. This problem I think is unique in my job only and people won't probably need this I'm just here to share the tool

Solution

I made a CLI and Static site to generate go structs directly from the database

// It will generate this
type TableFormat struct {
    profiles string
    products string
}

var Tables = TableFormat{
    profiles: "profiles",
    products: "products",
}

// So instead of hardcoding table names directly:
// supabaseClient.From("profiles").Select("*").Execute()

// use the generate 'Tables' struct
supabaseClient.From(Tables.profiles).Select("*").Execute() 

So it's like achieving typesafety'ish like in Supabase TS This way, if you make changes to your Supabase tables, you can simply regenerate the Go structs using the tool

This uses the supabase API to fetch the tables just like this Supabase Schema Visualizer App so this thing probably will work forever unless the v1 api changes.

Additional context

I'm proposing to somehow mention this tool in the Readme of this repo, people may find it useful. I don't really mind if not im just here to share it.

mmvergara commented 3 months ago

will improve this further

motatoes commented 2 months ago

hey @mmvergara this is exactly what I was looking for! I noticed the repo no longer exists, any chance you can point me to where you have moved it to? Thanks!

mmvergara commented 2 months ago

hey @mmvergara this is exactly what I was looking for! I noticed the repo no longer exists, any chance you can point me to where you have moved it to? Thanks!

Hey, i actually deleted the repository thinnking it is not so useful. but i restored it for you. links are now available https://github.com/mmvergara/supabase-go-tables

motatoes commented 2 months ago

Thanks a lot!