Remove code in rules and use SQL WHERE clause

This commit is contained in:
Tobie Morgan Hitchcock 2016-10-14 22:05:44 +01:00
parent a16f7b2aba
commit 115c97ce86
3 changed files with 7 additions and 27 deletions

View file

@ -178,7 +178,6 @@ type DefineRulesStatement struct {
What []string `cork:"-" codec:"-"`
When []string `cork:"-" codec:"-"`
Rule string `cork:"rule" codec:"rule"`
Code string `cork:"code" codec:"code"`
Cond []Expr `cork:"cond" codec:"cond"`
}

View file

@ -53,18 +53,12 @@ func (p *parser) parseDefineRulesStatement() (stmt *DefineRulesStatement, err er
return nil, &ParseError{Found: "", Expected: []string{"SELECT", "CREATE", "UPDATE", "DELETE", "RELATE"}}
}
if tok, _, err := p.shouldBe(ACCEPT, REJECT, CUSTOM); err != nil {
return nil, err
} else {
stmt.Rule = tok.String()
if p.is(tok, CUSTOM) {
if stmt.Code, err = p.parseScript(); err != nil {
if _, stmt.Rule, err = p.shouldBe(ACCEPT, REJECT); err != nil {
return nil, err
}
}
if stmt.Cond, err = p.parseCond(); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {

View file

@ -1364,7 +1364,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
},
{
sql: `DEFINE RULES ON person FOR select, create, update, delete`,
err: "Found `` but expected `ACCEPT, REJECT, CUSTOM`",
err: "Found `` but expected `ACCEPT, REJECT`",
},
{
sql: `DEFINE RULES ON person FOR select, create, update, delete ACCEPT`,
@ -1387,24 +1387,11 @@ func Test_Parse_Queries_Define(t *testing.T) {
}}},
},
{
sql: `DEFINE RULES ON person FOR select, create, update, delete REJECT something`,
sql: `DEFINE RULES ON person FOR select, create, update, delete ACCEPT something`,
err: "Found `something` but expected `EOF, ;`",
},
{
sql: `DEFINE RULES ON person FOR select, create, update, delete CUSTOM`,
err: "Found `` but expected `js/lua script`",
},
{
sql: `DEFINE RULES ON person FOR select, create, update, delete CUSTOM "return true"`,
res: &Query{Statements: []Statement{&DefineRulesStatement{
What: []string{"person"},
When: []string{"SELECT", "CREATE", "UPDATE", "DELETE"},
Rule: "CUSTOM",
Code: "return true",
}}},
},
{
sql: `DEFINE RULES ON person FOR select, create, update, delete CUSTOM "return true" something`,
sql: `DEFINE RULES ON person FOR select, create, update, delete REJECT something`,
err: "Found `something` but expected `EOF, ;`",
},
// ----------------------------------------------------------------------