cloudspannerecosystem / yo

yo is a command-line tool to generate Go code for Google Cloud Spanner.
MIT License
312 stars 50 forks source link

May I kindly ask you to support View? #95

Open dulao5 opened 2 years ago

dulao5 commented 2 years ago

Objective

I want to aggregate the results of a Table Join with a view and process the query results using newHoge_Decoder.

Problem

The comment in internal.TypeLoader.LoadTable says "LoadTable loads a schema table/view definition."

https://github.com/cloudspannerecosystem/yo/blob/f04de876c09a8b5c7b0ed2296ea303934e78a741/internal/loader.go#L88-L89

But actually when processing a View, I get the following error.

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
go.mercari.io/yo/internal.(*TypeLoader).loadPrimaryKeys(0xc0001c1890?, 0xc000916200)
    go/1.18.1/pkg/mod/go.mercari.io/yo@v0.5.2/internal/loader.go:179 +0x212
go.mercari.io/yo/internal.(*TypeLoader).LoadTable(0xc0001c1890, 0x1ecc660)
    go/1.18.1/pkg/mod/go.mercari.io/yo@v0.5.2/internal/loader.go:133 +0x1a5
go.mercari.io/yo/internal.(*TypeLoader).LoadSchema(0x0?, 0xc00034b220?)
    go/1.18.1/pkg/mod/go.mercari.io/yo@v0.5.2/internal/loader.go:72 +0x27
go.mercari.io/yo/cmd.glob..func5(0x1ebeec0?, {0xc00034b220?, 0x5?, 0x5?})
    go/1.18.1/pkg/mod/go.mercari.io/yo@v0.5.2/cmd/root.go:83 +0x21f
github.com/spf13/cobra.(*Command).execute(0x1ebeec0, {0xc0001a8130, 0x5, 0x5})
    go/1.18.1/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:856 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0x1ebeec0)
    go/1.18.1/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
    go/1.18.1/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902
go.mercari.io/yo/cmd.Execute(...)
    go/1.18.1/pkg/mod/go.mercari.io/yo@v0.5.2/cmd/root.go:110
main.main()
    go/1.18.1/pkg/mod/go.mercari.io/yo@v0.5.2/main.go:30 +0x25
kazegusuri commented 2 years ago

Oh I didn't notice view feature was supported in Spanner. It seems the comment is derived from xo. Yo does not support view for now. I will definitely support view soon.