Add blueprint for defined RULES logic
This commit is contained in:
parent
ba9f348e1c
commit
5c094a011d
5 changed files with 101 additions and 2 deletions
26
sql/ast.go
26
sql/ast.go
|
@ -149,6 +149,32 @@ type RecordStatement struct {
|
|||
Echo Token // What to return
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Rules
|
||||
// --------------------------------------------------
|
||||
|
||||
// DefineRulesStatement represents an SQL DEFINE RULES statement.
|
||||
//
|
||||
// DEFINE RULES person
|
||||
type DefineRulesStatement struct {
|
||||
EX bool // Explain
|
||||
KV string // Bucket
|
||||
NS string // Namespace
|
||||
DB string // Database
|
||||
What []Table // Table names
|
||||
}
|
||||
|
||||
// RemoveRulesStatement represents an SQL REMOVE RULES statement.
|
||||
//
|
||||
// REMOVE RULES person
|
||||
type RemoveRulesStatement struct {
|
||||
EX bool // Explain
|
||||
KV string // Bucket
|
||||
NS string // Namespace
|
||||
DB string // Database
|
||||
What []Table // Table names
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Table
|
||||
// --------------------------------------------------
|
||||
|
|
|
@ -17,9 +17,11 @@ package sql
|
|||
func (p *Parser) parseDefineStatement(explain bool) (Statement, error) {
|
||||
|
||||
// Inspect the next token.
|
||||
tok, _, err := p.shouldBe(TABLE, FIELD, INDEX)
|
||||
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
||||
|
||||
switch tok {
|
||||
case RULES:
|
||||
return p.parseDefineRulesStatement(explain)
|
||||
case TABLE:
|
||||
return p.parseDefineTableStatement(explain)
|
||||
case FIELD:
|
||||
|
|
|
@ -17,9 +17,11 @@ package sql
|
|||
func (p *Parser) parseRemoveStatement(explain bool) (Statement, error) {
|
||||
|
||||
// Inspect the next token.
|
||||
tok, _, err := p.shouldBe(TABLE, FIELD, INDEX)
|
||||
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
||||
|
||||
switch tok {
|
||||
case RULES:
|
||||
return p.parseRemoveRulesStatement(explain)
|
||||
case TABLE:
|
||||
return p.parseRemoveTableStatement(explain)
|
||||
case FIELD:
|
||||
|
|
59
sql/rules.go
Normal file
59
sql/rules.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright © 2016 Abcum Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesStatement, err error) {
|
||||
|
||||
stmt = &DefineRulesStatement{}
|
||||
|
||||
stmt.EX = explain
|
||||
|
||||
stmt.KV = p.c.Get("KV").(string)
|
||||
stmt.NS = p.c.Get("NS").(string)
|
||||
stmt.DB = p.c.Get("DB").(string)
|
||||
|
||||
if stmt.What, err = p.parseTables(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (p *Parser) parseRemoveRulesStatement(explain bool) (stmt *RemoveRulesStatement, err error) {
|
||||
|
||||
stmt = &RemoveRulesStatement{}
|
||||
|
||||
stmt.EX = explain
|
||||
|
||||
stmt.KV = p.c.Get("KV").(string)
|
||||
stmt.NS = p.c.Get("NS").(string)
|
||||
stmt.DB = p.c.Get("DB").(string)
|
||||
|
||||
if stmt.What, err = p.parseTables(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
|
@ -103,6 +103,16 @@ func New(kv kvs.KV, key *keys.Thing) (this *Doc) {
|
|||
}
|
||||
|
||||
func (this *Doc) Allow(txn kvs.TX, cond string) (val bool) {
|
||||
|
||||
switch cond {
|
||||
case "select":
|
||||
case "create":
|
||||
case "update":
|
||||
case "modify":
|
||||
case "delete":
|
||||
case "relate":
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue