Skip to content

Commit

Permalink
Export select items too
Browse files Browse the repository at this point in the history
  • Loading branch information
eatonphil committed Jan 23, 2021
1 parent ca1f00e commit 1c19792
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func (e Expression) GenerateCode() string {
return ""
}

type selectItem struct {
type SelectItem struct {
Exp *Expression
Asterisk bool // for *
As *Token
}

type SelectStatement struct {
Item *[]*selectItem
Item *[]*SelectItem
From *Token
Where *Expression
}
Expand Down
2 changes: 1 addition & 1 deletion ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ WHERE
("id" = 2);`,
Statement{
SelectStatement: &SelectStatement{
Item: &[]*selectItem{
Item: &[]*SelectItem{
{Exp: &Expression{Literal: &Token{Value: "id", Kind: IdentifierKind}, Kind: LiteralKind}},
{Exp: &Expression{Literal: &Token{Value: "name", Kind: IdentifierKind}, Kind: LiteralKind}},
},
Expand Down
6 changes: 3 additions & 3 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,12 @@ func (mb *MemoryBackend) Select(slct *SelectStatement) (*Results, error) {
}

// Expand SELECT * at the AST level into a SELECT on all columns
finalItems := []*selectItem{}
finalItems := []*SelectItem{}
for _, item := range *slct.Item {
if item.Asterisk {
newItems := []*selectItem{}
newItems := []*SelectItem{}
for j := 0; j < len(t.columns); j++ {
newSelectItem := &selectItem{
newSelectItem := &SelectItem{
Exp: &Expression{
Literal: &Token{
Value: t.columns[j],
Expand Down
8 changes: 4 additions & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ outer:
return exp, cursor, true
}

func (p Parser) parseSelectItem(tokens []*Token, initialCursor uint, delimiters []Token) (*[]*selectItem, uint, bool) {
func (p Parser) parseSelectItem(tokens []*Token, initialCursor uint, delimiters []Token) (*[]*SelectItem, uint, bool) {
cursor := initialCursor

var s []*selectItem
var s []*SelectItem
outer:
for {
if cursor >= uint(len(tokens)) {
Expand All @@ -205,10 +205,10 @@ outer:
}
}

var si selectItem
var si SelectItem
_, cursor, ok = p.parseToken(tokens, cursor, TokenFromSymbol(AsteriskSymbol))
if ok {
si = selectItem{Asterisk: true}
si = SelectItem{Asterisk: true}
} else {
asToken := TokenFromKeyword(AsKeyword)
delimiters := append(delimiters, TokenFromSymbol(CommaSymbol), asToken)
Expand Down
4 changes: 2 additions & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestParse(t *testing.T) {
{
Kind: SelectKind,
SelectStatement: &SelectStatement{
Item: &[]*selectItem{
Item: &[]*SelectItem{
{
Asterisk: true,
},
Expand All @@ -199,7 +199,7 @@ func TestParse(t *testing.T) {
{
Kind: SelectKind,
SelectStatement: &SelectStatement{
Item: &[]*selectItem{
Item: &[]*SelectItem{
{
Exp: &Expression{
Kind: LiteralKind,
Expand Down

0 comments on commit 1c19792

Please sign in to comment.