Add SQL command for DEFINE/REMOVE NAMESPACE

This commit is contained in:
Tobie Morgan Hitchcock 2016-11-04 11:29:08 +00:00
parent b720213bd4
commit 15103e202b
5 changed files with 131 additions and 2 deletions

View file

@ -166,6 +166,24 @@ type RelateStatement struct {
Echo Token `cork:"echo" codec:"echo"` Echo Token `cork:"echo" codec:"echo"`
} }
// --------------------------------------------------
// Namespace
// --------------------------------------------------
type DefineNamespaceStatement struct {
KV string `cork:"-" codec:"-"`
NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"`
Name string `cork:"name" codec:"name"`
}
type RemoveNamespaceStatement struct {
KV string `cork:"-" codec:"-"`
NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"`
Name string `cork:"name" codec:"name"`
}
// -------------------------------------------------- // --------------------------------------------------
// Scope // Scope
// -------------------------------------------------- // --------------------------------------------------

View file

@ -962,6 +962,58 @@ func (this *RelateStatement) UnmarshalCORK(src []byte) (err error) {
return return
} }
// --------------------------------------------------
// DefineNamespaceStatement
// --------------------------------------------------
func init() {
cork.Register(&DefineNamespaceStatement{})
}
func (this *DefineNamespaceStatement) ExtendCORK() byte {
return 0x77
}
func (this *DefineNamespaceStatement) MarshalCORK() (dst []byte, err error) {
b := bytes.NewBuffer(dst)
e := cork.NewEncoder(b)
e.Encode(this.Name)
return b.Bytes(), nil
}
func (this *DefineNamespaceStatement) UnmarshalCORK(src []byte) (err error) {
b := bytes.NewBuffer(src)
d := cork.NewDecoder(b)
d.Decode(&this.Name)
return
}
// --------------------------------------------------
// RemoveNamespaceStatement
// --------------------------------------------------
func init() {
cork.Register(&RemoveNamespaceStatement{})
}
func (this *RemoveNamespaceStatement) ExtendCORK() byte {
return 0x78
}
func (this *RemoveNamespaceStatement) MarshalCORK() (dst []byte, err error) {
b := bytes.NewBuffer(dst)
e := cork.NewEncoder(b)
e.Encode(this.Name)
return b.Bytes(), nil
}
func (this *RemoveNamespaceStatement) UnmarshalCORK(src []byte) (err error) {
b := bytes.NewBuffer(src)
d := cork.NewDecoder(b)
d.Decode(&this.Name)
return
}
// -------------------------------------------------- // --------------------------------------------------
// DefineScopeStatement // DefineScopeStatement
// -------------------------------------------------- // --------------------------------------------------

View file

@ -17,9 +17,11 @@ package sql
func (p *parser) parseDefineStatement() (Statement, error) { func (p *parser) parseDefineStatement() (Statement, error) {
// Inspect the next token. // Inspect the next token.
tok, _, err := p.shouldBe(SCOPE, TABLE, RULES, FIELD, INDEX, VIEW) tok, _, err := p.shouldBe(NAMESPACE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
switch tok { switch tok {
case NAMESPACE:
return p.parseDefineNamespaceStatement()
case SCOPE: case SCOPE:
return p.parseDefineScopeStatement() return p.parseDefineScopeStatement()
case TABLE: case TABLE:

55
sql/namespace.go Normal file
View file

@ -0,0 +1,55 @@
// 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) parseDefineNamespaceStatement() (stmt *DefineNamespaceStatement, err error) {
stmt = &DefineNamespaceStatement{}
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthKV); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(NAMESPACE); err != nil {
return nil, err
}
if stmt.Name, err = p.parseName(); err != nil {
return nil, err
}
return
}
func (p *parser) parseRemoveNamespaceStatement() (stmt *RemoveNamespaceStatement, err error) {
stmt = &RemoveNamespaceStatement{}
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthKV); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(NAMESPACE); err != nil {
return nil, err
}
if stmt.Name, err = p.parseName(); err != nil {
return nil, err
}
return
}

View file

@ -17,9 +17,11 @@ package sql
func (p *parser) parseRemoveStatement() (Statement, error) { func (p *parser) parseRemoveStatement() (Statement, error) {
// Inspect the next token. // Inspect the next token.
tok, _, err := p.shouldBe(SCOPE, TABLE, RULES, FIELD, INDEX, VIEW) tok, _, err := p.shouldBe(NAMESPACE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
switch tok { switch tok {
case NAMESPACE:
return p.parseRemoveNamespaceStatement()
case SCOPE: case SCOPE:
return p.parseRemoveScopeStatement() return p.parseRemoveScopeStatement()
case TABLE: case TABLE: