parser

package
v1.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

Spanner Statement Parser

This package is an internal package and can receive breaking changes without prior notice.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchType

type BatchType int
const (
	BatchTypeDdl BatchType = iota
	BatchTypeDml
)

type DmlType

type DmlType int

DmlType designates the type of modification that a DML statement will execute.

const (
	DmlTypeUnknown DmlType = iota
	DmlTypeInsert
	DmlTypeUpdate
	DmlTypeDelete
)

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 (*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 (*ParsedCreateDatabaseStatement) Query

type ParsedDropDatabaseStatement

type ParsedDropDatabaseStatement struct {
	Identifier Identifier
	// contains filtered or unexported fields
}

func (*ParsedDropDatabaseStatement) Name

func (*ParsedDropDatabaseStatement) Query

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 (*ParsedStartBatchStatement) Query

func (s *ParsedStartBatchStatement) Query() string

type ParsedStatement

type ParsedStatement interface {
	Name() string
	Query() string
	// contains filtered or unexported methods
}

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL