Add SCHEMALESS / SCHEMAFULL support to queries

This commit is contained in:
Tobie Morgan Hitchcock 2016-10-14 21:31:45 +01:00
parent 91b3b83554
commit a16f7b2aba
4 changed files with 31 additions and 0 deletions

View file

@ -155,6 +155,7 @@ type DefineTableStatement struct {
NS string `cork:"-" codec:"-"` NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"` DB string `cork:"-" codec:"-"`
What []string `cork:"-" codec:"-"` What []string `cork:"-" codec:"-"`
Full bool `cork:"full" codec:"full"`
} }
// RemoveTableStatement represents an SQL REMOVE TABLE statement. // RemoveTableStatement represents an SQL REMOVE TABLE statement.

View file

@ -1323,6 +1323,28 @@ func Test_Parse_Queries_Define(t *testing.T) {
sql: `DEFINE TABLE person something`, sql: `DEFINE TABLE person something`,
err: "Found `something` but expected `EOF, ;`", 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`, sql: `DEFINE RULES`,

View file

@ -26,6 +26,10 @@ func (p *parser) parseDefineTableStatement() (stmt *DefineTableStatement, err er
return nil, err return nil, err
} }
if tok, _, exi := p.mightBe(SCHEMAFULL, SCHEMALESS); exi && tok == SCHEMAFULL {
stmt.Full = true
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil { if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
return nil, err return nil, err
} }

View file

@ -166,6 +166,8 @@ const (
RETURN RETURN
ROLLBACK ROLLBACK
RULES RULES
SCHEMAFULL
SCHEMALESS
SELECT SELECT
SET SET
SOMECONTAINEDIN SOMECONTAINEDIN
@ -324,6 +326,8 @@ var tokens = [...]string{
RETURN: "RETURN", RETURN: "RETURN",
ROLLBACK: "ROLLBACK", ROLLBACK: "ROLLBACK",
RULES: "RULES", RULES: "RULES",
SCHEMAFULL: "SCHEMAFULL",
SCHEMALESS: "SCHEMALESS",
SELECT: "SELECT", SELECT: "SELECT",
SET: "SET", SET: "SET",
SOMECONTAINEDIN: "SOMECONTAINEDIN", SOMECONTAINEDIN: "SOMECONTAINEDIN",