Documentation
¶
Overview ¶
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 Google LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
System Variables Naming Convention: - Variables that correspond to java-spanner JDBC properties use the same names - Variables that are spanner-mycli specific MUST use CLI_ prefix - This ensures compatibility with existing JDBC tooling while clearly identifying custom extensions
This file contains the registry-based implementation of system variables ¶
InterceptorLogger adapts zap logger to interceptor logger.
Index ¶
- Constants
- Variables
- func GetExitCode(err error) int
- func GetTerminalSize(w io.Writer) (int, error)
- func InterceptorLogger(l *zap.Logger) logging.Logger
- func IsMetaCommand(line string) bool
- func LinkTypePred(typ string) func(cl *sppb.PlanNode_ChildLink) bool
- func ListAvailableSamples() string
- func Main(version, installFrom string)
- func NewExitCodeError(exitCode int) error
- func PS1PS2FuncToPromptFunc(ps1F func() string, ps2F func(ps1 string) string) func(w io.Writer, lnum int) (int, error)
- func ParseStatements(content []byte, filename string) ([]string, error)
- func SetLogLevel(logLevel string) (slog.Level, error)
- func ValidateSpannerOptions(opts *spannerOptions) error
- type AbortBatchStatement
- type AddSplitPointsStatement
- type BatchDMLStatement
- type BatchInfo
- type BeginRoStatement
- type BeginRwStatement
- type BeginStatement
- type BufferedProcessor
- type BulkDdlStatement
- type CQLStatement
- type Cli
- func (c *Cli) ExitOnError(err error) int
- func (c *Cli) GetErrStream() io.Writer
- func (c *Cli) GetInStream() io.ReadCloser
- func (c *Cli) GetTerminalSizeWithTty(w io.Writer) (int, error)
- func (c *Cli) GetTtyStream() *os.File
- func (c *Cli) GetWriter() io.Writer
- func (c *Cli) PrintBatchError(err error)
- func (c *Cli) PrintInteractiveError(err error)
- func (c *Cli) PrintProgressingMark(w io.Writer) func()
- func (c *Cli) PrintResult(screenWidth int, result *Result, interactive bool, input string, w io.Writer) error
- func (c *Cli) RunBatch(ctx context.Context, input string) error
- func (c *Cli) RunInteractive(ctx context.Context) error
- func (c *Cli) RunMCP(ctx context.Context) error
- type CommitStatement
- type CreateDatabaseStatement
- type CustomVar
- type DMLResult
- type DdlStatement
- type DependencyResolver
- func (dr *DependencyResolver) BuildDependencyGraphWithTxn(ctx context.Context, txn *spanner.ReadOnlyTransaction) error
- func (dr *DependencyResolver) GetDependencyInfo(tableName string) (*TableDependency, error)
- func (dr *DependencyResolver) GetOrderForTables(tablesToExport []string) ([]string, error)
- func (dr *DependencyResolver) GetTableOrder() ([]string, error)
- type DescribeStatement
- type DetachStatement
- type DetachedCompatible
- type DisableOutputRedirectMetaCommand
- type DisableTeeMetaCommand
- type DmlStatement
- type DropDatabaseStatement
- type DumpDatabaseStatement
- type DumpSchemaStatement
- type DumpTablesStatement
- type EndpointVar
- type EnumVar
- func AutocommitDMLModeVar(ptr *enums.AutocommitDMLMode, desc string) *EnumVar[enums.AutocommitDMLMode]
- func DisplayModeVar(ptr *enums.DisplayMode, desc string) *EnumVar[enums.DisplayMode]
- func ExplainFormatVar(ptr *enums.ExplainFormat, desc string) *EnumVar[enums.ExplainFormat]
- func ParseModeVar(ptr *enums.ParseMode, desc string) *EnumVar[enums.ParseMode]
- func StreamingModeVar(ptr *enums.StreamingMode, desc string) *EnumVar[enums.StreamingMode]
- type ErrAddNotSupported
- type ErrUnknownVariable
- type ExecuteStatementArgs
- type ExitCodeError
- type ExitStatement
- type ExplainAnalyzeDmlStatement
- type ExplainAnalyzeStatement
- type ExplainLastQueryStatement
- type ExplainStatement
- type FKReference
- type GeminiStatement
- type HelpStatement
- type HelpVariablesStatement
- type History
- type IntGetterVar
- type LastQueryCache
- type LogLevelVar
- type MetaCommandStatement
- type MutateStatement
- type MutationStatement
- type NopStatement
- type OutputContext
- type OutputRedirectMetaCommand
- type PartitionStatement
- type PartitionedDmlStatement
- type PromptMetaCommand
- type ProtoDescriptorVar
- type ProtoEnumVar
- func DatabaseDialectVar(ptr *databasepb.DatabaseDialect, desc string) *ProtoEnumVar[databasepb.DatabaseDialect]
- func IsolationLevelVar(ptr *sppb.TransactionOptions_IsolationLevel, desc string) *ProtoEnumVar[sppb.TransactionOptions_IsolationLevel]
- func QueryModeVar(ptr *sppb.ExecuteSqlRequest_QueryMode, desc string) *ProtoEnumVar[sppb.ExecuteSqlRequest_QueryMode]
- func RPCPriorityVar(ptr *sppb.RequestOptions_Priority, desc string) *ProtoEnumVar[sppb.RequestOptions_Priority]
- func ReadLockModeVar(ptr *sppb.TransactionOptions_ReadWrite_ReadLockMode, desc string) *ProtoEnumVar[sppb.TransactionOptions_ReadWrite_ReadLockMode]
- type QueryIndexAdvice
- type QueryResult
- type QueryStats
- type ReadOnlyVar
- type Result
- type RollbackStatement
- type Row
- type RowIterResult
- type RowProcessor
- type RunBatchStatement
- type RunPartitionStatement
- type RunPartitionedQueryStatement
- type SampleDatabase
- type SelectStatement
- type Session
- func (s *Session) BeginPendingTransaction(ctx context.Context, isolationLevel sppb.TransactionOptions_IsolationLevel, ...) error
- func (s *Session) BeginReadOnlyTransaction(ctx context.Context, typ timestampBoundType, staleness time.Duration, ...) (time.Time, error)
- func (s *Session) BeginReadOnlyTransactionLocked(ctx context.Context, typ timestampBoundType, staleness time.Duration, ...) (time.Time, error)
- func (s *Session) BeginReadWriteTransaction(ctx context.Context, isolationLevel sppb.TransactionOptions_IsolationLevel, ...) error
- func (s *Session) BeginReadWriteTransactionLocked(ctx context.Context, isolationLevel sppb.TransactionOptions_IsolationLevel, ...) error
- func (s *Session) Close()
- func (s *Session) ClosePendingTransaction() error
- func (s *Session) CloseReadOnlyTransaction() error
- func (s *Session) CommitReadWriteTransaction(ctx context.Context) (spanner.CommitResponse, error)
- func (s *Session) CommitReadWriteTransactionLocked(ctx context.Context) (spanner.CommitResponse, error)
- func (s *Session) ConnectToDatabase(ctx context.Context, databaseId string) error
- func (s *Session) DatabaseExists(ctx context.Context) (bool, error)
- func (s *Session) DatabasePath() string
- func (s *Session) DetermineTransaction(ctx context.Context) (time.Time, error)
- func (s *Session) DetermineTransactionAndState(ctx context.Context) (time.Time, bool, error)
- func (s *Session) DetermineTransactionLocked(ctx context.Context) (time.Time, error)
- func (s *Session) ExecuteStatement(ctx context.Context, stmt Statement) (result *Result, err error)
- func (s *Session) GetDatabaseSchema(ctx context.Context) ([]string, *descriptorpb.FileDescriptorSet, error)
- func (s *Session) GetTransactionFlagsWithLock() (inTransaction bool, inReadWriteTransaction bool)
- func (s *Session) InPendingTransaction() bool
- func (s *Session) InReadOnlyTransaction() bool
- func (s *Session) InReadWriteTransaction() bool
- func (s *Session) InTransaction() bool
- func (s *Session) IncrementSchemaGeneration()
- func (s *Session) InstanceExists() (bool, error)
- func (s *Session) InstancePath() string
- func (s *Session) IsDetached() bool
- func (s *Session) Mode() SessionMode
- func (s *Session) NewTransactionOptionsBuilder() *TransactionOptionsBuilder
- func (s *Session) RecreateClient() error
- func (s *Session) RequiresDatabaseConnection() bool
- func (s *Session) RollbackReadWriteTransaction(ctx context.Context) error
- func (s *Session) RollbackReadWriteTransactionLocked(ctx context.Context) error
- func (s *Session) RunAnalyzeQuery(ctx context.Context, stmt spanner.Statement) (*sppb.QueryPlan, *sppb.ResultSetMetadata, error)
- func (s *Session) RunInNewOrExistRwTx(ctx context.Context, ...) (*DMLResult, error)
- func (s *Session) RunInNewOrExistRwTxLocked(ctx context.Context, ...) (*DMLResult, error)
- func (s *Session) RunPartitionQuery(ctx context.Context, stmt spanner.Statement) ([]*spanner.Partition, *spanner.BatchReadOnlyTransaction, error)
- func (s *Session) RunQuery(ctx context.Context, stmt spanner.Statement) (*spanner.RowIterator, *spanner.ReadOnlyTransaction)
- func (s *Session) RunQueryWithStats(ctx context.Context, stmt spanner.Statement, implicit bool) (*spanner.RowIterator, *spanner.ReadOnlyTransaction)
- func (s *Session) RunUpdate(ctx context.Context, stmt spanner.Statement, implicit bool) ([]Row, map[string]any, int64, *sppb.ResultSetMetadata, *sppb.QueryPlan, error)
- func (s *Session) SchemaGeneration() uint64
- func (s *Session) TransactionAttrsWithLock() transactionAttributes
- func (s *Session) TransactionMode() transactionMode
- func (s *Session) TransactionState() (mode transactionMode, isActive bool)
- func (s *Session) TransitTransaction(ctx context.Context, ...) error
- func (s *Session) ValidateDatabaseOperation() error
- func (s *Session) ValidateDetachedOperation() error
- func (s *Session) ValidateStatementExecution(stmt Statement) error
- type SessionHandler
- type SessionMode
- type SetAddStatement
- type SetParamTypeStatement
- type SetParamValueStatement
- type SetStatement
- type SetTransactionStatement
- type ShellMetaCommand
- type ShowColumnsStatement
- type ShowCreateStatement
- type ShowDatabasesStatement
- type ShowDdlsStatement
- type ShowIndexStatement
- type ShowLocalProtoStatement
- type ShowOperationStatement
- type ShowParamsStatement
- type ShowPlanNodeStatement
- type ShowQueryProfileStatement
- type ShowQueryProfilesStatement
- type ShowRemoteProtoStatement
- type ShowSchemaUpdateOperations
- type ShowSplitPointsStatement
- type ShowTablesStatement
- type ShowVariableStatement
- type ShowVariablesStatement
- type SourceMetaCommand
- type StartBatchStatement
- type Statement
- func BuildCLIStatement(stripped, raw string) (Statement, error)
- func BuildNativeStatementLexical(stripped string, raw string) (Statement, error)
- func BuildNativeStatementMemefish(stripped, raw string) (Statement, error)
- func BuildStatement(input string) (Statement, error)
- func BuildStatementWithComments(stripped, raw string) (Statement, error)
- func BuildStatementWithCommentsWithMode(stripped, raw string, mode enums.ParseMode) (Statement, error)
- func ParseMetaCommand(input string) (Statement, error)
- type StreamingProcessor
- type SyncProtoStatement
- type TableDependency
- type TableHeader
- type TablePreviewProcessor
- type TeeOutputMetaCommand
- type TemplateVar
- type TimestampBoundVar
- type TimestampVar
- type TransactionOptionsBuilder
- func (b *TransactionOptionsBuilder) Build() spanner.TransactionOptions
- func (b *TransactionOptionsBuilder) BuildIsolationLevel() sppb.TransactionOptions_IsolationLevel
- func (b *TransactionOptionsBuilder) BuildPriority() sppb.RequestOptions_Priority
- func (b *TransactionOptionsBuilder) WithIsolationLevel(level sppb.TransactionOptions_IsolationLevel) *TransactionOptionsBuilder
- func (b *TransactionOptionsBuilder) WithPriority(priority sppb.RequestOptions_Priority) *TransactionOptionsBuilder
- func (b *TransactionOptionsBuilder) WithTag(tag string) *TransactionOptionsBuilder
- type TruncateTableStatement
- type TryPartitionedQueryStatement
- type UnimplementedVar
- type UnsetParamStatement
- type UpdateResult
- type UseDatabaseMetaCommand
- type UseStatement
- type ValidValuesEnumerator
- type VarHandler
- func BoolVar(ptr *bool, desc string) *VarHandler[bool]
- func IntVar(ptr *int64, desc string) *VarHandler[int64]
- func NullableDurationVar(ptr **time.Duration, desc string) *VarHandler[*time.Duration]
- func NullableIntVar(ptr **int64, desc string) *VarHandler[*int64]
- func StringVar(ptr *string, desc string) *VarHandler[string]
- func (h *VarHandler[T]) AsReadOnly() *VarHandler[T]
- func (h *VarHandler[T]) Description() string
- func (h *VarHandler[T]) Get() (string, error)
- func (h *VarHandler[T]) IsReadOnly() bool
- func (h *VarHandler[T]) Set(value string) error
- func (h *VarHandler[T]) ValidValues() []string
- func (h *VarHandler[T]) WithValidator(validate func(T) error) *VarHandler[T]
- type VarRegistry
- func (r *VarRegistry) Add(name, value string) error
- func (r *VarRegistry) Get(name string) (string, error)
- func (r *VarRegistry) GetDescription(name string) (string, error)
- func (r *VarRegistry) GetVariable(name string) Variable
- func (r *VarRegistry) IsReadOnly(name string) (bool, error)
- func (r *VarRegistry) ListVariableInfo() map[string]struct{ ... }
- func (r *VarRegistry) ListVariables() map[string]string
- func (r *VarRegistry) Register(name string, v Variable)
- func (r *VarRegistry) RegisterWithAdd(name string, v Variable, addFunc func(string) error)
- func (r *VarRegistry) Set(name, value string, isGoogleSQL bool) error
- type Variable
Constants ¶
const (
DefaultAnalyzeColumns = "Rows:{{.Rows.Total}},Exec.:{{.ExecutionSummary.NumExecutions}},Total Latency:{{.Latency}}"
)
Variables ¶
var ( ErrNoTransaction = errors.New("no active transaction") ErrNotInReadWriteTransaction = errors.New("not in read-write transaction") ErrNotInReadOnlyTransaction = errors.New("not in read-only transaction") ErrNotInPendingTransaction = errors.New("not in pending transaction") )
Transaction state errors
var DefaultParsedAnalyzeColumns = lo.Must(customListToTableRenderDefs(DefaultAnalyzeColumns))
Functions ¶
func GetExitCode ¶
GetExitCode returns the appropriate exit code based on the error type. It checks for ExitCodeError first and returns its exit code if found. Otherwise, it returns exitCodeSuccess for nil errors and exitCodeError for all other errors.
In the future, this function could be further enhanced to return different exit codes based on other error types, such as:
var validationErr *ValidationError
if errors.As(err, &validationErr) {
return exitCodeValidationError // e.g., 2
}
This would require defining additional exit code constants.
func GetTerminalSize ¶
GetTerminalSize returns the width of the terminal for the given io.Writer. It attempts to type assert the writer to *os.File to get the file descriptor. Returns an error if the terminal size cannot be determined.
func InterceptorLogger ¶
This code is simple enough to be copied and not imported.
func IsMetaCommand ¶
IsMetaCommand checks if a line starts with a backslash (meta command)
func LinkTypePred ¶
func LinkTypePred(typ string) func(cl *sppb.PlanNode_ChildLink) bool
func ListAvailableSamples ¶
func ListAvailableSamples() string
ListAvailableSamples returns a formatted list of available sample databases
func Main ¶
func Main(version, installFrom string)
Main is the entry point called from the root main package. version and installFrom are passed from main via ldflags.
func NewExitCodeError ¶
NewExitCodeError creates a new ExitCodeError
func PS1PS2FuncToPromptFunc ¶
func ParseStatements ¶
ParseStatements parses DDL or DML statements from SQL/SDL content using memefish
func ValidateSpannerOptions ¶
func ValidateSpannerOptions(opts *spannerOptions) error
ValidateSpannerOptions validates the spannerOptions struct.
Types ¶
type AbortBatchStatement ¶
type AbortBatchStatement struct{}
type AddSplitPointsStatement ¶
type AddSplitPointsStatement struct {
SplitPoints []*databasepb.SplitPoints
}
type BatchDMLStatement ¶
func (BatchDMLStatement) IsMutationStatement ¶
func (BatchDMLStatement) IsMutationStatement()
type BeginRoStatement ¶
type BeginRwStatement ¶
type BeginRwStatement struct {
IsolationLevel sppb.TransactionOptions_IsolationLevel
Priority sppb.RequestOptions_Priority
}
type BeginStatement ¶
type BeginStatement struct {
IsolationLevel sppb.TransactionOptions_IsolationLevel
Priority sppb.RequestOptions_Priority
}
type BufferedProcessor ¶
type BufferedProcessor struct {
// contains filtered or unexported fields
}
BufferedProcessor collects all rows in memory before formatting. This is the traditional approach used by spanner-mycli.
func NewBufferedProcessor ¶
func NewBufferedProcessor(formatter format.FormatFunc, out io.Writer, screenWidth int) *BufferedProcessor
NewBufferedProcessor creates a processor that collects all rows before formatting.
func (*BufferedProcessor) Finish ¶
func (p *BufferedProcessor) Finish(stats QueryStats, rowCount int64) error
Finish formats and outputs all collected rows.
func (*BufferedProcessor) Init ¶
func (p *BufferedProcessor) Init(metadata *sppb.ResultSetMetadata, sysVars *systemVariables) error
Init initializes the buffered processor with metadata.
func (*BufferedProcessor) ProcessRow ¶
func (p *BufferedProcessor) ProcessRow(row Row) error
ProcessRow adds a row to the buffer.
type BulkDdlStatement ¶
type BulkDdlStatement struct {
Ddls []string
}
func (BulkDdlStatement) IsMutationStatement ¶
func (BulkDdlStatement) IsMutationStatement()
func (*BulkDdlStatement) String ¶
func (s *BulkDdlStatement) String() string
type Cli ¶
type Cli struct {
SessionHandler *SessionHandler
Credential []byte
SystemVariables *systemVariables
// contains filtered or unexported fields
}
func (*Cli) ExitOnError ¶
func (*Cli) GetErrStream ¶
GetErrStream returns the error stream
func (*Cli) GetInStream ¶
func (c *Cli) GetInStream() io.ReadCloser
GetInStream returns the input stream
func (*Cli) GetTerminalSizeWithTty ¶
GetTerminalSizeWithTty returns the width of the terminal. It uses the TtyOutStream from StreamManager if available, otherwise falls back to attempting to type assert the writer to *os.File. Returns an error if the terminal size cannot be determined.
func (*Cli) GetTtyStream ¶
GetTtyStream returns the TTY stream for terminal operations
func (*Cli) PrintBatchError ¶
func (*Cli) PrintInteractiveError ¶
func (*Cli) PrintProgressingMark ¶
func (*Cli) PrintResult ¶
type CommitStatement ¶
type CommitStatement struct{}
type CreateDatabaseStatement ¶
type CreateDatabaseStatement struct {
CreateStatement string
}
func (CreateDatabaseStatement) IsMutationStatement ¶
func (CreateDatabaseStatement) IsMutationStatement()
func (*CreateDatabaseStatement) String ¶
func (s *CreateDatabaseStatement) String() string
type CustomVar ¶
type CustomVar struct {
// contains filtered or unexported fields
}
CustomVar wraps a variable with custom getter/setter
func (*CustomVar) Description ¶
func (*CustomVar) IsReadOnly ¶
type DMLResult ¶
type DMLResult struct {
Affected int64 // Total number of rows affected by the DML operation
CommitResponse spanner.CommitResponse // Commit response including timestamp and stats
Plan *sppb.QueryPlan // Query execution plan (when requested)
Metadata *sppb.ResultSetMetadata // Metadata about the result set
}
DMLResult holds the results of a DML operation execution including commit information.
type DdlStatement ¶
type DdlStatement struct {
Ddl string
}
func (*DdlStatement) String ¶
func (s *DdlStatement) String() string
type DependencyResolver ¶
type DependencyResolver struct {
// contains filtered or unexported fields
}
DependencyResolver manages table dependency resolution Note: This implementation works at the table level. For row-level dependency resolution that can handle circular FK relationships, see issue #438.
func NewDependencyResolver ¶
func NewDependencyResolver() *DependencyResolver
NewDependencyResolver creates a new dependency resolver
func (*DependencyResolver) BuildDependencyGraphWithTxn ¶
func (dr *DependencyResolver) BuildDependencyGraphWithTxn(ctx context.Context, txn *spanner.ReadOnlyTransaction) error
BuildDependencyGraphWithTxn queries the database and builds the complete dependency graph using a transaction
func (*DependencyResolver) GetDependencyInfo ¶
func (dr *DependencyResolver) GetDependencyInfo(tableName string) (*TableDependency, error)
GetDependencyInfo returns detailed dependency information for a table
func (*DependencyResolver) GetOrderForTables ¶
func (dr *DependencyResolver) GetOrderForTables(tablesToExport []string) ([]string, error)
GetOrderForTables returns specific tables in safe execution order
func (*DependencyResolver) GetTableOrder ¶
func (dr *DependencyResolver) GetTableOrder() ([]string, error)
GetTableOrder returns all tables in safe execution order. It assumes that BuildDependencyGraph has already been called.
type DescribeStatement ¶
type DescribeStatement struct {
Statement string
IsDML bool // Whether the statement being described is a DML
}
func (*DescribeStatement) String ¶
func (s *DescribeStatement) String() string
type DetachStatement ¶
type DetachStatement struct {
NopStatement
}
DetachStatement is actually implemented in cli.go because it needs to replace Session pointer in Cli.
type DetachedCompatible ¶
type DetachedCompatible interface {
// contains filtered or unexported methods
}
DetachedCompatible is a marker interface for statements that can run in Detached session mode (admin operation only mode). Statements implementing this interface can execute when session.IsDetached() is true.
type DisableOutputRedirectMetaCommand ¶
type DisableOutputRedirectMetaCommand struct{}
DisableOutputRedirectMetaCommand disables output redirect using \o (with no args) syntax
type DisableTeeMetaCommand ¶
type DisableTeeMetaCommand struct{}
DisableTeeMetaCommand disables output tee using \t syntax
type DmlStatement ¶
type DmlStatement struct {
Dml string
}
func (*DmlStatement) String ¶
func (s *DmlStatement) String() string
type DropDatabaseStatement ¶
type DropDatabaseStatement struct {
DatabaseId string
}
type DumpDatabaseStatement ¶
type DumpDatabaseStatement struct{}
DumpDatabaseStatement represents DUMP DATABASE statement It exports both DDL and data for all tables in the database
type DumpSchemaStatement ¶
type DumpSchemaStatement struct{}
DumpSchemaStatement represents DUMP SCHEMA statement It exports only DDL statements without any data
type DumpTablesStatement ¶
type DumpTablesStatement struct {
Tables []string
}
DumpTablesStatement represents DUMP TABLES statement It exports data only for specified tables (no DDL)
type EndpointVar ¶
type EndpointVar struct {
// contains filtered or unexported fields
}
EndpointVar handles CLI_ENDPOINT (host:port)
func (*EndpointVar) Description ¶
func (e *EndpointVar) Description() string
func (*EndpointVar) Get ¶
func (e *EndpointVar) Get() (string, error)
func (*EndpointVar) IsReadOnly ¶
func (e *EndpointVar) IsReadOnly() bool
func (*EndpointVar) Set ¶
func (e *EndpointVar) Set(value string) error
type EnumVar ¶
type EnumVar[T comparable] struct { // contains filtered or unexported fields }
EnumVar handles enum-like variables
func AutocommitDMLModeVar ¶
func AutocommitDMLModeVar(ptr *enums.AutocommitDMLMode, desc string) *EnumVar[enums.AutocommitDMLMode]
AutocommitDMLModeVar handles AUTOCOMMIT_DML_MODE using enumer-generated methods
func DisplayModeVar ¶
func DisplayModeVar(ptr *enums.DisplayMode, desc string) *EnumVar[enums.DisplayMode]
DisplayModeVar creates an enum handler for DisplayMode
func ExplainFormatVar ¶
func ExplainFormatVar(ptr *enums.ExplainFormat, desc string) *EnumVar[enums.ExplainFormat]
ExplainFormatVar creates an enum handler for ExplainFormat
func ParseModeVar ¶
ParseModeVar creates an enum handler for ParseMode
func StreamingModeVar ¶
func StreamingModeVar(ptr *enums.StreamingMode, desc string) *EnumVar[enums.StreamingMode]
StreamingModeVar creates an enum handler for StreamingMode
func (*EnumVar[T]) Description ¶
func (*EnumVar[T]) IsReadOnly ¶
func (*EnumVar[T]) ValidValues ¶
ValidValues returns sorted valid values as GoogleSQL string literals.
type ErrAddNotSupported ¶
type ErrAddNotSupported struct {
Name string
}
ErrAddNotSupported is returned when ADD operation is not supported for a variable
func (*ErrAddNotSupported) Error ¶
func (e *ErrAddNotSupported) Error() string
type ErrUnknownVariable ¶
type ErrUnknownVariable struct {
Name string
}
ErrUnknownVariable is returned when a variable name is not recognized
func (*ErrUnknownVariable) Error ¶
func (e *ErrUnknownVariable) Error() string
type ExecuteStatementArgs ¶
type ExecuteStatementArgs struct {
Statement string `json:"statement" jsonschema:"Valid spanner-mycli statement to execute"`
}
ExecuteStatementArgs represents the arguments for the execute_statement tool
type ExitCodeError ¶
type ExitCodeError struct {
// contains filtered or unexported fields
}
ExitCodeError represents an error that only carries an exit code without a message
func (*ExitCodeError) Error ¶
func (e *ExitCodeError) Error() string
Error implements the error interface
type ExitStatement ¶
type ExitStatement struct {
NopStatement
}
type ExplainAnalyzeDmlStatement ¶
type ExplainAnalyzeDmlStatement struct {
Dml string
Format enums.ExplainFormat
Width int64
}
type ExplainAnalyzeStatement ¶
type ExplainAnalyzeStatement struct {
Query string
Format enums.ExplainFormat
Width int64
}
type ExplainLastQueryStatement ¶
type ExplainLastQueryStatement struct {
Analyze bool
Format enums.ExplainFormat
Width int64
}
type ExplainStatement ¶
type ExplainStatement struct {
Explain string
IsDML bool // Whether the statement being explained is a DML
Format enums.ExplainFormat
Width int64
}
func (*ExplainStatement) String ¶
func (s *ExplainStatement) String() string
type FKReference ¶
type FKReference struct {
ConstraintName string `spanner:"CONSTRAINT_NAME"`
ChildTable string `spanner:"CHILD_TABLE"`
ParentTable string `spanner:"PARENT_TABLE"`
}
FKReference represents a foreign key relationship between tables
type GeminiStatement ¶
type GeminiStatement struct {
Text string
}
type HelpStatement ¶
type HelpStatement struct{}
type HelpVariablesStatement ¶
type HelpVariablesStatement struct{}
type IntGetterVar ¶
type IntGetterVar struct {
// contains filtered or unexported fields
}
IntGetterVar handles integer variables with custom getters
func (*IntGetterVar) Description ¶
func (i *IntGetterVar) Description() string
func (*IntGetterVar) Get ¶
func (i *IntGetterVar) Get() (string, error)
func (*IntGetterVar) IsReadOnly ¶
func (i *IntGetterVar) IsReadOnly() bool
func (*IntGetterVar) Set ¶
func (i *IntGetterVar) Set(value string) error
type LastQueryCache ¶
type LogLevelVar ¶
type LogLevelVar struct {
// contains filtered or unexported fields
}
LogLevelVar handles CLI_LOG_LEVEL
func (*LogLevelVar) Description ¶
func (l *LogLevelVar) Description() string
func (*LogLevelVar) Get ¶
func (l *LogLevelVar) Get() (string, error)
func (*LogLevelVar) IsReadOnly ¶
func (l *LogLevelVar) IsReadOnly() bool
func (*LogLevelVar) Set ¶
func (l *LogLevelVar) Set(value string) error
func (*LogLevelVar) ValidValues ¶
func (l *LogLevelVar) ValidValues() []string
ValidValues returns the standard log level names as GoogleSQL string literals.
type MetaCommandStatement ¶
type MetaCommandStatement interface {
Statement
// contains filtered or unexported methods
}
MetaCommandStatement is a marker interface for meta commands (commands starting with \). Meta commands are not SQL statements and have special handling in the CLI.
type MutateStatement ¶
type MutationStatement ¶
type MutationStatement interface {
// contains filtered or unexported methods
}
MutationStatement is a marker interface for mutation statements. Mutation statements are not permitted in a read-only transaction. It determines pending transactions.
type NopStatement ¶
type NopStatement struct{}
type OutputContext ¶
type OutputContext struct {
Verbose bool
IsExecutedDML bool
ReadTimestamp string
CommitTimestamp string
Stats *QueryStats
CommitStats *sppb.CommitResponse_CommitStats
Metrics *metrics.ExecutionMetrics
}
type OutputRedirectMetaCommand ¶
type OutputRedirectMetaCommand struct {
FilePath string
}
OutputRedirectMetaCommand redirects output to a file using \o syntax (PostgreSQL-style: file only)
type PartitionStatement ¶
type PartitionStatement struct{ SQL string }
type PartitionedDmlStatement ¶
type PartitionedDmlStatement struct {
Dml string
}
type PromptMetaCommand ¶
type PromptMetaCommand struct {
PromptString string
}
PromptMetaCommand changes the prompt string using \R syntax
type ProtoDescriptorVar ¶
type ProtoDescriptorVar struct {
// contains filtered or unexported fields
}
ProtoDescriptorVar handles CLI_PROTO_DESCRIPTOR_FILE with ADD support
func (*ProtoDescriptorVar) Add ¶
func (p *ProtoDescriptorVar) Add(value string) error
func (*ProtoDescriptorVar) Description ¶
func (p *ProtoDescriptorVar) Description() string
func (*ProtoDescriptorVar) Get ¶
func (p *ProtoDescriptorVar) Get() (string, error)
func (*ProtoDescriptorVar) IsReadOnly ¶
func (p *ProtoDescriptorVar) IsReadOnly() bool
func (*ProtoDescriptorVar) Set ¶
func (p *ProtoDescriptorVar) Set(value string) error
type ProtoEnumVar ¶
type ProtoEnumVar[T ~int32] struct { // contains filtered or unexported fields }
ProtoEnumVar handles Protocol Buffer enum variables
func DatabaseDialectVar ¶
func DatabaseDialectVar(ptr *databasepb.DatabaseDialect, desc string) *ProtoEnumVar[databasepb.DatabaseDialect]
func IsolationLevelVar ¶
func IsolationLevelVar(ptr *sppb.TransactionOptions_IsolationLevel, desc string) *ProtoEnumVar[sppb.TransactionOptions_IsolationLevel]
func QueryModeVar ¶
func QueryModeVar(ptr *sppb.ExecuteSqlRequest_QueryMode, desc string) *ProtoEnumVar[sppb.ExecuteSqlRequest_QueryMode]
func RPCPriorityVar ¶
func RPCPriorityVar(ptr *sppb.RequestOptions_Priority, desc string) *ProtoEnumVar[sppb.RequestOptions_Priority]
func ReadLockModeVar ¶
func ReadLockModeVar(ptr *sppb.TransactionOptions_ReadWrite_ReadLockMode, desc string) *ProtoEnumVar[sppb.TransactionOptions_ReadWrite_ReadLockMode]
ReadLockModeVar creates an enum handler for ReadLockMode
func (*ProtoEnumVar[T]) Description ¶
func (p *ProtoEnumVar[T]) Description() string
func (*ProtoEnumVar[T]) Get ¶
func (p *ProtoEnumVar[T]) Get() (string, error)
func (*ProtoEnumVar[T]) IsReadOnly ¶
func (p *ProtoEnumVar[T]) IsReadOnly() bool
func (*ProtoEnumVar[T]) Set ¶
func (p *ProtoEnumVar[T]) Set(value string) error
func (*ProtoEnumVar[T]) ValidValues ¶
func (p *ProtoEnumVar[T]) ValidValues() []string
ValidValues returns sorted prefix-stripped valid values as GoogleSQL string literals.
type QueryIndexAdvice ¶
QueryIndexAdvice holds an index recommendation from the Spanner query advisor.
type QueryResult ¶
type QueryResult struct {
Iterator *spanner.RowIterator
Transaction *spanner.ReadOnlyTransaction
}
QueryResult holds the result of a query operation with optional transaction.
type QueryStats ¶
type QueryStats struct {
ElapsedTime string `json:"elapsed_time"`
CPUTime string `json:"cpu_time"`
RowsReturned string `json:"rows_returned"`
RowsScanned string `json:"rows_scanned"`
DeletedRowsScanned string `json:"deleted_rows_scanned"`
OptimizerVersion string `json:"optimizer_version"`
OptimizerStatisticsPackage string `json:"optimizer_statistics_package"`
RemoteServerCalls string `json:"remote_server_calls"`
MemoryPeakUsageBytes string `json:"memory_peak_usage_bytes"`
TotalMemoryPeakUsageByte string `json:"total_memory_peak_usage_byte"`
QueryText string `json:"query_text"`
BytesReturned string `json:"bytes_returned"`
RuntimeCreationTime string `json:"runtime_creation_time"`
StatisticsLoadTime string `json:"statistics_load_time"`
MemoryUsagePercentage string `json:"memory_usage_percentage"`
FilesystemDelaySeconds string `json:"filesystem_delay_seconds"`
LockingDelay string `json:"locking_delay"`
QueryPlanCreationTime string `json:"query_plan_creation_time"`
ServerQueueDelay string `json:"server_queue_delay"`
DataBytesRead string `json:"data_bytes_read"`
IsGraphQuery string `json:"is_graph_query"`
RuntimeCached string `json:"runtime_cached"`
QueryPlanCached string `json:"query_plan_cached"`
Unknown jsontext.Value `json:",unknown" pp:"-"`
}
QueryStats contains query statistics. Some fields may not have a valid value depending on the environment. For example, only ElapsedTime and RowsReturned has valid value for Cloud Spanner Emulator.
type ReadOnlyVar ¶
type ReadOnlyVar struct {
// contains filtered or unexported fields
}
ReadOnlyVar creates a read-only variable with custom getter
func NewReadOnlyVar ¶
func NewReadOnlyVar(getter func() string, desc string) *ReadOnlyVar
NewReadOnlyVar creates a new read-only variable
func (*ReadOnlyVar) Description ¶
func (r *ReadOnlyVar) Description() string
func (*ReadOnlyVar) Get ¶
func (r *ReadOnlyVar) Get() (string, error)
func (*ReadOnlyVar) IsReadOnly ¶
func (r *ReadOnlyVar) IsReadOnly() bool
func (*ReadOnlyVar) Set ¶
func (r *ReadOnlyVar) Set(value string) error
type Result ¶
type Result struct {
ColumnAlign []tw.Align // optional
Rows []Row
Predicates []string
AffectedRows int
AffectedRowsType rowCountType
Stats QueryStats
// IsExecutedDML indicates this is an executed DML statement (INSERT/UPDATE/DELETE) that can report affected rows
IsExecutedDML bool
ReadTimestamp time.Time // For SELECT/read-only transactions
CommitTimestamp time.Time // For COMMIT/DML operations
ForceVerbose bool
CommitStats *sppb.CommitResponse_CommitStats
KeepVariables bool
TableHeader TableHeader
ForceWrap bool
LintResults []string
IndexAdvice []QueryIndexAdvice // Index recommendations from query advisor
PreInput string
// HasSQLFormattedValues indicates that the row values have been formatted as SQL literals
// using spanvalue.LiteralFormatConfig instead of regular display formatting.
// This flag is set to true only when:
// - executeSQL is called with SQL export format (SQL_INSERT, SQL_INSERT_OR_IGNORE, SQL_INSERT_OR_UPDATE)
// - The values in Rows are valid SQL literals that can be used in INSERT statements
// When false, SQL export formats will fall back to table format to prevent invalid SQL generation.
// Examples of statements that have this as false:
// - SHOW CREATE TABLE, SHOW TABLES (metadata queries)
// - EXPLAIN, EXPLAIN ANALYZE (query plan information)
// - DML with THEN RETURN (uses regular formatting)
HasSQLFormattedValues bool
// IsDirectOutput indicates that Rows contain pre-formatted text lines that should
// be printed directly without any table formatting. Used by DUMP statements and
// potentially other commands that produce pre-formatted output.
// When true, Rows bypass normal table formatting and are output as-is.
IsDirectOutput bool
// SQLTableNameForExport stores the auto-detected or explicitly set table name for SQL export.
// This field is populated during query execution when SQL export formats are used.
// It ensures the table name is available during the formatting phase, even in buffered mode.
SQLTableNameForExport string
BatchInfo *BatchInfo
PartitionCount int
Streamed bool // Indicates rows were streamed and not buffered
Metrics *metrics.ExecutionMetrics // Performance metrics for query execution
}
type RollbackStatement ¶
type RollbackStatement struct{}
type RowIterResult ¶
type RowIterResult struct {
Metadata *sppb.ResultSetMetadata
Rows iter.Seq[Row]
QueryStats map[string]interface{}
RowCount int64
QueryPlan *sppb.QueryPlan
Error error
}
RowIterResult contains metadata and a row iterator sequence. The metadata is available immediately after the first row is fetched.
type RowProcessor ¶
type RowProcessor interface {
// Init is called once after metadata becomes available (after first row fetch).
// This is where headers are written for formats like CSV, or table initialization occurs.
Init(metadata *sppb.ResultSetMetadata, sysVars *systemVariables) error
// ProcessRow is called for each row in the result set.
// In buffered mode, rows are collected. In streaming mode, rows are output immediately.
ProcessRow(row Row) error
// Finish is called after all rows have been processed.
// It receives final statistics and row count for summary output.
Finish(stats QueryStats, rowCount int64) error
}
RowProcessor handles rows either in buffered or streaming mode. It provides a unified interface for processing query results regardless of whether rows are collected first or streamed directly.
func NewStreamingProcessorForMode ¶
func NewStreamingProcessorForMode(mode enums.DisplayMode, out io.Writer, sysVars *systemVariables, screenWidth int) RowProcessor
NewStreamingProcessorForMode creates a streaming processor for the given display mode. Returns nil if the mode doesn't support streaming yet. This is primarily used for testing - production code uses createStreamingProcessor.
type RunBatchStatement ¶
type RunBatchStatement struct{}
type RunPartitionStatement ¶
type RunPartitionStatement struct{ Token string }
type RunPartitionedQueryStatement ¶
type RunPartitionedQueryStatement struct{ SQL string }
type SampleDatabase ¶
type SampleDatabase struct {
Name string `json:"name"` // Unique identifier for the sample
Description string `json:"description"` // Human-readable description
Dialect string `json:"dialect"` // SQL dialect (GOOGLE_STANDARD_SQL or POSTGRESQL)
SchemaURI string `json:"schemaURI"` // URI to schema file (can be relative or absolute)
DataURI string `json:"dataURI,omitempty"` // URI to data file (optional)
Source string `json:"source,omitempty"` // Documentation URL or description (optional)
// Runtime fields (not in JSON)
BaseDir string `json:"-"` // Base directory for relative path resolution
IsEmbedded bool `json:"-"` // Distinguishes embedded:// from file:// base URIs
ParsedDialect databasepb.DatabaseDialect `json:"-"` // Parsed dialect enum value
}
SampleDatabase represents both metadata and runtime configuration
func (*SampleDatabase) ResolveURIs ¶
func (s *SampleDatabase) ResolveURIs()
ResolveURIs converts relative paths to absolute URIs based on BaseDir
type SelectStatement ¶
type SelectStatement struct {
Query string
}
func (*SelectStatement) String ¶
func (s *SelectStatement) String() string
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a database session with transaction management.
Mutex Protection Rationale:
While spanner-mycli is primarily a CLI tool with sequential user interactions, mutex protection is essential for several reasons:
1. **Goroutine safety**: Even in a CLI, operations may spawn goroutines:
- Background heartbeat for long-running transactions
- Progress bars and monitoring features
- Future parallel query execution features
- Signal handlers (Ctrl+C) that may access transaction state
2. **Correctness over performance**: The mutex ensures:
- Atomic check-and-act operations (e.g., checking transaction state before modifying)
- Prevention of use-after-free bugs if transaction is closed concurrently
- Consistent transaction state across all operations
3. **Future extensibility**: The mutex-based design allows for:
- Safe addition of concurrent features without major refactoring
- Integration with tools that may access session state concurrently
- Support for multiplexed connections or parallel operations
4. **Best practices**: Following Go's concurrency principles:
- "Don't communicate by sharing memory; share memory by communicating"
- When sharing is necessary (as with session state), protect it properly
- Make the zero value useful - mutex provides safe default behavior
The performance overhead of mutex operations is negligible for CLI usage patterns, while the safety guarantees prevent subtle bugs that could corrupt user data.
func NewAdminSession ¶
func NewSession ¶
func (*Session) BeginPendingTransaction ¶
func (s *Session) BeginPendingTransaction(ctx context.Context, isolationLevel sppb.TransactionOptions_IsolationLevel, priority sppb.RequestOptions_Priority) error
BeginPendingTransaction starts pending transaction. The actual start of the transaction is delayed until the first operation in the transaction is executed.
func (*Session) BeginReadOnlyTransaction ¶
func (s *Session) BeginReadOnlyTransaction(ctx context.Context, typ timestampBoundType, staleness time.Duration, timestamp time.Time, priority sppb.RequestOptions_Priority) (time.Time, error)
BeginReadOnlyTransaction starts read-only transaction and returns the snapshot timestamp for the transaction if successful.
func (*Session) BeginReadOnlyTransactionLocked ¶
func (s *Session) BeginReadOnlyTransactionLocked(ctx context.Context, typ timestampBoundType, staleness time.Duration, timestamp time.Time, priority sppb.RequestOptions_Priority) (time.Time, error)
BeginReadOnlyTransactionLocked starts read-only transaction and returns the snapshot timestamp for the transaction if successful. Caller must hold s.tcMutex.
func (*Session) BeginReadWriteTransaction ¶
func (s *Session) BeginReadWriteTransaction(ctx context.Context, isolationLevel sppb.TransactionOptions_IsolationLevel, priority sppb.RequestOptions_Priority) error
BeginReadWriteTransaction starts read-write transaction.
func (*Session) BeginReadWriteTransactionLocked ¶
func (s *Session) BeginReadWriteTransactionLocked(ctx context.Context, isolationLevel sppb.TransactionOptions_IsolationLevel, priority sppb.RequestOptions_Priority) error
BeginReadWriteTransactionLocked starts read-write transaction. Caller must hold s.tcMutex.
func (*Session) ClosePendingTransaction ¶
ClosePendingTransaction closes a pending transaction.
func (*Session) CloseReadOnlyTransaction ¶
CloseReadOnlyTransaction closes a running read-only transaction.
func (*Session) CommitReadWriteTransaction ¶
CommitReadWriteTransaction commits read-write transaction and returns commit timestamp if successful.
func (*Session) CommitReadWriteTransactionLocked ¶
func (s *Session) CommitReadWriteTransactionLocked(ctx context.Context) (spanner.CommitResponse, error)
CommitReadWriteTransactionLocked commits read-write transaction and returns commit timestamp if successful. Caller must hold s.tcMutex.
func (*Session) ConnectToDatabase ¶
func (*Session) DatabaseExists ¶
func (*Session) DatabasePath ¶
func (*Session) DetermineTransaction ¶
DetermineTransaction determines the type of transaction to start based on the pending transaction and system variables. It returns the timestamp for read-only transactions or a zero time for read-write transactions.
func (*Session) DetermineTransactionAndState ¶
DetermineTransactionAndState determines transaction and returns both the timestamp and current transaction state. This combines DetermineTransaction and InTransaction checks in a single lock acquisition.
func (*Session) DetermineTransactionLocked ¶
DetermineTransactionLocked determines the type of transaction to start based on the pending transaction and system variables. It returns the timestamp for read-only transactions or a zero time for read-write transactions. Caller must hold s.tcMutex.
func (*Session) ExecuteStatement ¶
ExecuteStatement executes stmt. If stmt is a MutationStatement, pending transaction is determined and fails if there is an active read-only transaction.
func (*Session) GetDatabaseSchema ¶
func (s *Session) GetDatabaseSchema(ctx context.Context) ([]string, *descriptorpb.FileDescriptorSet, error)
func (*Session) GetTransactionFlagsWithLock ¶
GetTransactionFlagsWithLock returns multiple transaction state flags in a single lock acquisition. This is useful for avoiding multiple lock acquisitions when checking different transaction states. Acquires RLock for concurrent read access.
func (*Session) InPendingTransaction ¶
InPendingTransaction returns true if the session is running pending transaction.
func (*Session) InReadOnlyTransaction ¶
InReadOnlyTransaction returns true if the session is running read-only transaction.
func (*Session) InReadWriteTransaction ¶
InReadWriteTransaction returns true if the session is running read-write transaction.
func (*Session) InTransaction ¶
InTransaction returns true if the session is running transaction.
func (*Session) IncrementSchemaGeneration ¶
func (s *Session) IncrementSchemaGeneration()
IncrementSchemaGeneration bumps the schema generation counter, signaling that schema-dependent caches should be invalidated.
func (*Session) InstanceExists ¶
func (*Session) InstancePath ¶
func (*Session) IsDetached ¶
func (*Session) Mode ¶
func (s *Session) Mode() SessionMode
func (*Session) NewTransactionOptionsBuilder ¶
func (s *Session) NewTransactionOptionsBuilder() *TransactionOptionsBuilder
NewTransactionOptionsBuilder creates a new builder with session defaults.
func (*Session) RecreateClient ¶
RecreateClient closes the current client and creates a new client for the session.
func (*Session) RequiresDatabaseConnection ¶
func (*Session) RollbackReadWriteTransaction ¶
RollbackReadWriteTransaction rollbacks read-write transaction.
func (*Session) RollbackReadWriteTransactionLocked ¶
RollbackReadWriteTransactionLocked rollbacks read-write transaction. Caller must hold s.tcMutex.
func (*Session) RunAnalyzeQuery ¶
func (s *Session) RunAnalyzeQuery(ctx context.Context, stmt spanner.Statement) (*sppb.QueryPlan, *sppb.ResultSetMetadata, error)
RunAnalyzeQuery analyzes a statement either on the running transaction or on the temporal read-only transaction.
func (*Session) RunInNewOrExistRwTx ¶
func (s *Session) RunInNewOrExistRwTx(ctx context.Context, f func(tx *spanner.ReadWriteStmtBasedTransaction, implicit bool) (affected int64, plan *sppb.QueryPlan, metadata *sppb.ResultSetMetadata, err error), ) (*DMLResult, error)
RunInNewOrExistRwTx is a helper function for DML execution. It executes a function in the current RW transaction or an implicit RW transaction. If there is an error, the transaction will be rolled back.
func (*Session) RunInNewOrExistRwTxLocked ¶
func (s *Session) RunInNewOrExistRwTxLocked(ctx context.Context, f func(tx *spanner.ReadWriteStmtBasedTransaction, implicit bool) (affected int64, plan *sppb.QueryPlan, metadata *sppb.ResultSetMetadata, err error), ) (*DMLResult, error)
RunInNewOrExistRwTxLocked is a helper function for DML execution. It executes a function in the current RW transaction or an implicit RW transaction. If there is an error, the transaction will be rolled back. Caller must hold s.tcMutex.
func (*Session) RunPartitionQuery ¶
func (*Session) RunQuery ¶
func (s *Session) RunQuery(ctx context.Context, stmt spanner.Statement) (*spanner.RowIterator, *spanner.ReadOnlyTransaction)
RunQuery executes a statement either on the running transaction or on the temporal read-only transaction. It returns row iterator and read-only transaction if the statement was executed on the read-only transaction.
func (*Session) RunQueryWithStats ¶
func (s *Session) RunQueryWithStats(ctx context.Context, stmt spanner.Statement, implicit bool) (*spanner.RowIterator, *spanner.ReadOnlyTransaction)
RunQueryWithStats executes a statement with stats either on the running transaction or on the temporal read-only transaction. It returns row iterator and read-only transaction if the statement was executed on the read-only transaction.
func (*Session) RunUpdate ¶
func (s *Session) RunUpdate(ctx context.Context, stmt spanner.Statement, implicit bool) ([]Row, map[string]any, int64, *sppb.ResultSetMetadata, *sppb.QueryPlan, error, )
RunUpdate executes a DML statement on the running read-write transaction. It returns error if there is no running read-write transaction.
func (*Session) SchemaGeneration ¶
SchemaGeneration returns the current schema generation counter.
func (*Session) TransactionAttrsWithLock ¶
func (s *Session) TransactionAttrsWithLock() transactionAttributes
TransactionAttrs returns a copy of all transaction attributes. This allows safe inspection of transaction state without holding the mutex. If no transaction is active, returns a zero-value struct with mode=transactionModeUndetermined.
Design decision: This method uses RLock for read-only access, allowing concurrent reads of transaction state.
Naming convention: - TransactionAttrsWithLock() - Acquires read lock internally (this method) - transactionAttrsLocked() - Assumes caller holds lock (read or write)
func (*Session) TransactionMode ¶
func (s *Session) TransactionMode() transactionMode
TransactionMode returns the current transaction mode. Deprecated: Use TransactionState() for new code.
func (*Session) TransactionState ¶
TransactionState returns the current transaction mode and whether a transaction is active. This consolidates multiple transaction state checks into a single method.
func (*Session) TransitTransaction ¶
func (s *Session) TransitTransaction(ctx context.Context, fn func(tc *transactionContext) (*transactionContext, error)) error
TransitTransaction implements a functional state transition pattern for transaction management. It atomically transitions from one transaction state to another, handling cleanup of the old state. The transition function receives the current context and returns the new context. If an error occurs during transition, the original state is preserved.
func (*Session) ValidateDatabaseOperation ¶
func (*Session) ValidateDetachedOperation ¶
func (*Session) ValidateStatementExecution ¶
type SessionHandler ¶
type SessionHandler struct {
*Session
}
SessionHandler manages a session pointer and can handle session-changing statements
func NewSessionHandler ¶
func NewSessionHandler(session *Session) *SessionHandler
func (*SessionHandler) Close ¶
func (h *SessionHandler) Close()
func (*SessionHandler) ExecuteStatement ¶
ExecuteStatement executes a statement, handling session-changing statements appropriately
func (*SessionHandler) GetSession ¶
func (h *SessionHandler) GetSession() *Session
type SetAddStatement ¶
type SetParamTypeStatement ¶
type SetParamValueStatement ¶
type SetStatement ¶
type SetTransactionStatement ¶
type SetTransactionStatement struct {
IsReadOnly bool
}
type ShellMetaCommand ¶
type ShellMetaCommand struct {
Command string
}
ShellMetaCommand executes system shell commands using \! syntax
type ShowColumnsStatement ¶
type ShowCreateStatement ¶
type ShowDatabasesStatement ¶
type ShowDatabasesStatement struct{}
type ShowDdlsStatement ¶
type ShowDdlsStatement struct{}
type ShowIndexStatement ¶
type ShowLocalProtoStatement ¶
type ShowLocalProtoStatement struct{}
type ShowOperationStatement ¶
type ShowParamsStatement ¶
type ShowParamsStatement struct{}
type ShowPlanNodeStatement ¶
type ShowPlanNodeStatement struct {
NodeID int
}
type ShowQueryProfileStatement ¶
type ShowQueryProfileStatement struct {
Fprint int64
}
type ShowQueryProfilesStatement ¶
type ShowQueryProfilesStatement struct{}
type ShowRemoteProtoStatement ¶
type ShowRemoteProtoStatement struct{}
type ShowSchemaUpdateOperations ¶
type ShowSchemaUpdateOperations struct{}
type ShowSplitPointsStatement ¶
type ShowSplitPointsStatement struct{}
type ShowTablesStatement ¶
type ShowTablesStatement struct {
Schema string
}
type ShowVariableStatement ¶
type ShowVariableStatement struct {
VarName string
}
type ShowVariablesStatement ¶
type ShowVariablesStatement struct{}
type SourceMetaCommand ¶
type SourceMetaCommand struct {
FilePath string
}
SourceMetaCommand executes SQL statements from a file using \. syntax
type StartBatchStatement ¶
type StartBatchStatement struct {
Mode batchMode
}
type Statement ¶
func BuildCLIStatement ¶
func BuildStatement ¶
func ParseMetaCommand ¶
ParseMetaCommand parses a meta command string into a Statement
type StreamingProcessor ¶
type StreamingProcessor struct {
// contains filtered or unexported fields
}
StreamingProcessor processes rows immediately as they arrive. This reduces memory usage and improves Time To First Byte for large result sets.
func NewStreamingProcessor ¶
func NewStreamingProcessor(formatter format.StreamingFormatter, out io.Writer, screenWidth int) *StreamingProcessor
NewStreamingProcessor creates a processor that outputs rows immediately.
func (*StreamingProcessor) Finish ¶
func (p *StreamingProcessor) Finish(stats QueryStats, rowCount int64) error
Finish completes the streaming output.
func (*StreamingProcessor) Init ¶
func (p *StreamingProcessor) Init(metadata *sppb.ResultSetMetadata, sysVars *systemVariables) error
Init initializes the streaming processor and writes headers if needed.
func (*StreamingProcessor) ProcessRow ¶
func (p *StreamingProcessor) ProcessRow(row Row) error
ProcessRow immediately outputs a row.
type SyncProtoStatement ¶
type TableDependency ¶
type TableDependency struct {
TableName string
ParentTable string // INTERLEAVE parent
OnDeleteAction string // CASCADE, NO ACTION for INTERLEAVE
ChildrenTables []string // Tables that interleave in this table
ForeignKeys []FKReference // Foreign key references FROM this table
ReferencedBy []FKReference // Foreign key references TO this table
Level int // INTERLEAVE depth (0-7)
}
TableDependency represents a table with all its dependencies
type TableHeader ¶
type TablePreviewProcessor ¶
type TablePreviewProcessor struct {
// contains filtered or unexported fields
}
TablePreviewProcessor collects a configurable number of rows for table width calculation. This allows table formats to determine optimal column widths before starting output.
func NewTablePreviewProcessor ¶
func NewTablePreviewProcessor(formatter format.StreamingFormatter, previewSize int) *TablePreviewProcessor
NewTablePreviewProcessor creates a processor that previews rows for width calculation. previewSize of 0 means collect all rows (non-streaming mode).
func (*TablePreviewProcessor) Finish ¶
func (p *TablePreviewProcessor) Finish(stats QueryStats, rowCount int64) error
Finish ensures formatter is initialized and completes output.
func (*TablePreviewProcessor) Init ¶
func (p *TablePreviewProcessor) Init(metadata *sppb.ResultSetMetadata, sysVars *systemVariables) error
Init stores metadata for later use.
func (*TablePreviewProcessor) ProcessRow ¶
func (p *TablePreviewProcessor) ProcessRow(row Row) error
ProcessRow collects rows for preview or passes them through after initialization.
type TeeOutputMetaCommand ¶
type TeeOutputMetaCommand struct {
FilePath string
}
TeeOutputMetaCommand enables output tee to a file using \T syntax (MySQL-style: both screen and file)
type TemplateVar ¶
type TemplateVar struct {
// contains filtered or unexported fields
}
TemplateVar handles template variables like CLI_ANALYZE_COLUMNS
func (*TemplateVar) Description ¶
func (t *TemplateVar) Description() string
func (*TemplateVar) Get ¶
func (t *TemplateVar) Get() (string, error)
func (*TemplateVar) IsReadOnly ¶
func (t *TemplateVar) IsReadOnly() bool
func (*TemplateVar) Set ¶
func (t *TemplateVar) Set(value string) error
type TimestampBoundVar ¶
type TimestampBoundVar struct {
// contains filtered or unexported fields
}
TimestampBoundVar handles READ_ONLY_STALENESS variable
func (*TimestampBoundVar) Description ¶
func (t *TimestampBoundVar) Description() string
func (*TimestampBoundVar) Get ¶
func (t *TimestampBoundVar) Get() (string, error)
func (*TimestampBoundVar) IsReadOnly ¶
func (t *TimestampBoundVar) IsReadOnly() bool
func (*TimestampBoundVar) Set ¶
func (t *TimestampBoundVar) Set(value string) error
type TimestampVar ¶
type TimestampVar struct {
// contains filtered or unexported fields
}
TimestampVar handles timestamp formatting for read-only timestamp variables
func (*TimestampVar) Description ¶
func (t *TimestampVar) Description() string
func (*TimestampVar) Get ¶
func (t *TimestampVar) Get() (string, error)
func (*TimestampVar) IsReadOnly ¶
func (t *TimestampVar) IsReadOnly() bool
func (*TimestampVar) Set ¶
func (t *TimestampVar) Set(value string) error
type TransactionOptionsBuilder ¶
type TransactionOptionsBuilder struct {
// contains filtered or unexported fields
}
TransactionOptionsBuilder helps build transaction options with proper defaults.
func (*TransactionOptionsBuilder) Build ¶
func (b *TransactionOptionsBuilder) Build() spanner.TransactionOptions
Build creates the final TransactionOptions with resolved defaults.
func (*TransactionOptionsBuilder) BuildIsolationLevel ¶
func (b *TransactionOptionsBuilder) BuildIsolationLevel() sppb.TransactionOptions_IsolationLevel
BuildIsolationLevel returns just the resolved isolation level.
func (*TransactionOptionsBuilder) BuildPriority ¶
func (b *TransactionOptionsBuilder) BuildPriority() sppb.RequestOptions_Priority
BuildPriority returns just the resolved priority.
func (*TransactionOptionsBuilder) WithIsolationLevel ¶
func (b *TransactionOptionsBuilder) WithIsolationLevel(level sppb.TransactionOptions_IsolationLevel) *TransactionOptionsBuilder
WithIsolationLevel sets the transaction isolation level.
func (*TransactionOptionsBuilder) WithPriority ¶
func (b *TransactionOptionsBuilder) WithPriority(priority sppb.RequestOptions_Priority) *TransactionOptionsBuilder
WithPriority sets the transaction priority.
func (*TransactionOptionsBuilder) WithTag ¶
func (b *TransactionOptionsBuilder) WithTag(tag string) *TransactionOptionsBuilder
WithTag sets the transaction tag.
type TruncateTableStatement ¶
type TryPartitionedQueryStatement ¶
type TryPartitionedQueryStatement struct{ SQL string }
type UnimplementedVar ¶
type UnimplementedVar struct {
// contains filtered or unexported fields
}
UnimplementedVar handles unimplemented variables
func (*UnimplementedVar) Description ¶
func (u *UnimplementedVar) Description() string
func (*UnimplementedVar) Get ¶
func (u *UnimplementedVar) Get() (string, error)
func (*UnimplementedVar) IsReadOnly ¶
func (u *UnimplementedVar) IsReadOnly() bool
func (*UnimplementedVar) Set ¶
func (u *UnimplementedVar) Set(value string) error
type UnsetParamStatement ¶
type UnsetParamStatement struct {
Name string
}
type UpdateResult ¶
type UpdateResult struct {
Rows []Row // Rows returned by the update operation (e.g., from RETURNING clause)
Stats map[string]any // Query statistics from the operation
Count int64 // Number of rows affected by the update
Metadata *sppb.ResultSetMetadata // Metadata about the result set
Plan *sppb.QueryPlan // Query execution plan (when requested)
}
UpdateResult holds the complete result of an update operation.
type UseDatabaseMetaCommand ¶
type UseDatabaseMetaCommand struct {
Database string
}
UseDatabaseMetaCommand switches database using \u syntax
type UseStatement ¶
type UseStatement struct {
Database string
Role string
NopStatement
}
UseStatement is actually implemented in cli.go because it needs to replace Session pointer in Cli.
type ValidValuesEnumerator ¶
type ValidValuesEnumerator interface {
ValidValues() []string
}
ValidValuesEnumerator is implemented by variables that have a constrained set of valid values. Used by fuzzy completion to offer value candidates for SET <name> = <Ctrl+T>. Values must be returned as valid GoogleSQL literals (e.g., 'TABLE' for strings, TRUE for booleans).
type VarHandler ¶
type VarHandler[T any] struct { // contains filtered or unexported fields }
VarHandler handles get/set operations for a variable
TODO: Consider adding native support for session-init-only variables. Currently, variables like CLI_ENABLE_ADC_PLUS use custom setters to check if CurrentSession != nil, but this could be better supported as a first-class feature. Potential implementation:
- Add a sessionInitOnly bool field to VarHandler
- Move the CurrentSession check logic into the Set method
- This would centralize the behavior and make it declarative rather than imperative
func BoolVar ¶
func BoolVar(ptr *bool, desc string) *VarHandler[bool]
BoolVar creates a handler for bool variables
func IntVar ¶
func IntVar(ptr *int64, desc string) *VarHandler[int64]
IntVar creates a handler for int64 variables
func NullableDurationVar ¶
NullableDurationVar creates a handler for nullable duration variables
func NullableIntVar ¶
func NullableIntVar(ptr **int64, desc string) *VarHandler[*int64]
NullableIntVar creates a handler for nullable int64 variables
func StringVar ¶
func StringVar(ptr *string, desc string) *VarHandler[string]
StringVar creates a handler for string variables
func (*VarHandler[T]) AsReadOnly ¶
func (h *VarHandler[T]) AsReadOnly() *VarHandler[T]
AsReadOnly makes the handler read-only
func (*VarHandler[T]) Description ¶
func (h *VarHandler[T]) Description() string
Description returns the variable description
func (*VarHandler[T]) Get ¶
func (h *VarHandler[T]) Get() (string, error)
Get returns the formatted value
func (*VarHandler[T]) IsReadOnly ¶
func (h *VarHandler[T]) IsReadOnly() bool
IsReadOnly returns whether the variable is read-only
func (*VarHandler[T]) Set ¶
func (h *VarHandler[T]) Set(value string) error
Set parses and sets the value
func (*VarHandler[T]) ValidValues ¶
func (h *VarHandler[T]) ValidValues() []string
ValidValues returns the constrained valid values, if any. Implements ValidValuesEnumerator for VarHandler instances with enumValues set.
func (*VarHandler[T]) WithValidator ¶
func (h *VarHandler[T]) WithValidator(validate func(T) error) *VarHandler[T]
WithValidator adds a validator function
type VarRegistry ¶
type VarRegistry struct {
// contains filtered or unexported fields
}
VarRegistry is a registry for system variables
func NewVarRegistry ¶
func NewVarRegistry(sv *systemVariables) *VarRegistry
NewVarRegistry creates a new variable registry
func (*VarRegistry) Add ¶
func (r *VarRegistry) Add(name, value string) error
Add performs ADD operation on a variable
func (*VarRegistry) Get ¶
func (r *VarRegistry) Get(name string) (string, error)
Get retrieves a variable value
func (*VarRegistry) GetDescription ¶
func (r *VarRegistry) GetDescription(name string) (string, error)
GetDescription returns variable description
func (*VarRegistry) GetVariable ¶
func (r *VarRegistry) GetVariable(name string) Variable
GetVariable retrieves the Variable handler by name, or nil if not found.
func (*VarRegistry) IsReadOnly ¶
func (r *VarRegistry) IsReadOnly(name string) (bool, error)
IsReadOnly checks if a variable is read-only
func (*VarRegistry) ListVariableInfo ¶
func (r *VarRegistry) ListVariableInfo() map[string]struct { Description string ReadOnly bool CanAdd bool }
ListVariableInfo returns information about all variables
func (*VarRegistry) ListVariables ¶
func (r *VarRegistry) ListVariables() map[string]string
ListVariables returns a map of all variables with their current values
func (*VarRegistry) Register ¶
func (r *VarRegistry) Register(name string, v Variable)
Register adds a variable to the registry
func (*VarRegistry) RegisterWithAdd ¶
func (r *VarRegistry) RegisterWithAdd(name string, v Variable, addFunc func(string) error)
RegisterWithAdd adds a variable with ADD support
Source Files
¶
- app.go
- cli.go
- cli_mcp.go
- cli_output.go
- cli_readline.go
- client_side_statement_def.go
- dependency_resolver.go
- errors.go
- execute_sql.go
- formatter_utils.go
- fuzzy_finder.go
- lint_plan.go
- meta_commands.go
- row_processor.go
- sample_databases.go
- separator.go
- session.go
- session_transaction_context.go
- statement_processing.go
- statements.go
- statements_dump.go
- statements_explain_describe.go
- statements_llm.go
- statements_mutations.go
- statements_params.go
- statements_partitioned_query.go
- statements_proto.go
- statements_query_profile.go
- statements_schema.go
- statements_split_points.go
- statements_system_variable.go
- statements_transaction.go
- streaming.go
- system_variables.go
- system_variables_registry.go
- var_custom_handlers.go
- var_enum_handlers.go
- var_errors.go
- var_handler.go
- var_registry.go
- zap_logger.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package format implements SQL export formatting for query results.
|
Package format implements SQL export formatting for query results. |
|
StreamManager manages all I/O streams for the CLI.
|
StreamManager manages all I/O streams for the CLI. |