Add SQL command for DEFINE/REMOVE DATABASE
This commit is contained in:
parent
15103e202b
commit
b9327723f8
5 changed files with 143 additions and 14 deletions
18
sql/ast.go
18
sql/ast.go
|
@ -184,6 +184,24 @@ type RemoveNamespaceStatement struct {
|
|||
Name string `cork:"name" codec:"name"`
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Database
|
||||
// --------------------------------------------------
|
||||
|
||||
type DefineDatabaseStatement struct {
|
||||
KV string `cork:"-" codec:"-"`
|
||||
NS string `cork:"-" codec:"-"`
|
||||
DB string `cork:"-" codec:"-"`
|
||||
Name string `cork:"name" codec:"name"`
|
||||
}
|
||||
|
||||
type RemoveDatabaseStatement struct {
|
||||
KV string `cork:"-" codec:"-"`
|
||||
NS string `cork:"-" codec:"-"`
|
||||
DB string `cork:"-" codec:"-"`
|
||||
Name string `cork:"name" codec:"name"`
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Scope
|
||||
// --------------------------------------------------
|
||||
|
|
76
sql/cork.go
76
sql/cork.go
|
@ -1014,6 +1014,58 @@ func (this *RemoveNamespaceStatement) UnmarshalCORK(src []byte) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// DefineDatabaseStatement
|
||||
// --------------------------------------------------
|
||||
|
||||
func init() {
|
||||
cork.Register(&DefineDatabaseStatement{})
|
||||
}
|
||||
|
||||
func (this *DefineDatabaseStatement) ExtendCORK() byte {
|
||||
return 0x79
|
||||
}
|
||||
|
||||
func (this *DefineDatabaseStatement) MarshalCORK() (dst []byte, err error) {
|
||||
b := bytes.NewBuffer(dst)
|
||||
e := cork.NewEncoder(b)
|
||||
e.Encode(this.Name)
|
||||
return b.Bytes(), nil
|
||||
}
|
||||
|
||||
func (this *DefineDatabaseStatement) UnmarshalCORK(src []byte) (err error) {
|
||||
b := bytes.NewBuffer(src)
|
||||
d := cork.NewDecoder(b)
|
||||
d.Decode(&this.Name)
|
||||
return
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// RemoveDatabaseStatement
|
||||
// --------------------------------------------------
|
||||
|
||||
func init() {
|
||||
cork.Register(&RemoveDatabaseStatement{})
|
||||
}
|
||||
|
||||
func (this *RemoveDatabaseStatement) ExtendCORK() byte {
|
||||
return 0x80
|
||||
}
|
||||
|
||||
func (this *RemoveDatabaseStatement) MarshalCORK() (dst []byte, err error) {
|
||||
b := bytes.NewBuffer(dst)
|
||||
e := cork.NewEncoder(b)
|
||||
e.Encode(this.Name)
|
||||
return b.Bytes(), nil
|
||||
}
|
||||
|
||||
func (this *RemoveDatabaseStatement) UnmarshalCORK(src []byte) (err error) {
|
||||
b := bytes.NewBuffer(src)
|
||||
d := cork.NewDecoder(b)
|
||||
d.Decode(&this.Name)
|
||||
return
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// DefineScopeStatement
|
||||
// --------------------------------------------------
|
||||
|
@ -1023,7 +1075,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *DefineScopeStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x81
|
||||
}
|
||||
|
||||
func (this *DefineScopeStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1053,7 +1105,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *RemoveScopeStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x82
|
||||
}
|
||||
|
||||
func (this *RemoveScopeStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1079,7 +1131,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *DefineTableStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x83
|
||||
}
|
||||
|
||||
func (this *DefineTableStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1107,7 +1159,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *RemoveTableStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x84
|
||||
}
|
||||
|
||||
func (this *RemoveTableStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1133,7 +1185,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *DefineRulesStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x85
|
||||
}
|
||||
|
||||
func (this *DefineRulesStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1165,7 +1217,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *RemoveRulesStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x86
|
||||
}
|
||||
|
||||
func (this *RemoveRulesStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1193,7 +1245,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *DefineFieldStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x87
|
||||
}
|
||||
|
||||
func (this *DefineFieldStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1243,7 +1295,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *RemoveFieldStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x88
|
||||
}
|
||||
|
||||
func (this *RemoveFieldStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1271,7 +1323,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *DefineIndexStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x89
|
||||
}
|
||||
|
||||
func (this *DefineIndexStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1303,7 +1355,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *RemoveIndexStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x90
|
||||
}
|
||||
|
||||
func (this *RemoveIndexStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1331,7 +1383,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *DefineViewStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x91
|
||||
}
|
||||
|
||||
func (this *DefineViewStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
@ -1365,7 +1417,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (this *RemoveViewStatement) ExtendCORK() byte {
|
||||
return 0x76
|
||||
return 0x92
|
||||
}
|
||||
|
||||
func (this *RemoveViewStatement) MarshalCORK() (dst []byte, err error) {
|
||||
|
|
55
sql/database.go
Normal file
55
sql/database.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) parseDefineDatabaseStatement() (stmt *DefineDatabaseStatement, err error) {
|
||||
|
||||
stmt = &DefineDatabaseStatement{}
|
||||
|
||||
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, _, err = p.shouldBe(DATABASE); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if stmt.Name, err = p.parseName(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (p *parser) parseRemoveDatabaseStatement() (stmt *RemoveDatabaseStatement, err error) {
|
||||
|
||||
stmt = &RemoveDatabaseStatement{}
|
||||
|
||||
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, _, err = p.shouldBe(DATABASE); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if stmt.Name, err = p.parseName(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
|
@ -17,11 +17,13 @@ package sql
|
|||
func (p *parser) parseDefineStatement() (Statement, error) {
|
||||
|
||||
// Inspect the next token.
|
||||
tok, _, err := p.shouldBe(NAMESPACE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
||||
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
||||
|
||||
switch tok {
|
||||
case NAMESPACE:
|
||||
return p.parseDefineNamespaceStatement()
|
||||
case DATABASE:
|
||||
return p.parseDefineDatabaseStatement()
|
||||
case SCOPE:
|
||||
return p.parseDefineScopeStatement()
|
||||
case TABLE:
|
||||
|
|
|
@ -17,11 +17,13 @@ package sql
|
|||
func (p *parser) parseRemoveStatement() (Statement, error) {
|
||||
|
||||
// Inspect the next token.
|
||||
tok, _, err := p.shouldBe(NAMESPACE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
||||
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
||||
|
||||
switch tok {
|
||||
case NAMESPACE:
|
||||
return p.parseRemoveNamespaceStatement()
|
||||
case DATABASE:
|
||||
return p.parseRemoveDatabaseStatement()
|
||||
case SCOPE:
|
||||
return p.parseRemoveScopeStatement()
|
||||
case TABLE:
|
||||
|
|
Loading…
Reference in a new issue