2016-02-27 01:00:19 +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 db
|
|
|
|
|
|
|
|
import (
|
2017-03-03 21:39:37 +00:00
|
|
|
"context"
|
|
|
|
|
2016-02-27 01:00:19 +00:00
|
|
|
"github.com/abcum/surreal/sql"
|
2016-07-04 10:37:29 +00:00
|
|
|
"github.com/abcum/surreal/util/keys"
|
2016-02-27 01:00:19 +00:00
|
|
|
)
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveNamespace(ctx context.Context, ast *sql.RemoveNamespaceStatement) (out []interface{}, err error) {
|
|
|
|
|
|
|
|
e.dbo.DelNS(ast.Name.ID)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
nkey := &keys.NS{KV: ast.KV, NS: ast.Name.ID}
|
2018-02-09 15:08:27 +00:00
|
|
|
_, err = e.dbo.Clr(nkey.Encode())
|
|
|
|
|
|
|
|
akey := &keys.Namespace{KV: ast.KV, NS: ast.Name.ID}
|
|
|
|
_, err = e.dbo.ClrP(akey.Encode(), 0)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveDatabase(ctx context.Context, ast *sql.RemoveDatabaseStatement) (out []interface{}, err error) {
|
|
|
|
|
|
|
|
e.dbo.DelDB(ast.NS, ast.Name.ID)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID}
|
2018-02-09 15:08:27 +00:00
|
|
|
_, err = e.dbo.Clr(dkey.Encode())
|
|
|
|
|
|
|
|
akey := &keys.Database{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID}
|
|
|
|
_, err = e.dbo.ClrP(akey.Encode(), 0)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveLogin(ctx context.Context, ast *sql.RemoveLoginStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
switch ast.Kind {
|
|
|
|
case sql.NAMESPACE:
|
2017-03-02 10:47:10 +00:00
|
|
|
ukey := &keys.NU{KV: ast.KV, NS: ast.NS, US: ast.User.ID}
|
2017-11-16 20:53:39 +00:00
|
|
|
_, err = e.dbo.ClrP(ukey.Encode(), 0)
|
|
|
|
case sql.DATABASE:
|
2017-03-02 10:47:10 +00:00
|
|
|
ukey := &keys.DU{KV: ast.KV, NS: ast.NS, DB: ast.DB, US: ast.User.ID}
|
2017-11-16 20:53:39 +00:00
|
|
|
_, err = e.dbo.ClrP(ukey.Encode(), 0)
|
2016-10-18 13:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveToken(ctx context.Context, ast *sql.RemoveTokenStatement) (out []interface{}, err error) {
|
2016-07-04 10:37:29 +00:00
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
switch ast.Kind {
|
|
|
|
case sql.NAMESPACE:
|
2017-03-02 10:47:10 +00:00
|
|
|
tkey := &keys.NT{KV: ast.KV, NS: ast.NS, TK: ast.Name.ID}
|
2017-11-16 20:53:39 +00:00
|
|
|
_, err = e.dbo.ClrP(tkey.Encode(), 0)
|
|
|
|
case sql.DATABASE:
|
2017-03-02 10:47:10 +00:00
|
|
|
tkey := &keys.DT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TK: ast.Name.ID}
|
2017-11-16 20:53:39 +00:00
|
|
|
_, err = e.dbo.ClrP(tkey.Encode(), 0)
|
2016-07-04 10:37:29 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 13:33:02 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveScope(ctx context.Context, ast *sql.RemoveScopeStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
skey := &keys.SC{KV: ast.KV, NS: ast.NS, DB: ast.DB, SC: ast.Name.ID}
|
2017-11-16 20:53:39 +00:00
|
|
|
_, err = e.dbo.ClrP(skey.Encode(), 0)
|
2016-09-06 13:33:02 +00:00
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
return
|
2016-09-06 13:33:02 +00:00
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
}
|
2016-09-06 13:33:02 +00:00
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveTable(ctx context.Context, ast *sql.RemoveTableStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
|
|
|
for _, TB := range ast.What {
|
2016-09-06 13:33:02 +00:00
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
e.dbo.DelTB(ast.NS, ast.DB, TB.TB)
|
|
|
|
|
|
|
|
tb, err := e.dbo.GetTB(ast.NS, ast.DB, TB.TB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
tkey := &keys.TB{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB}
|
2018-02-09 15:08:27 +00:00
|
|
|
_, err = e.dbo.Clr(tkey.Encode())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
akey := &keys.Table{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB}
|
|
|
|
_, err = e.dbo.ClrP(akey.Encode(), 0)
|
2017-11-16 20:53:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if tb.Lock {
|
|
|
|
for _, FT := range tb.From {
|
|
|
|
tkey := &keys.FT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: FT.TB, FT: TB.TB}
|
|
|
|
if _, err = e.dbo.ClrP(tkey.Encode(), 0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *executor) executeRemoveEvent(ctx context.Context, ast *sql.RemoveEventStatement) (out []interface{}, err error) {
|
|
|
|
|
|
|
|
for _, TB := range ast.What {
|
|
|
|
|
|
|
|
e.dbo.DelEV(ast.NS, ast.DB, TB.TB, ast.Name.ID)
|
|
|
|
|
|
|
|
ekey := &keys.EV{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, EV: ast.Name.ID}
|
|
|
|
if _, err = e.dbo.ClrP(ekey.Encode(), 0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-09-06 13:33:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-04 10:37:29 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveField(ctx context.Context, ast *sql.RemoveFieldStatement) (out []interface{}, err error) {
|
2016-09-06 13:33:02 +00:00
|
|
|
|
2016-07-04 10:37:29 +00:00
|
|
|
for _, TB := range ast.What {
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
e.dbo.DelFD(ast.NS, ast.DB, TB.TB, ast.Name.ID)
|
|
|
|
|
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}
|
2017-11-16 20:53:39 +00:00
|
|
|
if _, err = e.dbo.ClrP(fkey.Encode(), 0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-07-04 10:37:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2016-05-11 19:23:21 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
func (e *executor) executeRemoveIndex(ctx context.Context, ast *sql.RemoveIndexStatement) (out []interface{}, err error) {
|
2016-07-04 10:37:29 +00:00
|
|
|
|
|
|
|
for _, TB := range ast.What {
|
|
|
|
|
2017-11-16 20:53:39 +00:00
|
|
|
e.dbo.DelIX(ast.NS, ast.DB, TB.TB, ast.Name.ID)
|
|
|
|
|
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}
|
2017-11-16 20:53:39 +00:00
|
|
|
if _, err = e.dbo.ClrP(ikey.Encode(), 0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-07-04 10:37:29 +00:00
|
|
|
|
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}
|
2017-11-16 20:53:39 +00:00
|
|
|
if _, err = e.dbo.ClrP(dkey.Encode(), 0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-07-04 10:37:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2016-02-27 01:00:19 +00:00
|
|
|
}
|