Add SQL DEFINE TOKEN statement

This commit is contained in:
Tobie Morgan Hitchcock 2016-11-16 22:47:23 +00:00
parent a66c604c2f
commit cf79487b81
5 changed files with 169 additions and 2 deletions

View file

@ -226,6 +226,30 @@ type RemoveLoginStatement struct {
User string `cork:"user" codec:"user"`
}
// --------------------------------------------------
// Token
// --------------------------------------------------
// DefineTokenStatement represents an SQL DEFINE TOKEN statement.
type DefineTokenStatement struct {
KV string `cork:"-" codec:"-"`
NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"`
Kind Token `cork:"kind" codec:"kind"`
Name string `cork:"name" codec:"name"`
Type string `cork:"type" codec:"type"`
Text string `cork:"text" codec:"text"`
}
// RemoveTokenStatement represents an SQL REMOVE TOKEN statement.
type RemoveTokenStatement struct {
KV string `cork:"-" codec:"-"`
NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"`
Kind Token `cork:"kind" codec:"kind"`
Name string `cork:"name" codec:"name"`
}
// --------------------------------------------------
// Scope
// --------------------------------------------------

View file

@ -1122,6 +1122,66 @@ func (this *RemoveLoginStatement) UnmarshalCORK(src []byte) (err error) {
return
}
// --------------------------------------------------
// DefineTokenStatement
// --------------------------------------------------
func init() {
cork.Register(&DefineTokenStatement{})
}
func (this *DefineTokenStatement) ExtendCORK() byte {
return 0x81
}
func (this *DefineTokenStatement) MarshalCORK() (dst []byte, err error) {
b := bytes.NewBuffer(dst)
e := cork.NewEncoder(b)
e.Encode(this.Kind)
e.Encode(this.Name)
e.Encode(this.Type)
e.Encode(this.Text)
return b.Bytes(), nil
}
func (this *DefineTokenStatement) UnmarshalCORK(src []byte) (err error) {
b := bytes.NewBuffer(src)
d := cork.NewDecoder(b)
d.Decode(&this.Kind)
d.Decode(&this.Name)
d.Decode(&this.Type)
d.Decode(&this.Text)
return
}
// --------------------------------------------------
// RemoveTokenStatement
// --------------------------------------------------
func init() {
cork.Register(&RemoveTokenStatement{})
}
func (this *RemoveTokenStatement) ExtendCORK() byte {
return 0x82
}
func (this *RemoveTokenStatement) MarshalCORK() (dst []byte, err error) {
b := bytes.NewBuffer(dst)
e := cork.NewEncoder(b)
e.Encode(this.Kind)
e.Encode(this.Name)
return b.Bytes(), nil
}
func (this *RemoveTokenStatement) UnmarshalCORK(src []byte) (err error) {
b := bytes.NewBuffer(src)
d := cork.NewDecoder(b)
d.Decode(&this.Kind)
d.Decode(&this.Name)
return
}
// --------------------------------------------------
// DefineScopeStatement
// --------------------------------------------------

View file

@ -17,7 +17,7 @@ package sql
func (p *parser) parseDefineStatement() (Statement, error) {
// Inspect the next token.
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
switch tok {
case NAMESPACE:
@ -26,6 +26,8 @@ func (p *parser) parseDefineStatement() (Statement, error) {
return p.parseDefineDatabaseStatement()
case LOGIN:
return p.parseDefineLoginStatement()
case TOKEN:
return p.parseDefineTokenStatement()
case SCOPE:
return p.parseDefineScopeStatement()
case TABLE:

View file

@ -17,7 +17,7 @@ package sql
func (p *parser) parseRemoveStatement() (Statement, error) {
// Inspect the next token.
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
switch tok {
case NAMESPACE:
@ -26,6 +26,8 @@ func (p *parser) parseRemoveStatement() (Statement, error) {
return p.parseRemoveDatabaseStatement()
case LOGIN:
return p.parseRemoveLoginStatement()
case TOKEN:
return p.parseRemoveTokenStatement()
case SCOPE:
return p.parseRemoveScopeStatement()
case TABLE:

79
sql/token.go Normal file
View file

@ -0,0 +1,79 @@
// 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) parseDefineTokenStatement() (stmt *DefineTokenStatement, err error) {
stmt = &DefineTokenStatement{}
if _, _, err = p.shouldBe(ON); err != nil {
return nil, err
}
if stmt.Kind, _, err = p.shouldBe(NAMESPACE, DATABASE); err != nil {
return nil, err
}
if p.is(stmt.Kind, NAMESPACE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil {
return nil, err
}
}
if p.is(stmt.Kind, DATABASE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil {
return nil, err
}
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
return nil, err
}
return
}
func (p *parser) parseRemoveTokenStatement() (stmt *RemoveTokenStatement, err error) {
stmt = &RemoveTokenStatement{}
if _, _, err = p.shouldBe(ON); err != nil {
return nil, err
}
if stmt.Kind, _, err = p.shouldBe(NAMESPACE, DATABASE); err != nil {
return nil, err
}
if p.is(stmt.Kind, NAMESPACE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil {
return nil, err
}
}
if p.is(stmt.Kind, DATABASE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil {
return nil, err
}
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
return nil, err
}
return
}