surrealpatch/db/remove.go

143 lines
3.5 KiB
Go
Raw Normal View History

// 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 db
import (
"context"
"github.com/abcum/surreal/sql"
2016-07-04 10:37:29 +00:00
"github.com/abcum/surreal/util/keys"
)
func (e *executor) executeRemoveNamespaceStatement(ctx context.Context, ast *sql.RemoveNamespaceStatement) (out []interface{}, err error) {
// Remove the namespace
2017-03-02 10:47:10 +00:00
nkey := &keys.NS{KV: ast.KV, NS: ast.Name.ID}
_, err = e.txn.DelP(0, nkey.Encode(), 0)
return
}
func (e *executor) executeRemoveDatabaseStatement(ctx context.Context, ast *sql.RemoveDatabaseStatement) (out []interface{}, err error) {
// Remove the database
2017-03-02 10:47:10 +00:00
dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID}
_, err = e.txn.DelP(0, dkey.Encode(), 0)
return
}
func (e *executor) executeRemoveLoginStatement(ctx context.Context, ast *sql.RemoveLoginStatement) (out []interface{}, err error) {
if ast.Kind == sql.NAMESPACE {
// Remove the login
2017-03-02 10:47:10 +00:00
ukey := &keys.NU{KV: ast.KV, NS: ast.NS, US: ast.User.ID}
_, err = e.txn.DelP(0, ukey.Encode(), 0)
}
if ast.Kind == sql.DATABASE {
// Remove the login
2017-03-02 10:47:10 +00:00
ukey := &keys.DU{KV: ast.KV, NS: ast.NS, DB: ast.DB, US: ast.User.ID}
_, err = e.txn.DelP(0, ukey.Encode(), 0)
2016-10-18 13:27:17 +00:00
}
return
}
func (e *executor) executeRemoveTokenStatement(ctx context.Context, ast *sql.RemoveTokenStatement) (out []interface{}, err error) {
2016-07-04 10:37:29 +00:00
if ast.Kind == sql.NAMESPACE {
2016-07-04 10:37:29 +00:00
// Remove the token
2017-03-02 10:47:10 +00:00
tkey := &keys.NT{KV: ast.KV, NS: ast.NS, TK: ast.Name.ID}
_, err = e.txn.DelP(0, tkey.Encode(), 0)
}
if ast.Kind == sql.DATABASE {
// Remove the token
2017-03-02 10:47:10 +00:00
tkey := &keys.DT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TK: ast.Name.ID}
_, err = e.txn.DelP(0, tkey.Encode(), 0)
2016-07-04 10:37:29 +00:00
}
return
}
func (e *executor) executeRemoveScopeStatement(ctx context.Context, ast *sql.RemoveScopeStatement) (out []interface{}, err error) {
// Remove the scope
2017-03-02 10:47:10 +00:00
skey := &keys.SC{KV: ast.KV, NS: ast.NS, DB: ast.DB, SC: ast.Name.ID}
_, err = e.txn.DelP(0, skey.Encode(), 0)
return
}
func (e *executor) executeRemoveTableStatement(ctx context.Context, ast *sql.RemoveTableStatement) (out []interface{}, err error) {
for _, TB := range ast.What {
// Remove the table
2017-03-02 10:47:10 +00:00
tkey := &keys.TB{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB}
_, err = e.txn.DelP(0, tkey.Encode(), 0)
}
2016-07-04 10:37:29 +00:00
return
}
func (e *executor) executeRemoveFieldStatement(ctx context.Context, ast *sql.RemoveFieldStatement) (out []interface{}, err error) {
2016-07-04 10:37:29 +00:00
for _, TB := range ast.What {
// Remove the field
2017-03-02 10:47:10 +00:00
fkey := &keys.FD{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, FD: ast.Name.ID}
_, err = e.txn.DelP(0, fkey.Encode(), 0)
2016-07-04 10:37:29 +00:00
}
return
}
func (e *executor) executeRemoveIndexStatement(ctx context.Context, ast *sql.RemoveIndexStatement) (out []interface{}, err error) {
2016-07-04 10:37:29 +00:00
for _, TB := range ast.What {
// Remove the index
2017-03-02 10:47:10 +00:00
ikey := &keys.IX{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, IX: ast.Name.ID}
_, err = e.txn.DelP(0, ikey.Encode(), 0)
2016-07-04 10:37:29 +00:00
// Remove the index
2017-03-02 10:47:10 +00:00
dkey := &keys.Index{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, IX: ast.Name.ID, FD: keys.Ignore}
_, err = e.txn.DelP(0, dkey.Encode(), 0)
2016-07-04 10:37:29 +00:00
}
return
}