From a16f7b2aba96e2ded9ce543fe92263ee00df533f Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 14 Oct 2016 21:31:45 +0100 Subject: [PATCH] Add SCHEMALESS / SCHEMAFULL support to queries --- sql/ast.go | 1 + sql/sql_test.go | 22 ++++++++++++++++++++++ sql/table.go | 4 ++++ sql/token.go | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/sql/ast.go b/sql/ast.go index 2c3b9329..9fbaab2e 100644 --- a/sql/ast.go +++ b/sql/ast.go @@ -155,6 +155,7 @@ type DefineTableStatement struct { NS string `cork:"-" codec:"-"` DB string `cork:"-" codec:"-"` What []string `cork:"-" codec:"-"` + Full bool `cork:"full" codec:"full"` } // RemoveTableStatement represents an SQL REMOVE TABLE statement. diff --git a/sql/sql_test.go b/sql/sql_test.go index 5e65d892..af147dda 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -1323,6 +1323,28 @@ func Test_Parse_Queries_Define(t *testing.T) { sql: `DEFINE TABLE person something`, err: "Found `something` but expected `EOF, ;`", }, + { + sql: `DEFINE TABLE person SCHEMALESS`, + res: &Query{Statements: []Statement{&DefineTableStatement{ + What: []string{"person"}, + Full: false, + }}}, + }, + { + sql: `DEFINE TABLE person SCHEMAFULL`, + res: &Query{Statements: []Statement{&DefineTableStatement{ + What: []string{"person"}, + Full: true, + }}}, + }, + { + sql: `DEFINE TABLE person SCHEMALESS something`, + err: "Found `something` but expected `EOF, ;`", + }, + { + sql: `DEFINE TABLE person SCHEMAFULL something`, + err: "Found `something` but expected `EOF, ;`", + }, // ---------------------------------------------------------------------- { sql: `DEFINE RULES`, diff --git a/sql/table.go b/sql/table.go index 60900d6c..b1b3b616 100644 --- a/sql/table.go +++ b/sql/table.go @@ -26,6 +26,10 @@ func (p *parser) parseDefineTableStatement() (stmt *DefineTableStatement, err er return nil, err } + if tok, _, exi := p.mightBe(SCHEMAFULL, SCHEMALESS); exi && tok == SCHEMAFULL { + stmt.Full = true + } + if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil { return nil, err } diff --git a/sql/token.go b/sql/token.go index 6d63bb87..ca00610f 100644 --- a/sql/token.go +++ b/sql/token.go @@ -166,6 +166,8 @@ const ( RETURN ROLLBACK RULES + SCHEMAFULL + SCHEMALESS SELECT SET SOMECONTAINEDIN @@ -324,6 +326,8 @@ var tokens = [...]string{ RETURN: "RETURN", ROLLBACK: "ROLLBACK", RULES: "RULES", + SCHEMAFULL: "SCHEMAFULL", + SCHEMALESS: "SCHEMALESS", SELECT: "SELECT", SET: "SET", SOMECONTAINEDIN: "SOMECONTAINEDIN",