sql

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SQLDateLayout is the go-formatted date representation of a SQL Basic Date
	SQLDateLayout = "2006-01-02"

	// SQLTimeLayout is the go-formatted date representation of a SQL Basic Date
	SQLTimeLayout = "15:04:05"

	// SQLDateTimeLayout is the go-formatted date representation of a SQL Basic DateTime
	SQLDateTimeLayout = SQLDateLayout + " " + SQLTimeLayout

	SQLDateTimeSubSec1Layout = SQLDateTimeLayout + ".0"
	SQLDateTimeSubSec2Layout = SQLDateTimeLayout + ".00"
	SQLDateTimeSubSec3Layout = SQLDateTimeLayout + ".000"
	SQLDateTimeSubSec4Layout = SQLDateTimeLayout + ".0000"
	SQLDateTimeSubSec5Layout = SQLDateTimeLayout + ".00000"
	SQLDateTimeSubSec6Layout = SQLDateTimeLayout + ".000000"
	SQLDateTimeSubSec7Layout = SQLDateTimeLayout + ".0000000"
	SQLDateTimeSubSec8Layout = SQLDateTimeLayout + ".00000000"
	SQLDateTimeSubSec9Layout = SQLDateTimeLayout + ".000000000"
)
View Source
const (
	TokenValNull = "null"
	TokenValNaN  = "nan"
	// keyword tokens
	TokenValWith        = "with"
	TokenValSelect      = "select"
	TokenValFrom        = "from"
	TokenValJoin        = "join"
	TokenValAs          = "as"
	TokenValWhere       = "where"
	TokenValBetween     = "between"
	TokenValGroupBy     = "group by"
	TokenValOrderBy     = "order by"
	TokenValLimit       = "limit"
	TokenValUnion       = "union"
	TokenValHaving      = "having"
	TokenValIntoOutfile = "into outfile"
	TokenValAnd         = "and"
	TokenValOr          = "or"
	TokenValNot         = "not"
	TokenValAsc         = "asc"
	TokenValDesc        = "desc"
	// functions
	TokenValNow   = "now()"
	TokenValCount = "count"
)

tokens for SELECT query

View Source
const (
	TimeFormatSQL         = 1
	TimeFormatUnixSecs    = 2
	TimeFormatUnixMilli   = 3
	TimeFormatUnixNano    = 4
	TimeFormatUnsupported = 255
)
View Source
const (
	// TokenSQLNonKeyword is the lower bound value for SQL non-Keyword tokens, and must not be
	// assigned to a Token.Typ
	TokenSQLNonKeyword token.Typ = iota + (token.CustomNonKeyword + 128)
	// TokenComment is a Comment Token Type
	// comments are useful to Trickster, so we provide them as their own Typ to the parser
	TokenComment
	// TokenNull represents a token of "NULL"
	TokenNull
	// TokenNaN represents a token of "NaN"
	TokenNaN
	// TokenSQLNonKeywordExtensions is the marker after which custom extensions to this section
	// may start, and must not be assigned to a Token.Typ
	TokenSQLNonKeywordExtensions
	// TokenSQLNonKeywordEnd is the upper bound value for SQL Words that are not Keywords, and
	// must not be assigned to a Token.Typ
	TokenSQLNonKeywordEnd = TokenSQLNonKeyword + 256 // allow room for custom sql tokens
	// TokenSQLKeyword is the lower bound value for SQL Keywords and must not be assigned to a Token.Typ
	TokenSQLKeyword token.Typ = iota + (token.CustomKeyword + 128)
	// TokenSQLPrimaryKeyword is the lower bound value for Primary SQL Keywords and must not be
	// assigned to a Token.Typ
	TokenSQLPrimaryKeyword
	// TokenSQLVerb is the lower bound value for SQL Verbs and must not be assigned to a Token.Typ
	TokenSQLVerb
	// TokenWith represents a token of "WITH"
	TokenWith
	// TokenSelect represents a token of "SELECT"
	TokenSelect
	// TokenInsert represents a token of "INSERT"
	TokenInsert
	// TokenUpdate represents a token of "UPDATE"
	TokenUpdate
	// TokenDelete represents a token of "DELETE"
	TokenDelete
	// TokenTruncate represents a token of "TRUNCATE"
	TokenTruncate
	// TokenAlter represents a token of "ALTER"
	TokenAlter
	// TokenCreate represents a token of "CREATE"
	TokenCreate
	// TokenSQLVerbExtensions is the marker after which custom extensions to this section
	// may start, and must not be assigned to a Token.Typ
	TokenSQLVerbExtensions
	// TokenSQLVerbEnd is the upper bound value for SQL Verbs and must not be assigned to a Token.Typ
	TokenSQLVerbEnd = TokenSQLVerb + 128 // allow room for custom sql verbs
	// TokenSQLNonVerb is the lower bound value for SQL non-Verb primary keywords
	// and must not be assigned to a Token.Typ
	TokenSQLNonVerb = iota + TokenSQLVerbEnd + 1
	// TokenFrom represents a token of "FROM"
	TokenFrom
	// TokenJoin represents a token of "JOIN"
	TokenJoin
	// TokenWhere represents a token of "WHERE"
	TokenWhere
	// TokenBetween represents a token of "BETWEEN"
	TokenBetween
	// TokenGroupBy represents a token of "GROUP BY"
	TokenGroupBy
	// TokenHaving represents a token of "HAVING"
	TokenHaving
	// TokenOrderBy represents a token of "ORDER BY"
	TokenOrderBy
	// TokenUnion Represents a token of "UNION"
	TokenUnion
	// TokenLimit represents a token of "LIMIT"
	TokenLimit
	// TokenIntoOutfile represents a token of "INTO OUTFILE"
	TokenIntoOutfile
	// TokenSQLNonVerbExtensions is the marker after which custom extensions to this section
	// may start, and must not be assigned to a Token.Typ
	TokenSQLNonVerbExtensions
	// TokenSQLNonVerbEnd is the upper bound value for SQL Verbs and must not
	// be assigned to a Token.Typ
	TokenSQLNonVerbEnd = TokenSQLNonVerb + 256
	// TokenSQLPrimaryKeywordEnd is the upper bound value for Primary SQL Keywords
	// and must not be assigned to a Token.Typ
	TokenSQLPrimaryKeywordEnd = iota + TokenSQLNonVerbEnd + 1
	// TokenNowFunc represents a token of now() which we consider more of a keyword than a func
	TokenNowFunc
	// TokenAs represents a token of "AS"
	TokenAs
	// TokenAsc represents a token of "ASC"
	TokenAsc
	// TokenDesc represents a token of "DESC"
	TokenDesc
	// TokenSQLKeywordExtensions is the marker after which custom extensions to this section
	// may start, and must not be assigned to a Token.Typ
	TokenSQLKeywordExtensions
	// TokenSQLKeywordEnd is the end delimiter for SQL Keywords and must not be assigned to a Token.Typ
	TokenSQLKeywordEnd = TokenSQLPrimaryKeywordEnd + 1 + 128
	// TokenSQLFunction is the lower bound value for SQL Built-in Functions() and must not be assigned to a Token.Typ
	TokenSQLFunction token.Typ = TokenSQLKeywordEnd + 1
	// TokenCount represents the count() function
	TokenCount
	// TokenSQLFunctionExtensions is the marker after which custom extensions to this section
	// may start, and must not be assigned to a Token.Typ
	TokenSQLFunctionExtensions
	// TokenSQLFunctionEnd is the upper bound value for SQL Built-in Functions() and must not be assigned to a Token.Typ
	TokenSQLFunctionEnd = TokenSQLFunction + 512
)

Variables

View Source
var ErrInvalidGroupByClause = errors.New("invalid GROUP BY expression list")

ErrInvalidGroupByClause indicates the GROUP BY clause of the query is not properly formatted

View Source
var ErrInvalidInputLength = errors.New("invalid input length")

ErrInvalidInputLength indicates the input length was invalid

View Source
var SpacedKeywords = func() map[string]int {
	return map[string]int{
		"group": 3,
		"order": 3,
		"into":  8,
		"now":   2,
	}
}

SpacedKeywords gives hints to lexIdentifier to check for keywords that have a space in them. the integer is length of the real keyword, minus the the key's length

Functions

func BaseKey

func BaseKey() map[string]token.Typ

BaseKey returns the base Key map for a SQL Lexer

func IsKeyword

func IsKeyword(t token.Typ) bool

IsKeyword returns true if the token is a known SQL Keyword based on value range

func IsNonVerbPrimaryKeyword

func IsNonVerbPrimaryKeyword(t token.Typ) bool

IsNonVerbPrimaryKeyword returns true if the token is a known Primary SQL Keyword that is also not a Verb (SELECT, INSERT, etc) based on value range.

func IsPrimaryKeyword

func IsPrimaryKeyword(t token.Typ) bool

IsPrimaryKeyword returns true if the token is a known Primary SQL Keyword based on value range

func IsVerb

func IsVerb(t token.Typ) bool

IsVerb returns true if the token is a known SQL Verb based on value range

func NewLexer

func NewLexer(lo *lex.Options) lex.Lexer

NewLexer returns a new SQL Lexer reference

func ParseBasicDateTime

func ParseBasicDateTime(input string) (time.Time, error)

ParseBasicDateTime parses a basic sql date time in the format of YYYY-MM-DD HH:MM:SS

func ParseTimeField

func ParseTimeField(t *token.Token) (int64, timeseries.FieldDataType, error)

func TokenToTime

func TokenToTime(i *token.Token) (time.Time, byte, error)

TokenToTime returns a time value derived from the token

func UnQuote

func UnQuote(input string) string

UnQuote removes the single quotes surrounding a string, but only if both are present

Types

This section is empty.

Jump to

Keyboard shortcuts

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