Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DIALECTS = []Dialect{ DialectMSSQL, DialectSQLite, DialectMySQL, DialectOracle, DialectPSQL, DialectBigQuery, DialectGeneric, }
View Source
var ExecutionTypes = map[StatementType]ExecutionType{ StatementSelect: ExecutionListing, StatementInsert: ExecutionModification, StatementDelete: ExecutionModification, StatementUpdate: ExecutionModification, StatementTruncate: ExecutionModification, StatementCreateDatabase: ExecutionModification, StatementCreateSchema: ExecutionModification, StatementCreateTable: ExecutionModification, StatementCreateView: ExecutionModification, StatementCreateTrigger: ExecutionModification, StatementCreateFunction: ExecutionModification, StatementCreateIndex: ExecutionModification, StatementCreateProcedure: ExecutionModification, StatementShowBinary: ExecutionListing, StatementShowBinlog: ExecutionListing, StatementShowCharacter: ExecutionListing, StatementShowCollation: ExecutionListing, StatementShowCreate: ExecutionListing, StatementShowEngine: ExecutionListing, StatementShowEngines: ExecutionListing, StatementShowErrors: ExecutionListing, StatementShowEvents: ExecutionListing, StatementShowFunction: ExecutionListing, StatementShowGrants: ExecutionListing, StatementShowMaster: ExecutionListing, StatementShowOpen: ExecutionListing, StatementShowPlugins: ExecutionListing, StatementShowPrivileges: ExecutionListing, StatementShowProcedure: ExecutionListing, StatementShowProcesslist: ExecutionListing, StatementShowProfile: ExecutionListing, StatementShowProfiles: ExecutionListing, StatementShowRelaylog: ExecutionListing, StatementShowReplicas: ExecutionListing, StatementShowSlave: ExecutionListing, StatementShowReplica: ExecutionListing, StatementShowStatus: ExecutionListing, StatementShowTriggers: ExecutionListing, StatementShowVariables: ExecutionListing, StatementShowWarnings: ExecutionListing, StatementShowDatabases: ExecutionListing, StatementShowKeys: ExecutionListing, StatementShowIndex: ExecutionListing, StatementShowTable: ExecutionListing, StatementShowTables: ExecutionListing, StatementShowColumns: ExecutionListing, StatementDropDatabase: ExecutionModification, StatementDropSchema: ExecutionModification, StatementDropTable: ExecutionModification, StatementDropView: ExecutionModification, StatementDropTrigger: ExecutionModification, StatementDropFunction: ExecutionModification, StatementDropIndex: ExecutionModification, StatementDropProcedure: ExecutionModification, StatementAlterDatabase: ExecutionModification, StatementAlterSchema: ExecutionModification, StatementAlterTable: ExecutionModification, StatementAlterView: ExecutionModification, StatementAlterTrigger: ExecutionModification, StatementAlterFunction: ExecutionModification, StatementAlterIndex: ExecutionModification, StatementAlterProcedure: ExecutionModification, StatementUnknown: ExecutionUnknown, StatementAnonBlock: ExecutionAnonBlock, }
maps statement types to their execution behavior
Functions ¶
This section is empty.
Types ¶
type AcceptToken ¶
type ConcreteStatement ¶
type ExecutionType ¶
type ExecutionType string
represents the behavior of a statement (e.g., LISTING, MODIFICATION)
const ( ExecutionListing ExecutionType = "LISTING" ExecutionModification ExecutionType = "MODIFICATION" ExecutionInformation ExecutionType = "INFORMATION" ExecutionAnonBlock ExecutionType = "ANON_BLOCK" ExecutionUnknown ExecutionType = "UNKNOWN" )
func GetExecutionType ¶
func GetExecutionType(command StatementType) ExecutionType
type IdentifyOptions ¶
type IdentifyOptions struct {
Strict *bool
Dialect *Dialect
IdentifyTables *bool
ParamTypes *ParamTypes
}
provides configuration for the Identify function
type IdentifyResult ¶
type IdentifyResult struct {
Start int `json:"start"`
End int `json:"end"`
Text string `json:"text"`
Type StatementType `json:"type"`
ExecutionType ExecutionType `json:"executionType"`
Parameters []string `json:"parameters"`
Tables []string `json:"tables"`
}
represents a single parsed SQL statement
func Identify ¶
func Identify(query string, options IdentifyOptions) (results []IdentifyResult, err error)
type ParamTypes ¶
type ParamTypes struct {
Positional *bool
Numbered []rune // '?' | ':' | '$'
Named []rune // ':' | '@' | '$'
Quoted []rune // ':' | '@' | '$'
Custom []string
}
func DefaultParamTypesFor ¶
func DefaultParamTypesFor(dialect Dialect) *ParamTypes
returns the default parameter types for a given SQL dialect
type ParseOptions ¶
type ParseOptions struct {
IsStrict bool
Dialect Dialect
IdentifyTables bool
ParamTypes *ParamTypes
}
type ParseResult ¶
type ParseResult struct {
Type string `json:"type"`
Start int `json:"start"`
End int `json:"end"`
Body []ConcreteStatement `json:"body"`
Tokens []Token `json:"tokens"`
}
func Parse ¶
func Parse(input string, isStrict bool, dialect Dialect, identifyTables bool, paramTypes *ParamTypes) *ParseResult
type Statement ¶
type Statement struct {
Start int
End int
Type *StatementType
ExecutionType *ExecutionType
EndStatement *string
CanEnd *bool
Definer *int
Algorithm *int
SQLSecurity *int
Parameters []string
Tables []string
IsCte *bool
}
func (*Statement) ToConcrete ¶
func (s *Statement) ToConcrete() ConcreteStatement
type StatementParser ¶
type StatementType ¶
type StatementType string
represents the type of a SQL statement (e.g., SELECT, INSERT)
const ( StatementInsert StatementType = "INSERT" StatementUpdate StatementType = "UPDATE" StatementDelete StatementType = "DELETE" StatementSelect StatementType = "SELECT" StatementTruncate StatementType = "TRUNCATE" StatementCreateDatabase StatementType = "CREATE_DATABASE" StatementCreateSchema StatementType = "CREATE_SCHEMA" StatementCreateTable StatementType = "CREATE_TABLE" StatementCreateView StatementType = "CREATE_VIEW" StatementCreateTrigger StatementType = "CREATE_TRIGGER" StatementCreateFunction StatementType = "CREATE_FUNCTION" StatementCreateIndex StatementType = "CREATE_INDEX" StatementCreateProcedure StatementType = "CREATE_PROCEDURE" StatementShowBinary StatementType = "SHOW_BINARY" StatementShowBinlog StatementType = "SHOW_BINLOG" StatementShowCharacter StatementType = "SHOW_CHARACTER" StatementShowCollation StatementType = "SHOW_COLLATION" StatementShowCreate StatementType = "SHOW_CREATE" StatementShowEngine StatementType = "SHOW_ENGINE" StatementShowEngines StatementType = "SHOW_ENGINES" StatementShowErrors StatementType = "SHOW_ERRORS" StatementShowEvents StatementType = "SHOW_EVENTS" StatementShowFunction StatementType = "SHOW_FUNCTION" StatementShowGrants StatementType = "SHOW_GRANTS" StatementShowMaster StatementType = "SHOW_MASTER" StatementShowOpen StatementType = "SHOW_OPEN" StatementShowPlugins StatementType = "SHOW_PLUGINS" StatementShowPrivileges StatementType = "SHOW_PRIVILEGES" StatementShowProcedure StatementType = "SHOW_PROCEDURE" StatementShowProcesslist StatementType = "SHOW_PROCESSLIST" StatementShowProfile StatementType = "SHOW_PROFILE" StatementShowProfiles StatementType = "SHOW_PROFILES" StatementShowRelaylog StatementType = "SHOW_RELAYLOG" StatementShowReplicas StatementType = "SHOW_REPLICAS" StatementShowSlave StatementType = "SHOW_SLAVE" StatementShowReplica StatementType = "SHOW_REPLICA" StatementShowStatus StatementType = "SHOW_STATUS" StatementShowTriggers StatementType = "SHOW_TRIGGERS" StatementShowVariables StatementType = "SHOW_VARIABLES" StatementShowWarnings StatementType = "SHOW_WARNINGS" StatementShowDatabases StatementType = "SHOW_DATABASES" StatementShowKeys StatementType = "SHOW_KEYS" StatementShowIndex StatementType = "SHOW_INDEX" StatementShowTable StatementType = "SHOW_TABLE" StatementShowTables StatementType = "SHOW_TABLES" StatementShowColumns StatementType = "SHOW_COLUMNS" StatementDropDatabase StatementType = "DROP_DATABASE" StatementDropSchema StatementType = "DROP_SCHEMA" StatementDropTable StatementType = "DROP_TABLE" StatementDropView StatementType = "DROP_VIEW" StatementDropTrigger StatementType = "DROP_TRIGGER" StatementDropFunction StatementType = "DROP_FUNCTION" StatementDropIndex StatementType = "DROP_INDEX" StatementDropProcedure StatementType = "DROP_PROCEDURE" StatementAlterDatabase StatementType = "ALTER_DATABASE" StatementAlterSchema StatementType = "ALTER_SCHEMA" StatementAlterTable StatementType = "ALTER_TABLE" StatementAlterView StatementType = "ALTER_VIEW" StatementAlterTrigger StatementType = "ALTER_TRIGGER" StatementAlterFunction StatementType = "ALTER_FUNCTION" StatementAlterIndex StatementType = "ALTER_INDEX" StatementAlterProcedure StatementType = "ALTER_PROCEDURE" StatementAnonBlock StatementType = "ANON_BLOCK" StatementUnknown StatementType = "UNKNOWN" )
type StepValidation ¶
type StepValidation struct {
RequireBefore []string
AcceptTokens []AcceptToken
}
type Token ¶
type TokenType ¶
type TokenType string
const ( TokenWhitespace TokenType = "whitespace" TokenCommentInline TokenType = "comment-inline" TokenCommentBlock TokenType = "comment-block" TokenString TokenType = "string" TokenSemicolon TokenType = "semicolon" TokenKeyword TokenType = "keyword" TokenParameter TokenType = "parameter" TokenTable TokenType = "table" TokenUnknown TokenType = "unknown" )
Click to show internal directories.
Click to hide internal directories.