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:"-"`
DB string `cork:"-" codec:"-"`
What []string `cork:"-" codec:"-"`
Full bool `cork:"full" codec:"full"`
}
// 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`,
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`,

View file

@ -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
}

View file

@ -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",