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-02-20 01:11:50 +00:00
|
|
|
"github.com/abcum/surreal/log"
|
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-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveNamespaceStatement(ast *sql.RemoveNamespaceStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the namespace
|
|
|
|
nkey := &keys.NS{KV: ast.KV, NS: ast.Name}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, nkey.Encode(), 0)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveDatabaseStatement(ast *sql.RemoveDatabaseStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the database
|
|
|
|
dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, dkey.Encode(), 0)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveLoginStatement(ast *sql.RemoveLoginStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
if ast.Kind == sql.NAMESPACE {
|
|
|
|
|
|
|
|
// Remove the login
|
|
|
|
ukey := &keys.NU{KV: ast.KV, NS: ast.NS, US: ast.User}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, ukey.Encode(), 0)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ast.Kind == sql.DATABASE {
|
|
|
|
|
|
|
|
// Remove the login
|
|
|
|
ukey := &keys.DU{KV: ast.KV, NS: ast.NS, DB: ast.DB, US: ast.User}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, ukey.Encode(), 0)
|
2016-10-18 13:27:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveTokenStatement(ast *sql.RemoveTokenStatement) (out []interface{}, err error) {
|
2016-07-04 10:37:29 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
if ast.Kind == sql.NAMESPACE {
|
2016-07-04 10:37:29 +00:00
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the token
|
|
|
|
tkey := &keys.NT{KV: ast.KV, NS: ast.NS, TK: ast.Name}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, tkey.Encode(), 0)
|
2017-02-09 20:39:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ast.Kind == sql.DATABASE {
|
|
|
|
|
|
|
|
// Remove the token
|
|
|
|
tkey := &keys.DT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TK: ast.Name}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, tkey.Encode(), 0)
|
2016-07-04 10:37:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-06 13:33:02 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveScopeStatement(ast *sql.RemoveScopeStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the scope
|
|
|
|
skey := &keys.SC{KV: ast.KV, NS: ast.NS, DB: ast.DB, SC: ast.Name}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, 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-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveTableStatement(ast *sql.RemoveTableStatement) (out []interface{}, err error) {
|
2017-02-09 20:39:19 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
for _, TB := range ast.What {
|
2016-09-06 13:33:02 +00:00
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the table
|
|
|
|
tkey := &keys.TB{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, tkey.Encode(), 0)
|
2016-09-06 13:33:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-04 10:37:29 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveFieldStatement(ast *sql.RemoveFieldStatement) (out []interface{}, err error) {
|
2016-09-06 13:33:02 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2016-07-04 10:37:29 +00:00
|
|
|
for _, TB := range ast.What {
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the field
|
|
|
|
fkey := &keys.FD{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB, FD: ast.Name}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, fkey.Encode(), 0)
|
2016-07-04 10:37:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2016-05-11 19:23:21 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeRemoveIndexStatement(ast *sql.RemoveIndexStatement) (out []interface{}, err error) {
|
2016-07-04 10:37:29 +00:00
|
|
|
|
2017-02-20 01:11:50 +00:00
|
|
|
log.WithPrefix("sql").WithFields(map[string]interface{}{
|
|
|
|
"ns": ast.NS,
|
|
|
|
"db": ast.DB,
|
|
|
|
}).Debugln(ast)
|
|
|
|
|
2016-07-04 10:37:29 +00:00
|
|
|
for _, TB := range ast.What {
|
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the index
|
|
|
|
ikey := &keys.IX{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB, IX: ast.Name}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, ikey.Encode(), 0)
|
2016-07-04 10:37:29 +00:00
|
|
|
|
2017-02-09 20:39:19 +00:00
|
|
|
// Remove the index
|
2016-07-04 10:37:29 +00:00
|
|
|
dkey := &keys.Index{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB, IX: ast.Name, FD: keys.Ignore}
|
2017-02-09 20:43:24 +00:00
|
|
|
_, err = e.txn.DelP(0, dkey.Encode(), 0)
|
2016-07-04 10:37:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2016-02-27 01:00:19 +00:00
|
|
|
}
|