sql

package
v0.3.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoolType     = "bool"
	BigIntType   = "bigint"
	StringType   = "string"
	DatetimeType = "datetime"
)

Variables

View Source
var (
	ErrDistinct          = errors.New("DISTINCT is not supported")
	ErrNotFoundTable     = errors.New("not found table")
	ErrJoin              = errors.New("JOIN is not supported")
	ErrTableAlias        = errors.New("table alias is not supported")
	ErrTableQualifier    = errors.New("table qualifier is not supported")
	ErrDBQualifier       = errors.New("database name qualifier is not supported")
	ErrSubquery          = errors.New("subquery is not supported")
	ErrStar              = errors.New("\"*\" and other columns are exclusive")
	ErrColumnAlias       = errors.New("column alias is not supported")
	ErrColumnQualifier   = errors.New("column qualifier is not supported")
	ErrColumnList        = errors.New("column list MUST NOT contain anything other than field names")
	ErrUnsupportedStmt   = errors.New("this statement is not supported")
	ErrGroupBy           = errors.New("GROUP BY is not supported")
	ErrHaving            = errors.New("HAVING is not supported")
	ErrOrderBy           = errors.New("ORDER BY is not supported")
	ErrLimit             = errors.New("LIMIT is not supported")
	ErrFunctionQualifier = errors.New("function qualifier is not supported")
)

Functions

This section is empty.

Types

type AndOp

type AndOp struct {
	Left  SqlAny
	Right SqlAny
}

func (*AndOp) BigInt

func (o *AndOp) BigInt() int64

func (*AndOp) Bool

func (o *AndOp) Bool() bool

func (*AndOp) Const

func (o *AndOp) Const() bool

func (*AndOp) Datetime

func (o *AndOp) Datetime() types.Time

func (*AndOp) String

func (o *AndOp) String() string

func (*AndOp) Type

func (o *AndOp) Type() string

func (*AndOp) WithRow

func (o *AndOp) WithRow(row SqlRow)

type CompOp

type CompOp struct {
	Operator string
	Left     SqlAny
	Right    SqlAny
	// contains filtered or unexported fields
}

func (*CompOp) BigInt

func (o *CompOp) BigInt() int64

func (*CompOp) Bool

func (o *CompOp) Bool() bool

func (*CompOp) Const

func (o *CompOp) Const() bool

func (*CompOp) Datetime

func (o *CompOp) Datetime() types.Time

func (*CompOp) String

func (o *CompOp) String() string

func (*CompOp) Type

func (o *CompOp) Type() string

func (*CompOp) WithRow

func (o *CompOp) WithRow(row SqlRow)

type Field

type Field struct {
	// table name
	Table string
	// field name
	Name string
	// display name
	AliasName string
}

func (Field) LongName

func (f Field) LongName() string

func (Field) String

func (f Field) String() string

type NotOp

type NotOp struct {
	Expr SqlAny
}

func (*NotOp) BigInt

func (o *NotOp) BigInt() int64

func (*NotOp) Bool

func (o *NotOp) Bool() bool

func (*NotOp) Const

func (o *NotOp) Const() bool

func (*NotOp) Datetime

func (o *NotOp) Datetime() types.Time

func (*NotOp) String

func (o *NotOp) String() string

func (*NotOp) Type

func (o *NotOp) Type() string

func (*NotOp) WithRow

func (o *NotOp) WithRow(row SqlRow)

type OrOp

type OrOp struct {
	Left  SqlAny
	Right SqlAny
}

func (*OrOp) BigInt

func (o *OrOp) BigInt() int64

func (*OrOp) Bool

func (o *OrOp) Bool() bool

func (*OrOp) Const

func (o *OrOp) Const() bool

func (*OrOp) Datetime

func (o *OrOp) Datetime() types.Time

func (*OrOp) String

func (o *OrOp) String() string

func (*OrOp) Type

func (o *OrOp) Type() string

func (*OrOp) WithRow

func (o *OrOp) WithRow(row SqlRow)

type OutputFormat

type OutputFormat int
const (
	CsvFormat OutputFormat = iota
)

type RangeOp

type RangeOp struct {
	Left SqlAny
	From SqlAny
	To   SqlAny
}

func (*RangeOp) BigInt

func (r *RangeOp) BigInt() int64

func (*RangeOp) Bool

func (r *RangeOp) Bool() bool

func (*RangeOp) Const

func (r *RangeOp) Const() bool

func (*RangeOp) Datetime

func (r *RangeOp) Datetime() types.Time

func (*RangeOp) String

func (r *RangeOp) String() string

func (*RangeOp) Type

func (r *RangeOp) Type() string

func (*RangeOp) WithRow

func (r *RangeOp) WithRow(row SqlRow)

type SelectParser

type SelectParser struct {
	Stmt *sqlparser.Select
	// contains filtered or unexported fields
}

func ParseSelect

func ParseSelect(sql string) (*SelectParser, error)

ParseSelect parses the SELECT statement.

func (*SelectParser) ColNames

func (s *SelectParser) ColNames() []string

func (*SelectParser) Cols

func (s *SelectParser) Cols() []Field

func (*SelectParser) From

func (s *SelectParser) From() string

func (*SelectParser) Limit

func (s *SelectParser) Limit() (offset, rows int64)

func (*SelectParser) Parse

func (s *SelectParser) Parse() error

parseSelect parses a "SELECT" statement.

func (*SelectParser) Where

func (s *SelectParser) Where() SqlAny

type SqlAny

type SqlAny interface {
	Bool() bool
	BigInt() int64
	String() string
	Datetime() types.Time

	// 定数として扱えるならtrueを返す。
	Const() bool
	// データ型を文字列として返す。
	Type() string
	// row には *types.FuncLog のような特定のデータ型のポインタを格納する。
	// 処理対象の行を変更したい場合は、ここで渡したポインタの先を書き換える。
	// Const() がtrueを返すなら、これを設定する必要ない。
	// 不正なフィールド名などが指定されていた場合、これはpanicする場合がある。
	// 呼び出し元は適切にrecover()などで適切にハンドルする必要がある。
	WithRow(row SqlRow)
}

このシステム内で扱う全てのデータ型

type SqlBigInt

type SqlBigInt int64

func (SqlBigInt) BigInt

func (b SqlBigInt) BigInt() int64

func (SqlBigInt) Bool

func (b SqlBigInt) Bool() bool

func (SqlBigInt) Const

func (b SqlBigInt) Const() bool

func (SqlBigInt) Datetime

func (b SqlBigInt) Datetime() types.Time

func (SqlBigInt) String

func (b SqlBigInt) String() string

func (SqlBigInt) Type

func (b SqlBigInt) Type() string

func (SqlBigInt) WithRow

func (b SqlBigInt) WithRow(row SqlRow)

type SqlBool

type SqlBool bool

func (SqlBool) BigInt

func (b SqlBool) BigInt() int64

func (SqlBool) Bool

func (b SqlBool) Bool() bool

func (SqlBool) Const

func (b SqlBool) Const() bool

func (SqlBool) Datetime

func (b SqlBool) Datetime() types.Time

func (SqlBool) String

func (b SqlBool) String() string

func (SqlBool) Type

func (b SqlBool) Type() string

func (SqlBool) WithRow

func (b SqlBool) WithRow(row SqlRow)

type SqlDatetime

type SqlDatetime types.Time

func (SqlDatetime) BigInt

func (d SqlDatetime) BigInt() int64

func (SqlDatetime) Bool

func (d SqlDatetime) Bool() bool

func (SqlDatetime) Const

func (d SqlDatetime) Const() bool

func (SqlDatetime) Datetime

func (d SqlDatetime) Datetime() types.Time

func (SqlDatetime) String

func (d SqlDatetime) String() string

func (SqlDatetime) Type

func (d SqlDatetime) Type() string

func (SqlDatetime) WithRow

func (d SqlDatetime) WithRow(row SqlRow)

type SqlField

type SqlField struct {
	Field Field
	// contains filtered or unexported fields
}

テーブルの1つのフィールドを表す。 これの値を取得するときは、先にWithRow()で処理対象の行を指定すること。

func (*SqlField) BigInt

func (f *SqlField) BigInt() int64

func (*SqlField) Bool

func (f *SqlField) Bool() bool

func (*SqlField) Const

func (f *SqlField) Const() bool

func (*SqlField) Datetime

func (f *SqlField) Datetime() types.Time

func (*SqlField) String

func (f *SqlField) String() string

func (*SqlField) Type

func (f *SqlField) Type() string

func (*SqlField) WithRow

func (f *SqlField) WithRow(row SqlRow)

type SqlFieldGetter

type SqlFieldGetter func() SqlAny

SqlFieldGetter は SqlAny.WithRow() で指定した行の特定のフィールドを返す。 対象の行やoffsetが変更になった場合、既存の SqlFieldGetter も変更後のフィールドを返す。

func (SqlFieldGetter) Printer

func (g SqlFieldGetter) Printer(format OutputFormat) SqlFieldPrinter

type SqlFieldGetters

type SqlFieldGetters []SqlFieldGetter

func (SqlFieldGetters) Printer

func (gs SqlFieldGetters) Printer(format OutputFormat) (p SqlFieldPrinter)

type SqlFieldPrinter

type SqlFieldPrinter func(buf []byte) int64

SqlFieldPrinter は SqlAny.WithRow() で指定した行を特定の文字列フォーマットに変換する。 引数で指定したバッファに変換後の文字列を書き込み、書き込んだバイト数を戻り地として返す。 バッファサイズが足りない場合、この関数はpanicする。 SqlFieldGetter 同様に、処理対象の行が変更になると既存の SqlFieldPrinter も変更後の文字列を返す。

type SqlFunc

type SqlFunc struct {
	Name string
	// 関数の引数で、テーブル名が省略された場合に補完するテーブル名。
	// 空の場合は、関数呼び出し元の設定が適用される。
	Table string
	Parse func(args ...SqlAny) SqlAny
}

type SqlFuncAddTime

type SqlFuncAddTime struct {
	Base SqlAny
	Diff SqlAny
}

func (*SqlFuncAddTime) BigInt

func (d *SqlFuncAddTime) BigInt() int64

func (*SqlFuncAddTime) Bool

func (d *SqlFuncAddTime) Bool() bool

func (*SqlFuncAddTime) Const

func (d *SqlFuncAddTime) Const() bool

func (*SqlFuncAddTime) Datetime

func (d *SqlFuncAddTime) Datetime() types.Time

func (*SqlFuncAddTime) String

func (d *SqlFuncAddTime) String() string

func (*SqlFuncAddTime) Type

func (d *SqlFuncAddTime) Type() string

func (*SqlFuncAddTime) WithRow

func (d *SqlFuncAddTime) WithRow(row SqlRow)

type SqlFuncCall

type SqlFuncCall struct {
	Expr SqlAny
	// contains filtered or unexported fields
}

func (*SqlFuncCall) BigInt

func (d *SqlFuncCall) BigInt() int64

func (*SqlFuncCall) Bool

func (d *SqlFuncCall) Bool() bool

func (*SqlFuncCall) Const

func (d *SqlFuncCall) Const() bool

func (*SqlFuncCall) Datetime

func (d *SqlFuncCall) Datetime() types.Time

func (*SqlFuncCall) String

func (d *SqlFuncCall) String() string

func (*SqlFuncCall) Type

func (d *SqlFuncCall) Type() string

func (*SqlFuncCall) WithRow

func (d *SqlFuncCall) WithRow(row SqlRow)

type SqlFuncFrame

type SqlFuncFrame struct {
	Expr SqlAny
	// contains filtered or unexported fields
}

func (*SqlFuncFrame) BigInt

func (d *SqlFuncFrame) BigInt() int64

func (*SqlFuncFrame) Bool

func (d *SqlFuncFrame) Bool() bool

func (*SqlFuncFrame) Const

func (d *SqlFuncFrame) Const() bool

func (*SqlFuncFrame) Datetime

func (d *SqlFuncFrame) Datetime() types.Time

func (*SqlFuncFrame) String

func (d *SqlFuncFrame) String() string

func (*SqlFuncFrame) Type

func (d *SqlFuncFrame) Type() string

func (*SqlFuncFrame) WithRow

func (d *SqlFuncFrame) WithRow(row SqlRow)

type SqlFuncLogRow

type SqlFuncLogRow struct {
	// 処理対象の FuncLog へのポインタ。
	// このポインタ、またはその先のデータを書き換えることで、 SqlFieldGetter が返す値を変更できる。
	FuncLog *types.FuncLog
	Symbols *types.Symbols
	// contains filtered or unexported fields
}

func (*SqlFuncLogRow) Field

func (r *SqlFuncLogRow) Field(field Field) SqlFieldGetter

func (*SqlFuncLogRow) Fields

func (r *SqlFuncLogRow) Fields(fields []Field) SqlFieldGetters

func (*SqlFuncLogRow) MaxOffset

func (r *SqlFuncLogRow) MaxOffset() int

func (*SqlFuncLogRow) SetOffset

func (r *SqlFuncLogRow) SetOffset(offset int)

type SqlFuncNow

type SqlFuncNow struct {
}

func (*SqlFuncNow) BigInt

func (d *SqlFuncNow) BigInt() int64

func (*SqlFuncNow) Bool

func (d *SqlFuncNow) Bool() bool

func (*SqlFuncNow) Const

func (d *SqlFuncNow) Const() bool

func (*SqlFuncNow) Datetime

func (d *SqlFuncNow) Datetime() types.Time

func (*SqlFuncNow) String

func (d *SqlFuncNow) String() string

func (*SqlFuncNow) Type

func (d *SqlFuncNow) Type() string

func (*SqlFuncNow) WithRow

func (d *SqlFuncNow) WithRow(row SqlRow)

type SqlFuncSubTime

type SqlFuncSubTime struct {
	Base SqlAny
	Diff SqlAny
}

func (*SqlFuncSubTime) BigInt

func (d *SqlFuncSubTime) BigInt() int64

func (*SqlFuncSubTime) Bool

func (d *SqlFuncSubTime) Bool() bool

func (*SqlFuncSubTime) Const

func (d *SqlFuncSubTime) Const() bool

func (*SqlFuncSubTime) Datetime

func (d *SqlFuncSubTime) Datetime() types.Time

func (*SqlFuncSubTime) String

func (d *SqlFuncSubTime) String() string

func (*SqlFuncSubTime) Type

func (d *SqlFuncSubTime) Type() string

func (*SqlFuncSubTime) WithRow

func (d *SqlFuncSubTime) WithRow(row SqlRow)

type SqlGoFuncRow

type SqlGoFuncRow struct {
	GoFunc  *types.GoFunc
	Symbols *types.Symbols
}

func (*SqlGoFuncRow) Field

func (r *SqlGoFuncRow) Field(field Field) SqlFieldGetter

func (*SqlGoFuncRow) Fields

func (r *SqlGoFuncRow) Fields(fields []Field) SqlFieldGetters

func (*SqlGoFuncRow) MaxOffset

func (r *SqlGoFuncRow) MaxOffset() int

func (*SqlGoFuncRow) SetOffset

func (r *SqlGoFuncRow) SetOffset(offset int)

type SqlGoModuleRow

type SqlGoModuleRow struct {
	*types.GoModule
}

func (*SqlGoModuleRow) Field

func (r *SqlGoModuleRow) Field(field Field) SqlFieldGetter

func (*SqlGoModuleRow) Fields

func (r *SqlGoModuleRow) Fields(fields []Field) SqlFieldGetters

func (*SqlGoModuleRow) MaxOffset

func (r *SqlGoModuleRow) MaxOffset() int

func (*SqlGoModuleRow) SetOffset

func (r *SqlGoModuleRow) SetOffset(offset int)

type SqlGoroutineRow

type SqlGoroutineRow struct {
	types.Goroutine
}

func (*SqlGoroutineRow) Field

func (r *SqlGoroutineRow) Field(field Field) SqlFieldGetter

func (*SqlGoroutineRow) Fields

func (r *SqlGoroutineRow) Fields(fields []Field) SqlFieldGetters

func (*SqlGoroutineRow) MaxOffset

func (r *SqlGoroutineRow) MaxOffset() int

func (*SqlGoroutineRow) SetOffset

func (r *SqlGoroutineRow) SetOffset(offset int)

type SqlRow

type SqlRow interface {
	// 指定したフィールドを返す SqlFieldGetter を作成して返す。
	// 指定したテーブルや列が存在しない場合はpanicする。
	// 複数行を処理する場合は、パフォーマンス向上のために SqlFieldGetter を再利用するべき。
	Field(field Field) SqlFieldGetter
	// 指定したフィールドの SqlFieldGetter を全て返す。
	Fields(fields []Field) SqlFieldGetters
	// 対象となる types.FuncLog.Frames のインデックスを指定する。
	SetOffset(offset int)
	// 現時点での types.FuncLog.Frames の長さを返す。
	MaxOffset() int
}

SqlRow は処理対象の1つの行を表すデータ型。

type SqlString

type SqlString string

func (SqlString) BigInt

func (s SqlString) BigInt() int64

func (SqlString) Bool

func (s SqlString) Bool() bool

func (SqlString) Const

func (s SqlString) Const() bool

func (SqlString) Datetime

func (s SqlString) Datetime() types.Time

func (SqlString) String

func (s SqlString) String() string

func (SqlString) Type

func (s SqlString) Type() string

func (SqlString) WithRow

func (s SqlString) WithRow(row SqlRow)

type Table

type Table struct {
	Name   string
	Fields []string
	// a table name that can be implicitly joined.
	ImplictJoin string
}

func (Table) HasField

func (t Table) HasField(name string) bool

Jump to

Keyboard shortcuts

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