Add blueprint for defined RULES logic

This commit is contained in:
Tobie Morgan Hitchcock 2016-07-21 22:50:16 +01:00
parent ba9f348e1c
commit 5c094a011d
5 changed files with 101 additions and 2 deletions

View file

@ -149,6 +149,32 @@ type RecordStatement struct {
Echo Token // What to return 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 // Table
// -------------------------------------------------- // --------------------------------------------------

View file

@ -17,9 +17,11 @@ package sql
func (p *Parser) parseDefineStatement(explain bool) (Statement, error) { func (p *Parser) parseDefineStatement(explain bool) (Statement, error) {
// Inspect the next token. // Inspect the next token.
tok, _, err := p.shouldBe(TABLE, FIELD, INDEX) tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
switch tok { switch tok {
case RULES:
return p.parseDefineRulesStatement(explain)
case TABLE: case TABLE:
return p.parseDefineTableStatement(explain) return p.parseDefineTableStatement(explain)
case FIELD: case FIELD:

View file

@ -17,9 +17,11 @@ package sql
func (p *Parser) parseRemoveStatement(explain bool) (Statement, error) { func (p *Parser) parseRemoveStatement(explain bool) (Statement, error) {
// Inspect the next token. // Inspect the next token.
tok, _, err := p.shouldBe(TABLE, FIELD, INDEX) tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
switch tok { switch tok {
case RULES:
return p.parseRemoveRulesStatement(explain)
case TABLE: case TABLE:
return p.parseRemoveTableStatement(explain) return p.parseRemoveTableStatement(explain)
case FIELD: case FIELD:

59
sql/rules.go Normal file
View 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
}

View file

@ -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) { 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 return true
} }