sqlparser

package
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShardingKeyNotAllowNil = errors.New("sharding key does not allow nil")
)

Functions

This section is empty.

Types

type DeleteQuery

type DeleteQuery struct {
	*QueryBase
	Stmt            *vtparser.Delete
	IsDeleteTable   bool
	IsAllShardQuery bool
}

DeleteQuery a implementation of Query interface.

func NewDeleteQuery

func NewDeleteQuery(queryBase *QueryBase, stmt *vtparser.Delete) *DeleteQuery

NewDeleteQuery creates instance of DeleteQuery structure.

type Identifier

type Identifier int64

Identifier the type for sharding key

const (
	// UnknownID the identifier of default sharding key
	UnknownID Identifier = -1
)

type InsertQuery

type InsertQuery struct {
	*QueryBase
	Stmt         *vtparser.Insert
	ColumnValues []func() *vtparser.SQLVal
	// contains filtered or unexported fields
}

InsertQuery a implementation of Query interface.

func NewInsertQuery

func NewInsertQuery(queryBase *QueryBase, stmt *vtparser.Insert) *InsertQuery

NewInsertQuery creates instance of InsertQuery structure.

func (*InsertQuery) NextSequenceID

func (q *InsertQuery) NextSequenceID() Identifier

NextSequenceID get next unique id value generated by sequencer.

func (*InsertQuery) SetNextSequenceID

func (q *InsertQuery) SetNextSequenceID(id int64)

SetNextSequenceID set unique id value generated by sequencer.

func (*InsertQuery) String

func (q *InsertQuery) String() string

String returns formatted text. If insert query includes variable like placeholder, replace it.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser the structure for parsing SQL

func New

func New() (*Parser, error)

New creates Parser instance. If doesn't load configuration file before calling this, returns error.

func (*Parser) Parse

func (p *Parser) Parse(queryText string, args ...interface{}) (Query, error)

Parse parse SQL/DDL by blastrain/vitess-sqlparser(https://github.com/blastrain/vitess-sqlparser), it returns Query interface includes table name or query type nolint: gocyclo

func (*Parser) ValueIndexByValArg

func (p *Parser) ValueIndexByValArg(arg *vtparser.SQLVal) int

type Query

type Query interface {
	// Table returns a table name
	Table() string
	// QueryType returns a type of SQL/DDL
	QueryType() QueryType
}

Query the interface that must be implemented by each query.

type QueryBase

type QueryBase struct {
	Text                       string
	Args                       []interface{}
	Type                       QueryType
	TableName                  string
	ShardKeyID                 Identifier
	ShardKeyIDPlaceholderIndex int
	Stmt                       vtparser.Statement
}

QueryBase a implementation of Query interface.

func NewQueryBase

func NewQueryBase(stmt vtparser.Statement, query string, args []interface{}) *QueryBase

NewQueryBase creates instance of QueryBase structure, this is used by query that excluded INSERT or DELETE.

func (*QueryBase) IsNotFoundShardKeyID

func (q *QueryBase) IsNotFoundShardKeyID() bool

IsNotFoundShardKeyID returns whether sharding key is found in SQL

func (*QueryBase) QueryType

func (q *QueryBase) QueryType() QueryType

QueryType returns a type of SQL/DDL

func (*QueryBase) Table

func (q *QueryBase) Table() string

Table returns table name

type QueryType

type QueryType int

QueryType the type of SQL/DDL ( Select, Insert, Update, Delet, ...)

const (
	// Unknown undefined query type
	Unknown QueryType = iota
	// Select 'SELECT' query type
	Select
	// Insert 'INSERT' query type
	Insert
	// Update 'UPDATE' query type
	Update
	// Delete 'DELETE' query type
	Delete
	// Drop 'DROP' query type
	Drop
	// CreateTable 'CREATE TABLE' query type
	CreateTable
	// TruncateTable 'TRUNCATE TABLE' query type
	TruncateTable
	// Show 'SHOW' query type
	Show
)

func (QueryType) IsWriteQuery

func (t QueryType) IsWriteQuery() bool

func (QueryType) String

func (t QueryType) String() string

Jump to

Keyboard shortcuts

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