-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
67457: cli: extract the SQL connection code to a new package `clisqlclient` (2/) r=otan a=knz This is part of a family of PRs that aim to encapsulate CLI functionality into finer grained packages. Co-authored-by: Raphael 'kena' Poss <[email protected]>
- Loading branch information
Showing
51 changed files
with
1,621 additions
and
891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package cli | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/cli/clisqlclient" | ||
) | ||
|
||
// makeSQLConn creates a connection object from | ||
// a connection URL. | ||
// | ||
// This is the local variant of the function in the clisqlclient | ||
// package. | ||
func makeSQLConn(url string) clisqlclient.Conn { | ||
return clisqlclient.MakeSQLConn(url, | ||
cliCtx.isInteractive, | ||
&sqlCtx.enableServerExecutionTimings, | ||
sqlCtx.embeddedMode, | ||
&sqlCtx.echo, | ||
&sqlCtx.showTimes, | ||
&sqlCtx.verboseTimings, | ||
) | ||
} | ||
|
||
// PrintQueryOutput takes a list of column names and a list of row | ||
// contents writes a formatted table to 'w'. | ||
// | ||
// This is the local variant of the function in the clisqlclient | ||
// package. | ||
func PrintQueryOutput(w io.Writer, cols []string, allRows clisqlclient.RowStrIter) error { | ||
return clisqlclient.PrintQueryOutput(w, cols, allRows, | ||
cliCtx.tableDisplayFormat, | ||
cliCtx.tableBorderMode, | ||
) | ||
} | ||
|
||
// runQueryAndFormatResults takes a 'query' with optional 'parameters'. | ||
// It runs the sql query and writes output to 'w'. | ||
// | ||
// This is the local variant of the function in the clisqlclient | ||
// package. | ||
func runQueryAndFormatResults( | ||
conn clisqlclient.Conn, w io.Writer, fn clisqlclient.QueryFn, | ||
) (err error) { | ||
return clisqlclient.RunQueryAndFormatResults(conn, w, fn, | ||
cliCtx.tableDisplayFormat, | ||
cliCtx.tableBorderMode, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.