Skip to Content

gofasta g repo-method

The repository-layer twin of g method. Identical semantics — patches an existing interface and impl, AST-based, idempotent — with repository-specific default paths:

  • Interface: app/repositories/interfaces/<snake>_repository.go
  • Impl: app/repositories/<snake>.repository.go
  • Naming: <Resource>RepositoryInterface + <lowerResource>Repository

Use this for data-access methods (FK lookups, custom queries, batch operations). Use g method for business-logic methods on the service layer.

Usage

gofasta g repo-method <Resource> <Method> [param:type ...] [flags]

Flags

FlagDefaultDescription
--dry-runfalsePreview the patches without writing. Honors --json for a structured plan.

Examples

Add a FindByCustomer query:

gofasta g repo-method Order FindByCustomer customerID:uuid

Result — app/repositories/interfaces/order_repository.go:

type OrderRepositoryInterface interface { // ... existing methods preserved ... FindByCustomer(ctx context.Context, customerID uuid.UUID) error }

And app/repositories/order.repository.go:

// FindByCustomer is a generated stub. Replace with the real implementation. func (s *orderRepository) FindByCustomer(ctx context.Context, customerID uuid.UUID) error { return fmt.Errorf("OrderRepositoryInterface.FindByCustomer: not implemented") }

Add a method with no params:

gofasta g repo-method Order ArchiveAll

Preview without writing:

gofasta g repo-method Order BulkInsert --dry-run --json

Argument convention

Same as g method — every generated method takes ctx context.Context first, returns error last, with user-supplied args between.

Error codes

CodeWhen
RESOURCE_NOT_FOUNDThe interface or impl file is missing. Run gofasta g scaffold <Resource> first.
METHOD_ALREADY_EXISTSThe interface already declares a method by that name.
AST_PARSE_FAILEDOne of the target files has a syntax error.
Last updated on