Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to output enum definitions in the db doc README #601

Merged
merged 4 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type MD struct {
Index string `yaml:"index,omitempty"`
Table string `yaml:"table,omitempty"`
Viewpoint string `yaml:"viewpoint,omitempty"`
Enum string `yaml:"enum,omitempty"`
}

// Dot holds the paths to the dot template files.
Expand Down
42 changes: 42 additions & 0 deletions drivers/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ ORDER BY tgrelid
}
s.Functions = functions

// Enums
enums, err := p.getEnums()
if err != nil {
return err
}
s.Enums = enums

s.Tables = tables

// Relations
Expand Down Expand Up @@ -490,6 +497,41 @@ func (p *Postgres) getFunctionsByQuery(query string) ([]*schema.Function, error)
return functions, nil
}

func (p *Postgres) getEnums() ([]*schema.Enum, error) {
enums := []*schema.Enum{}

enumsResult, err := p.db.Query(`SELECT n.nspname, t.typname AS enum_name, ARRAY_AGG(e.enumlabel) AS enum_values
FROM pg_type t, pg_enum e, pg_catalog.pg_namespace n
WHERE t.typcategory = 'E'
AND t.oid = e.enumtypid
AND n.oid = t.typnamespace
GROUP BY n.nspname, t.typname `)

if err != nil {
return nil, errors.WithStack(err)
}
defer enumsResult.Close()

for enumsResult.Next() {
var (
schemaName string
enumName string
enumValues []string
)
err := enumsResult.Scan(&schemaName, &enumName, pq.Array(&enumValues))
if err != nil {
return enums, errors.WithStack(err)
}

enum := &schema.Enum{
Name: fmt.Sprintf("%s.%s", schemaName, enumName),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 NICE 👍

Values: enumValues,
}
enums = append(enums, enum)
}
return enums, nil
}

func fullTableName(owner string, tableName string) string {
return fmt.Sprintf("%s.%s", owner, tableName)
}
Expand Down
77 changes: 41 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/k1LoW/tbls
go 1.22.7

require (
cloud.google.com/go/bigquery v1.62.0
cloud.google.com/go/spanner v1.67.0
github.com/ClickHouse/clickhouse-go/v2 v2.28.2
cloud.google.com/go/bigquery v1.63.0
cloud.google.com/go/spanner v1.68.0
github.com/ClickHouse/clickhouse-go/v2 v2.29.0
github.com/aquasecurity/go-version v0.0.0-20210121072130-637058cfe492
github.com/aws/aws-sdk-go v1.55.5
github.com/beta/freetype v0.0.1
Expand All @@ -25,7 +25,7 @@ require (
github.com/lib/pq v1.10.9
github.com/loadoff/excl v0.0.0-20171207172601-c6a9e4c4b4c4
github.com/mattn/go-runewidth v0.0.16
github.com/mattn/go-sqlite3 v1.14.22
github.com/mattn/go-sqlite3 v1.14.23
github.com/microsoft/go-mssqldb v1.7.2
github.com/minio/pkg v1.7.5
github.com/olekukonko/tablewriter v0.0.5
Expand All @@ -36,19 +36,20 @@ require (
github.com/tenntenn/golden v0.5.4
github.com/xo/dburl v0.23.2
gitlab.com/golang-commonmark/mdurl v0.0.0-20191124015652-932350d1cb84
go.mongodb.org/mongo-driver v1.16.1
golang.org/x/image v0.19.0
golang.org/x/oauth2 v0.22.0
google.golang.org/api v0.191.0
go.mongodb.org/mongo-driver v1.17.0
golang.org/x/image v0.20.0
golang.org/x/oauth2 v0.23.0
google.golang.org/api v0.197.0
)

require (
cel.dev/expr v0.15.0 // indirect
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.8.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect
cel.dev/expr v0.16.0 // indirect
cloud.google.com/go v0.115.1 // indirect
cloud.google.com/go/auth v0.9.3 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.12 // indirect
cloud.google.com/go/iam v1.2.1 // indirect
cloud.google.com/go/monitoring v1.21.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand All @@ -57,6 +58,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.1 // indirect
github.com/ClickHouse/ch-go v0.61.5 // indirect
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.1 // indirect
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/apache/arrow/go/v15 v15.0.2 // indirect
Expand All @@ -79,11 +81,11 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cli/go-gh/v2 v2.6.0 // indirect
github.com/cli/safeexec v1.0.1 // indirect
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b // indirect
github.com/cncf/xds/go v0.0.0-20240822171458-6449f94b4d59 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/envoyproxy/go-control-plane v0.13.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fogleman/gg v1.3.0 // indirect
Expand All @@ -100,15 +102,14 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v23.5.26+incompatible // indirect
github.com/google/go-github/v58 v58.0.0 // indirect
github.com/google/go-github/v60 v60.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -126,6 +127,7 @@ require (
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
Expand All @@ -136,29 +138,32 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 // indirect
google.golang.org/genproto v0.0.0-20240730163845-b1a4ccb954bf // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect
google.golang.org/grpc v1.64.1 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading