Enable text formatting for some sql ast structs
This commit is contained in:
parent
d66e5d1a01
commit
b5ff2cc1cb
2 changed files with 37 additions and 1 deletions
34
sql/ast.go
34
sql/ast.go
|
@ -268,7 +268,7 @@ type DefineIndexStatement struct {
|
||||||
Name string `cork:"name" codec:"name"`
|
Name string `cork:"name" codec:"name"`
|
||||||
What []string `cork:"-" codec:"-"`
|
What []string `cork:"-" codec:"-"`
|
||||||
Cols []string `cork:"cols" codec:"cols"`
|
Cols []string `cork:"cols" codec:"cols"`
|
||||||
Uniq bool `cork:"unique" codec:"unique"`
|
Uniq bool `cork:"uniq" codec:"uniq"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveIndexStatement represents an SQL REMOVE INDEX statement.
|
// RemoveIndexStatement represents an SQL REMOVE INDEX statement.
|
||||||
|
@ -317,18 +317,38 @@ type All struct{}
|
||||||
// Asc represents the ASC expression.
|
// Asc represents the ASC expression.
|
||||||
type Asc struct{}
|
type Asc struct{}
|
||||||
|
|
||||||
|
func (this Asc) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte("~ASC~"), err
|
||||||
|
}
|
||||||
|
|
||||||
// Desc represents the DESC expression.
|
// Desc represents the DESC expression.
|
||||||
type Desc struct{}
|
type Desc struct{}
|
||||||
|
|
||||||
|
func (this Desc) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte("~DESC~"), err
|
||||||
|
}
|
||||||
|
|
||||||
// Null represents a null expression.
|
// Null represents a null expression.
|
||||||
type Null struct{}
|
type Null struct{}
|
||||||
|
|
||||||
|
func (this Null) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte("~NULL~"), err
|
||||||
|
}
|
||||||
|
|
||||||
// Void represents an expression which is not set.
|
// Void represents an expression which is not set.
|
||||||
type Void struct{}
|
type Void struct{}
|
||||||
|
|
||||||
|
func (this Void) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte("~VOID~"), err
|
||||||
|
}
|
||||||
|
|
||||||
// Empty represents an expression which is null or "".
|
// Empty represents an expression which is null or "".
|
||||||
type Empty struct{}
|
type Empty struct{}
|
||||||
|
|
||||||
|
func (this Empty) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte("~EMPTY~"), err
|
||||||
|
}
|
||||||
|
|
||||||
// Field represents a SELECT AS clause.
|
// Field represents a SELECT AS clause.
|
||||||
type Field struct {
|
type Field struct {
|
||||||
Expr Expr
|
Expr Expr
|
||||||
|
@ -386,6 +406,10 @@ func (this Ident) String() string {
|
||||||
return this.ID
|
return this.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this Ident) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte("ID:" + this.ID), err
|
||||||
|
}
|
||||||
|
|
||||||
func NewIdent(ID string) *Ident {
|
func NewIdent(ID string) *Ident {
|
||||||
return &Ident{ID}
|
return &Ident{ID}
|
||||||
}
|
}
|
||||||
|
@ -403,6 +427,10 @@ func (this Table) String() string {
|
||||||
return this.TB
|
return this.TB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this Table) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte("TB:" + this.TB), err
|
||||||
|
}
|
||||||
|
|
||||||
func NewTable(TB string) *Table {
|
func NewTable(TB string) *Table {
|
||||||
return &Table{TB}
|
return &Table{TB}
|
||||||
}
|
}
|
||||||
|
@ -421,6 +449,10 @@ func (this Thing) String() string {
|
||||||
return fmt.Sprintf("@%s:%v", this.TB, this.ID)
|
return fmt.Sprintf("@%s:%v", this.TB, this.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this Thing) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte(this.String()), err
|
||||||
|
}
|
||||||
|
|
||||||
func NewThing(TB string, ID interface{}) *Thing {
|
func NewThing(TB string, ID interface{}) *Thing {
|
||||||
if str, ok := ID.(string); ok {
|
if str, ok := ID.(string); ok {
|
||||||
if cnv, err := strconv.ParseInt(str, 10, 64); err == nil {
|
if cnv, err := strconv.ParseInt(str, 10, 64); err == nil {
|
||||||
|
|
|
@ -418,6 +418,10 @@ func (tok Token) String() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tok Token) MarshalText() (data []byte, err error) {
|
||||||
|
return []byte(tok.String()), err
|
||||||
|
}
|
||||||
|
|
||||||
func (tok Token) isLiteral() bool { return tok > literalsBeg && tok < literalsEnd }
|
func (tok Token) isLiteral() bool { return tok > literalsBeg && tok < literalsEnd }
|
||||||
|
|
||||||
func (tok Token) isKeyword() bool { return tok > keywordsBeg && tok < keywordsEnd }
|
func (tok Token) isKeyword() bool { return tok > keywordsBeg && tok < keywordsEnd }
|
||||||
|
|
Loading…
Reference in a new issue