From 7e9c595ff7f047f8eea2e836a801ae26696cd08c Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sun, 30 Oct 2016 16:59:16 +0000 Subject: [PATCH] Add blueprint for RELATE SQL query --- sql/exprs.go | 13 +++++++++++++ sql/relate.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/sql/exprs.go b/sql/exprs.go index 91dc86da..51e4b9a6 100644 --- a/sql/exprs.go +++ b/sql/exprs.go @@ -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) diff --git a/sql/relate.go b/sql/relate.go index f1e9c5da..b43ec746 100644 --- a/sql/relate.go +++ b/sql/relate.go @@ -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 }