Documentation
¶
Index ¶
- type BatchType
- type DmlType
- type Identifier
- type Literal
- type ParsedAbortBatchStatement
- type ParsedBeginStatement
- type ParsedCommitStatement
- type ParsedCreateDatabaseStatement
- type ParsedDropDatabaseStatement
- type ParsedResetStatement
- type ParsedRollbackStatement
- type ParsedRunBatchStatement
- type ParsedSetStatement
- type ParsedShowStatement
- type ParsedStartBatchStatement
- type ParsedStatement
- type StatementInfo
- type StatementParser
- func (p *StatementParser) CacheSize() int
- func (p *StatementParser) DetectStatementType(sql string) *StatementInfo
- func (p *StatementParser) ParseClientSideStatement(query string) (ParsedStatement, error)
- func (p *StatementParser) ParseParameters(sql string) (string, []string, error)
- func (p *StatementParser) UseCache() bool
- type StatementType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DmlType ¶
type DmlType int
DmlType designates the type of modification that a DML statement will execute.
type Identifier ¶
type Identifier struct {
Parts []string
}
Identifier represents an identifier (e.g. table name, variable name) in a SQL string. An identifier can consist of multiple parts separated by a dot in a SQL string. E.g. table name my_schema.my_table is an Identifier with two parts:
- my_schema
- my_table
func (*Identifier) String ¶
func (i *Identifier) String() string
type Literal ¶
type Literal struct {
Value string
}
Literal is a string, number or other literal in a SQL string.
type ParsedAbortBatchStatement ¶
type ParsedAbortBatchStatement struct {
// contains filtered or unexported fields
}
func (*ParsedAbortBatchStatement) Name ¶
func (s *ParsedAbortBatchStatement) Name() string
func (*ParsedAbortBatchStatement) Query ¶
func (s *ParsedAbortBatchStatement) Query() string
type ParsedBeginStatement ¶
type ParsedBeginStatement struct {
// contains filtered or unexported fields
}
func (*ParsedBeginStatement) Name ¶
func (s *ParsedBeginStatement) Name() string
func (*ParsedBeginStatement) Query ¶
func (s *ParsedBeginStatement) Query() string
type ParsedCommitStatement ¶
type ParsedCommitStatement struct {
// contains filtered or unexported fields
}
func (*ParsedCommitStatement) Name ¶
func (s *ParsedCommitStatement) Name() string
func (*ParsedCommitStatement) Query ¶
func (s *ParsedCommitStatement) Query() string
type ParsedCreateDatabaseStatement ¶
type ParsedCreateDatabaseStatement struct { Identifier Identifier // contains filtered or unexported fields }
func (*ParsedCreateDatabaseStatement) Name ¶
func (s *ParsedCreateDatabaseStatement) Name() string
func (*ParsedCreateDatabaseStatement) Query ¶
func (s *ParsedCreateDatabaseStatement) Query() string
type ParsedDropDatabaseStatement ¶
type ParsedDropDatabaseStatement struct { Identifier Identifier // contains filtered or unexported fields }
func (*ParsedDropDatabaseStatement) Name ¶
func (s *ParsedDropDatabaseStatement) Name() string
func (*ParsedDropDatabaseStatement) Query ¶
func (s *ParsedDropDatabaseStatement) Query() string
type ParsedResetStatement ¶
type ParsedResetStatement struct { Identifier Identifier // contains filtered or unexported fields }
ParsedResetStatement is a statement of the form RESET [my_extension.]my_property
func (*ParsedResetStatement) Name ¶
func (s *ParsedResetStatement) Name() string
func (*ParsedResetStatement) Query ¶
func (s *ParsedResetStatement) Query() string
type ParsedRollbackStatement ¶
type ParsedRollbackStatement struct {
// contains filtered or unexported fields
}
func (*ParsedRollbackStatement) Name ¶
func (s *ParsedRollbackStatement) Name() string
func (*ParsedRollbackStatement) Query ¶
func (s *ParsedRollbackStatement) Query() string
type ParsedRunBatchStatement ¶
type ParsedRunBatchStatement struct {
// contains filtered or unexported fields
}
func (*ParsedRunBatchStatement) Name ¶
func (s *ParsedRunBatchStatement) Name() string
func (*ParsedRunBatchStatement) Query ¶
func (s *ParsedRunBatchStatement) Query() string
type ParsedSetStatement ¶
type ParsedSetStatement struct { Identifier Identifier Literal Literal IsLocal bool // contains filtered or unexported fields }
ParsedSetStatement is a statement of the form SET [SESSION | LOCAL] [my_extension.]my_property {=|to} <value>
func (*ParsedSetStatement) Name ¶
func (s *ParsedSetStatement) Name() string
func (*ParsedSetStatement) Query ¶
func (s *ParsedSetStatement) Query() string
type ParsedShowStatement ¶
type ParsedShowStatement struct { Identifier Identifier // contains filtered or unexported fields }
ParsedShowStatement is a statement of the form SHOW [VARIABLE] [my_extension.]my_property
func (*ParsedShowStatement) Name ¶
func (s *ParsedShowStatement) Name() string
func (*ParsedShowStatement) Query ¶
func (s *ParsedShowStatement) Query() string
type ParsedStartBatchStatement ¶
type ParsedStartBatchStatement struct { Type BatchType // contains filtered or unexported fields }
func (*ParsedStartBatchStatement) Name ¶
func (s *ParsedStartBatchStatement) Name() string
func (*ParsedStartBatchStatement) Query ¶
func (s *ParsedStartBatchStatement) Query() string
type ParsedStatement ¶
type StatementInfo ¶
type StatementInfo struct { StatementType StatementType DmlType DmlType }
StatementInfo contains the type of SQL statement, and in case of a DML statement, the type of DML command.
type StatementParser ¶
type StatementParser struct { Dialect databasepb.DatabaseDialect // contains filtered or unexported fields }
StatementParser is a simple, dialect-aware SQL statement parser for Spanner. It can be used to determine the type of SQL statement (e.g. DQL/DML/DDL), and extract further information from the statement, such as the query parameters.
This is an internal type that can receive breaking changes without prior notice.
func NewStatementParser ¶
func NewStatementParser(dialect databasepb.DatabaseDialect, cacheSize int) (*StatementParser, error)
NewStatementParser creates a new parser for the given SQL dialect and with the given cache size. Parsers can be shared among multiple database connections. The Spanner database/sql driver will only create one parser per database dialect and cache size combination.
This is an internal function that can receive breaking changes without prior notice.
func (*StatementParser) CacheSize ¶
func (p *StatementParser) CacheSize() int
CacheSize returns the current size of the statement cache of this StatementParser.
func (*StatementParser) DetectStatementType ¶
func (p *StatementParser) DetectStatementType(sql string) *StatementInfo
DetectStatementType returns the type of SQL statement based on the first keyword that is found in the SQL statement.
func (*StatementParser) ParseClientSideStatement ¶
func (p *StatementParser) ParseClientSideStatement(query string) (ParsedStatement, error)
ParseClientSideStatement returns the executableClientSideStatement that corresponds with the given query string, or nil if it is not a valid client side statement.
func (*StatementParser) ParseParameters ¶
func (p *StatementParser) ParseParameters(sql string) (string, []string, error)
ParseParameters returns the parameters in the given sql string, if the input sql contains positional parameters it returns the converted sql string with all positional parameters replaced with named parameters. The sql string must be a valid Cloud Spanner sql statement. It may contain comments and (string) literals without any restrictions. That is, string literals containing for example an email address ('test@test.com') will be recognized as a string literal and not returned as a named parameter.
func (*StatementParser) UseCache ¶
func (p *StatementParser) UseCache() bool
UseCache returns true if this StatementParser uses a cache.
type StatementType ¶
type StatementType int
StatementType indicates the type of SQL statement.
const ( // StatementTypeUnknown indicates that the parser was not able to determine the // type of SQL statement. This could be an indication that the SQL string is invalid, // or that it uses a syntax that is not (yet) supported by the parser. StatementTypeUnknown StatementType = iota // StatementTypeQuery indicates that the statement is a query that will return rows from // Spanner, and that will not make any modifications to the database. StatementTypeQuery // StatementTypeDml indicates that the statement is a data modification language (DML) // statement that will make modifications to the data in the database. It may or may not // return rows, depending on whether it contains a THEN RETURN (GoogleSQL) or RETURNING // (PostgreSQL) clause. StatementTypeDml // StatementTypeDdl indicates that the statement is a data definition language (DDL) // statement that will modify the schema of the database. It will never return rows. StatementTypeDdl // StatementTypeClientSide indicates that the statement will be handled client-side in // the database/sql driver, and not be sent to Spanner. Examples of this includes SHOW // and SET statements. StatementTypeClientSide )