Remove code in rules and use SQL WHERE clause
This commit is contained in:
parent
a16f7b2aba
commit
115c97ce86
3 changed files with 7 additions and 27 deletions
|
@ -178,7 +178,6 @@ type DefineRulesStatement struct {
|
||||||
What []string `cork:"-" codec:"-"`
|
What []string `cork:"-" codec:"-"`
|
||||||
When []string `cork:"-" codec:"-"`
|
When []string `cork:"-" codec:"-"`
|
||||||
Rule string `cork:"rule" codec:"rule"`
|
Rule string `cork:"rule" codec:"rule"`
|
||||||
Code string `cork:"code" codec:"code"`
|
|
||||||
Cond []Expr `cork:"cond" codec:"cond"`
|
Cond []Expr `cork:"cond" codec:"cond"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
sql/rules.go
14
sql/rules.go
|
@ -53,18 +53,12 @@ func (p *parser) parseDefineRulesStatement() (stmt *DefineRulesStatement, err er
|
||||||
return nil, &ParseError{Found: "", Expected: []string{"SELECT", "CREATE", "UPDATE", "DELETE", "RELATE"}}
|
return nil, &ParseError{Found: "", Expected: []string{"SELECT", "CREATE", "UPDATE", "DELETE", "RELATE"}}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tok, _, err := p.shouldBe(ACCEPT, REJECT, CUSTOM); err != nil {
|
if _, stmt.Rule, err = p.shouldBe(ACCEPT, REJECT); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
stmt.Rule = tok.String()
|
|
||||||
|
|
||||||
if p.is(tok, CUSTOM) {
|
|
||||||
if stmt.Code, err = p.parseScript(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if stmt.Cond, err = p.parseCond(); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
|
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
|
||||||
|
|
|
@ -1364,7 +1364,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `DEFINE RULES ON person FOR select, create, update, delete`,
|
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`,
|
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, ;`",
|
err: "Found `something` but expected `EOF, ;`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `DEFINE RULES ON person FOR select, create, update, delete CUSTOM`,
|
sql: `DEFINE RULES ON person FOR select, create, update, delete REJECT something`,
|
||||||
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`,
|
|
||||||
err: "Found `something` but expected `EOF, ;`",
|
err: "Found `something` but expected `EOF, ;`",
|
||||||
},
|
},
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue