diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 938397c..d59072b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -23,4 +23,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.60 \ No newline at end of file + version: latest + args: --timeout=5m diff --git a/Makefile b/Makefile index 36ac2ce..c93d2b3 100644 --- a/Makefile +++ b/Makefile @@ -26,3 +26,6 @@ test: fasttest: go test --tags skip_slow_test -v ./... + +lint: + golangci-lint run diff --git a/README.md b/README.md index 7791f54..0e460f9 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,7 @@ and `{}` for a mutually exclusive keyword. | Set type query parameter | `SET PARAM ;` | | | Set value query parameter | `SET PARAM = ;` | | | Show variables | `SHOW PARAMS;` | | +| Show DDLs | `SHOW DDLS;` | | ## Customize prompt diff --git a/statement.go b/statement.go index b834644..7a3c86b 100644 --- a/statement.go +++ b/statement.go @@ -170,6 +170,7 @@ var ( mutateRe = regexp.MustCompile(`(?is)MUTATE\s+(\S+)\s+(INSERT|UPDATE|INSERT_OR_UPDATE|REPLACE|DELETE)\s+(.+)$`) showQueryProfilesRe = regexp.MustCompile(`(?is)^SHOW\s+QUERY\s+PROFILES$`) showQueryProfileRe = regexp.MustCompile(`(?is)^SHOW\s+QUERY\s+PROFILE\s+(.*)$`) + showDdlsRe = regexp.MustCompile(`(?is)^SHOW\s+DDLS$`) ) var ( @@ -300,6 +301,8 @@ func BuildCLIStatement(trimmed string) (Statement, error) { return nil, err } return &ShowQueryProfileStatement{Fprint: fprint}, nil + case showDdlsRe.MatchString(trimmed): + return &ShowDdlsStatement{}, nil default: return nil, errStatementNotMatched } @@ -1415,6 +1418,26 @@ ORDER BY INTERVAL_END DESC`, return result, nil } +type ShowDdlsStatement struct{} + +func (s *ShowDdlsStatement) Execute(ctx context.Context, session *Session) (*Result, error) { + resp, err := session.adminClient.GetDatabaseDdl(ctx, &adminpb.GetDatabaseDdlRequest{ + Database: session.DatabasePath(), + }) + if err != nil { + return nil, err + } + + return &Result{ + KeepVariables: true, + // intentionally empty column name to make TAB format valid DDL + ColumnNames: sliceOf(""), + Rows: sliceOf(toRow(hiter.StringsCollect(0, xiter.Map( + func(s string) string { return s + ";\n" }, + slices.Values(resp.GetStatements()))))), + }, nil +} + type NopStatement struct{} func (s *NopStatement) Execute(ctx context.Context, session *Session) (*Result, error) { diff --git a/statement_test.go b/statement_test.go index b09a180..11332a5 100644 --- a/statement_test.go +++ b/statement_test.go @@ -632,6 +632,11 @@ func TestBuildStatement(t *testing.T) { input: `SHOW PARAMS`, want: &ShowParamsStatement{}, }, + { + desc: "SHOW DDLS statement", + input: `SHOW DDLS`, + want: &ShowDdlsStatement{}, + }, } { t.Run(test.desc, func(t *testing.T) { got, err := BuildStatement(test.input)