Add blueprint for RELATE SQL query

This commit is contained in:
Tobie Morgan Hitchcock 2016-10-30 16:59:16 +00:00
parent feea12f93d
commit 7e9c595ff7
2 changed files with 47 additions and 0 deletions

View file

@ -106,6 +106,19 @@ func (p *parser) parseIdent() (*Ident, error) {
}
func (p *parser) parseTable() (*Table, error) {
_, lit, err := p.shouldBe(IDENT, NUMBER, DOUBLE)
if err != nil {
return nil, &ParseError{Found: lit, Expected: []string{"name"}}
}
val, err := p.declare(TABLE, lit)
return val.(*Table), err
}
func (p *parser) parseThing() (*Thing, error) {
_, lit, err := p.shouldBe(THING)

View file

@ -22,6 +22,40 @@ func (p *parser) parseRelateStatement() (stmt *RelateStatement, err error) {
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)
if stmt.Type, err = p.parseTable(); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(FROM); err != nil {
return nil, err
}
if stmt.From, err = p.parseWhat(); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(TO); err != nil {
return nil, err
}
if stmt.With, err = p.parseWhat(); err != nil {
return nil, err
}
_, _, stmt.Uniq = p.mightBe(UNIQUE)
if stmt.Data, err = p.parseData(); err != nil {
return nil, err
}
if stmt.Echo, err = p.parseEcho(); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
return nil, err
}
return
}