From 5c094a011d2cd3521720270a53cc463aa292f6d3 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 21 Jul 2016 22:50:16 +0100 Subject: [PATCH] Add blueprint for defined RULES logic --- sql/ast.go | 26 +++++++++++++++++++++ sql/define.go | 4 +++- sql/remove.go | 4 +++- sql/rules.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++ util/item/item.go | 10 ++++++++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 sql/rules.go diff --git a/sql/ast.go b/sql/ast.go index 1277b787..c641abb5 100644 --- a/sql/ast.go +++ b/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 // -------------------------------------------------- diff --git a/sql/define.go b/sql/define.go index e06b4899..f7221a56 100644 --- a/sql/define.go +++ b/sql/define.go @@ -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: diff --git a/sql/remove.go b/sql/remove.go index ca65de96..5cb41edc 100644 --- a/sql/remove.go +++ b/sql/remove.go @@ -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: diff --git a/sql/rules.go b/sql/rules.go new file mode 100644 index 00000000..4fde0dcf --- /dev/null +++ b/sql/rules.go @@ -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 + +} diff --git a/util/item/item.go b/util/item/item.go index 93bd3060..7a855abd 100644 --- a/util/item/item.go +++ b/util/item/item.go @@ -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 }