Add SQL command for DEFINE/REMOVE NAMESPACE
This commit is contained in:
parent
b720213bd4
commit
15103e202b
5 changed files with 131 additions and 2 deletions
18
sql/ast.go
18
sql/ast.go
|
@ -166,6 +166,24 @@ type RelateStatement struct {
|
|||
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
|
||||
// --------------------------------------------------
|
||||
|
|
52
sql/cork.go
52
sql/cork.go
|
@ -962,6 +962,58 @@ func (this *RelateStatement) UnmarshalCORK(src []byte) (err error) {
|
|||
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
|
||||
// --------------------------------------------------
|
||||
|
|
|
@ -17,9 +17,11 @@ package sql
|
|||
func (p *parser) parseDefineStatement() (Statement, error) {
|
||||
|
||||
// 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 {
|
||||
case NAMESPACE:
|
||||
return p.parseDefineNamespaceStatement()
|
||||
case SCOPE:
|
||||
return p.parseDefineScopeStatement()
|
||||
case TABLE:
|
||||
|
|
55
sql/namespace.go
Normal file
55
sql/namespace.go
Normal 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
|
||||
|
||||
}
|
|
@ -17,9 +17,11 @@ package sql
|
|||
func (p *parser) parseRemoveStatement() (Statement, error) {
|
||||
|
||||
// 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 {
|
||||
case NAMESPACE:
|
||||
return p.parseRemoveNamespaceStatement()
|
||||
case SCOPE:
|
||||
return p.parseRemoveScopeStatement()
|
||||
case TABLE:
|
||||
|
|
Loading…
Reference in a new issue