Enable text formatting for some sql ast structs

This commit is contained in:
Tobie Morgan Hitchcock 2016-10-14 22:52:57 +01:00
parent d66e5d1a01
commit b5ff2cc1cb
2 changed files with 37 additions and 1 deletions

View file

@ -268,7 +268,7 @@ type DefineIndexStatement struct {
Name string `cork:"name" codec:"name"`
What []string `cork:"-" codec:"-"`
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.
@ -317,18 +317,38 @@ type All struct{}
// Asc represents the ASC expression.
type Asc struct{}
func (this Asc) MarshalText() (data []byte, err error) {
return []byte("~ASC~"), err
}
// Desc represents the DESC expression.
type Desc struct{}
func (this Desc) MarshalText() (data []byte, err error) {
return []byte("~DESC~"), err
}
// Null represents a null expression.
type Null struct{}
func (this Null) MarshalText() (data []byte, err error) {
return []byte("~NULL~"), err
}
// Void represents an expression which is not set.
type Void struct{}
func (this Void) MarshalText() (data []byte, err error) {
return []byte("~VOID~"), err
}
// Empty represents an expression which is null or "".
type Empty struct{}
func (this Empty) MarshalText() (data []byte, err error) {
return []byte("~EMPTY~"), err
}
// Field represents a SELECT AS clause.
type Field struct {
Expr Expr
@ -386,6 +406,10 @@ func (this Ident) String() string {
return this.ID
}
func (this Ident) MarshalText() (data []byte, err error) {
return []byte("ID:" + this.ID), err
}
func NewIdent(ID string) *Ident {
return &Ident{ID}
}
@ -403,6 +427,10 @@ func (this Table) String() string {
return this.TB
}
func (this Table) MarshalText() (data []byte, err error) {
return []byte("TB:" + this.TB), err
}
func NewTable(TB string) *Table {
return &Table{TB}
}
@ -421,6 +449,10 @@ func (this Thing) String() string {
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 {
if str, ok := ID.(string); ok {
if cnv, err := strconv.ParseInt(str, 10, 64); err == nil {

View file

@ -418,6 +418,10 @@ func (tok Token) String() string {
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) isKeyword() bool { return tok > keywordsBeg && tok < keywordsEnd }