template

package
v0.0.0-...-13da7e0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntervalUnitWeek        = IntervalUnit(7 * 24 * time.Hour)
	IntervalUnitDay         = IntervalUnit(24 * time.Hour)
	IntervalUnitHour        = IntervalUnit(time.Hour)
	IntervalUnitMinute      = IntervalUnit(time.Minute)
	IntervalUnitSecond      = IntervalUnit(time.Second)
	IntervalUnitMillisecond = IntervalUnit(time.Millisecond)
	IntervalUnitMicrosecond = IntervalUnit(time.Microsecond)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Elems []Expr
}

func (*Array) String

func (a *Array) String() string

type BinaryExpr

type BinaryExpr struct {
	Op    Op
	Left  Expr
	Right Expr
}

func (*BinaryExpr) String

func (expr *BinaryExpr) String() string

type CaseValueWhen

type CaseValueWhen struct {
	Value Expr
	Whens []*When
	Else  Expr
}

func (*CaseValueWhen) String

func (c *CaseValueWhen) String() string

type Column

type Column struct {
	// Name is the name of the column. It is the first identifier before the
	// {{}} and /*{{}}*/ block. It can be empty if no identifier is found,
	// which means an anonymous column.
	//
	// e.g. `CREATE TABLE t ( /*{{ rownum }}*/ )` has an anonymous column.
	Name Name
	// Expr is the expression in the stmt block.
	Expr Expr
}

Column represents a column definition in a table.

type Constant

type Constant struct {
	constant.Value
}

Constant represents a constant value, numeric or string.

func (*Constant) String

func (c *Constant) String() string

type CurrentTimestamp

type CurrentTimestamp struct{}

func (*CurrentTimestamp) String

func (*CurrentTimestamp) String() string

type Expr

type Expr interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Expr represents an expression.

func ParseExpr

func ParseExpr(input string) (Expr, error)

type FuncExpr

type FuncExpr struct {
	Name *QName
	Args []Expr
}

func (*FuncExpr) String

func (f *FuncExpr) String() string

type GetVariable

type GetVariable struct {
	Name string
}

func (*GetVariable) String

func (gv *GetVariable) String() string

type Interval

type Interval struct {
	Unit  IntervalUnit
	Value Expr
}

func (*Interval) String

func (i *Interval) String() string

type IntervalUnit

type IntervalUnit time.Duration

func (IntervalUnit) String

func (u IntervalUnit) String() string

type Name

type Name struct {
	// O is the original name.
	O string
	// N is the normalized name. It is lower case, without quotation marks.
	N string
}

Name represents a name parsed from a template.

func NewName

func NewName(name string) Name

func (Name) String

func (n Name) String() string

type Op

type Op int
const (
	OpInvalid Op = iota
	OpAssign
	OpLT
	OpLE
	OpGT
	OpGE
	OpEQ
	OpNE
	OpConcat
	OpAdd
	OpSub
	OpMul
	OpFloatDiv
	OpBitAnd
	OpBitOr
	OpBitXor
	OpBitNot
	OpSemicolon
	OpOr
	OpAnd
	OpNot
	OpIs
	OpIsNot
)

func (Op) IsBinary

func (op Op) IsBinary() bool

func (Op) IsRightAssoc

func (op Op) IsRightAssoc() bool

func (Op) Prec

func (op Op) Prec() int

func (Op) String

func (op Op) String() string

type Overlay

type Overlay struct {
	Input   Expr
	Placing Expr
	From    Expr
	For     Expr
	Unit    StringUnit
}

func (*Overlay) String

func (o *Overlay) String() string

type ParenExpr

type ParenExpr struct {
	Expr Expr
}

func (*ParenExpr) String

func (expr *ParenExpr) String() string

type Parser

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

Parser is a parser for templates.

func (*Parser) Parse

func (p *Parser) Parse(input string) (*Template, error)

func (*Parser) ParseExpr

func (p *Parser) ParseExpr(input string) (Expr, error)

type QName

type QName struct {
	// Parts represents the name parts of a schema-qualified name.
	Parts []Name
}

QName is schema-qualified name with quotation marks still intact. e.g. "db"."schema"."table".

func NewQName

func NewQName(names ...string) *QName

NewQName creates a new QName from the given name parts.

func (*QName) Equal

func (q *QName) Equal(other *QName) bool

func (*QName) Name

func (q *QName) Name(qualified bool) string

func (*QName) SchemaName

func (q *QName) SchemaName() string

func (*QName) String

func (q *QName) String() string

func (*QName) UniqueName

func (q *QName) UniqueName() string

type RowNum

type RowNum struct{}

func (*RowNum) String

func (*RowNum) String() string

type SetVariable

type SetVariable struct {
	Name  string
	Value Expr
}

func (*SetVariable) String

func (sv *SetVariable) String() string

type StringUnit

type StringUnit int

StringUnit specifies how to index a (byte) string.

const (
	// StringUnitCharacters indexes the string using characters (code points).
	StringUnitCharacters StringUnit = iota + 1
	// StringUnitOctets indexes the string using bytes (code unit).
	StringUnitOctets
)

type SubRowNum

type SubRowNum struct{}

func (*SubRowNum) String

func (*SubRowNum) String() string

type Subscript

type Subscript struct {
	Base  Expr
	Index Expr
}

func (*Subscript) String

func (s *Subscript) String() string

type Substring

type Substring struct {
	Input Expr
	From  Expr
	For   Expr
	Unit  StringUnit
}

func (*Substring) String

func (s *Substring) String() string

type SyntaxError

type SyntaxError struct {
	Line   int
	Column int
	Near   string
	Cause  string
}

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type Table

type Table struct {
	Name *QName
	// Content is the content of whole create table statement
	// with the {{}} and /*{{}}*/ blocks removed.
	Content string
	// Columns is the list of columns in the table.
	Columns []*Column
	// Derived is the indices of derived tables and the number of rows to generate.
	Derived []lo.Tuple2[int, Expr]
}

Table represents a table in a template.

type Template

type Template struct {
	GlobalExprs []Expr
	Tables      []*Table
}

Template represents a template.

func Parse

func Parse(input string) (*Template, error)

type Timestamp

type Timestamp struct {
	WithTimezone bool
	Value        Expr
}

func (*Timestamp) String

func (t *Timestamp) String() string

type UnaryExpr

type UnaryExpr struct {
	Op   Op
	Expr Expr
}

func (*UnaryExpr) String

func (expr *UnaryExpr) String() string

type When

type When struct {
	Cond Expr
	Then Expr
}

func (*When) String

func (w *When) String() string

Jump to

Keyboard shortcuts

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