Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SupaGo logo

SupaGo

Supabase toolkit for Go projects.

Installation

go install github.com/01JAMIL/supago.git/cmd/supago@latest

Quick Start

supago init

# configure .env with your database URL (SUPAGO_DATABASE_URL)

supago generate all

Workflow Example

Given a database with users and tasks tables, supago generate all produces:

internal/
├── adapters/
│   └── supago/
│       ├── models.go              # All Go structs
│       ├── users/
│       │   └── repository.go      # Repository implementation
│       └── tasks/
│           └── repository.go      # Repository implementation
├── users/
│   ├── service.go                 # Business logic (starting point)
│   └── handler.go                 # HTTP handlers (starting point)
├── tasks/
│   ├── service.go                 # Business logic (starting point)
│   └── handler.go                 # HTTP handlers (starting point)
└── json/
    └── json.go                    # JSON helpers (generated, DO NOT EDIT)

Generated models

// internal/adapters/supago/models.go
package supago

type User struct {
    ID        int64      `json:"id"`
    FullName  *string    `json:"fullName"`
    Email     *string    `json:"email"`
    CreatedAt time.Time  `json:"createdAt"`
}

type Task struct {
    ID        int64      `json:"id"`
    TaskName  *string    `json:"taskName"`
    IsDone    *bool      `json:"isDone"`
    UserID    *int64     `json:"userId"`
    CreatedAt time.Time  `json:"createdAt"`
}

Generated repository

// internal/adapters/supago/users/repository.go
package users

type Repository struct {
    pool *pgxpool.Pool
}

func NewRepository(pool *pgxpool.Pool) *Repository { ... }
func (r *Repository) List(ctx context.Context) ([]supago.User, error) { ... }
func (r *Repository) GetByID(ctx context.Context, id int64) (*supago.User, error) { ... }
func (r *Repository) Create(ctx context.Context, user *supago.User) error { ... }
func (r *Repository) Update(ctx context.Context, user *supago.User) error { ... }
func (r *Repository) Delete(ctx context.Context, id int64) error { ... }

Generated service & handler

// internal/users/service.go — starting point, modify as needed
package users

type Service struct {
    repo *usersrepo.Repository
}

func (s *Service) List(ctx context.Context) ([]supago.User, error) {
    return s.repo.List(ctx)
}
// internal/users/handler.go — starting point, modify as needed
func (h *Handler) List(w http.ResponseWriter, r *http.Request) {
    items, err := h.svc.List(r.Context())
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
    json.Write(w, http.StatusOK, items)
}

Architecture

Layer Path Ownership
Infrastructure internal/adapters/supago/ Generated by SupaGo, DO NOT EDIT
Application internal/{table}/ Generated as starting point, modify freely

The infrastructure layer owns the models and repository implementations. The application layer owns the services and handlers — generated once as a starting point, then fully owned by the developer.

Configuration

supago.yaml is generated by supago init:

version: 1

database:
  driver: postgres
  url: ${SUPAGO_DATABASE_URL}

generation:
  output: internal/adapters/supago

Environment

# .env
SUPAGO_DATABASE_URL=postgresql://postgres:password@localhost:5432/postgres

Commands

Command Description
init Initialize SupaGo in an existing Go project
inspect Inspect the database schema and display tables, columns, types, and constraints
generate model Generate Go structs from database tables
generate repository Generate Go repositories with full CRUD per table
generate crud Generate services and HTTP handlers using net/http as a starting point
generate all Run the full generation pipeline (model, repository, crud)
version Print the version of SupaGo

License

MIT

About

SupaGo is a CLI tool that introspects your Supabase PostgreSQL database and generates idiomatic Go structs, reducing boilerplate and keeping your models in sync with your schema.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages