surrealpatch/sql/field.go

103 lines
2.1 KiB
Go
Raw Normal View History

2016-05-23 12:32:02 +00:00
// 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
2016-09-20 23:34:21 +00:00
func (p *parser) parseDefineFieldStatement() (stmt *DefineFieldStatement, err error) {
2016-05-23 12:32:02 +00:00
stmt = &DefineFieldStatement{}
2016-05-23 12:32:02 +00:00
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil {
return nil, err
}
2016-05-23 12:32:02 +00:00
2017-11-16 20:53:13 +00:00
if stmt.Name, err = p.parseIdiom(); err != nil {
2016-05-23 12:32:02 +00:00
return nil, err
}
if _, _, err = p.shouldBe(ON); err != nil {
return nil, err
}
2017-03-02 10:47:10 +00:00
if stmt.What, err = p.parseTables(); err != nil {
2016-05-23 12:32:02 +00:00
return nil, err
}
for {
tok, _, exi := p.mightBe(TYPE, VALUE, ASSERT, PRIORITY, PERMISSIONS)
2016-05-23 12:32:02 +00:00
if !exi {
break
}
if p.is(tok, TYPE) {
2017-11-16 20:53:13 +00:00
if stmt.Type, stmt.Kind, err = p.parseType(); err != nil {
2016-05-23 12:32:02 +00:00
return nil, err
}
}
2017-11-16 20:53:13 +00:00
if p.is(tok, VALUE) {
if stmt.Value, err = p.parseExpr(); err != nil {
2016-07-04 10:37:37 +00:00
return nil, err
}
}
2017-11-16 20:53:13 +00:00
if p.is(tok, ASSERT) {
if stmt.Assert, err = p.parseExpr(); err != nil {
2016-05-23 12:32:02 +00:00
return nil, err
}
}
if p.is(tok, PRIORITY) {
if stmt.Priority, err = p.parsePriority(); err != nil {
return nil, err
}
}
if p.is(tok, PERMISSIONS) {
2017-11-16 20:53:13 +00:00
if stmt.Perms, err = p.parsePerms(); err != nil {
return nil, err
}
}
2016-05-23 12:32:02 +00:00
}
return
}
2016-09-20 23:34:21 +00:00
func (p *parser) parseRemoveFieldStatement() (stmt *RemoveFieldStatement, err error) {
2016-05-23 12:32:02 +00:00
stmt = &RemoveFieldStatement{}
2016-05-23 12:32:02 +00:00
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil {
return nil, err
}
2016-05-23 12:32:02 +00:00
2017-03-02 10:47:10 +00:00
if stmt.Name, err = p.parseIdent(); err != nil {
2016-05-23 12:32:02 +00:00
return nil, err
}
if _, _, err = p.shouldBe(ON); err != nil {
return nil, err
}
2017-03-02 10:47:10 +00:00
if stmt.What, err = p.parseTables(); err != nil {
2016-05-23 12:32:02 +00:00
return nil, err
}
return
}