2016-09-19 10:08:44 +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 (
|
2016-11-23 12:53:27 +00:00
|
|
|
"github.com/abcum/surreal/mem"
|
2016-09-19 10:08:44 +00:00
|
|
|
"github.com/abcum/surreal/sql"
|
|
|
|
"github.com/abcum/surreal/util/data"
|
|
|
|
)
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeInfoStatement(ast *sql.InfoStatement) (out []interface{}, err error) {
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
switch ast.Kind {
|
|
|
|
case sql.NAMESPACE:
|
2017-02-09 20:43:24 +00:00
|
|
|
return e.executeInfoNSStatement(ast)
|
2016-11-23 12:53:27 +00:00
|
|
|
case sql.DATABASE:
|
2017-02-09 20:43:24 +00:00
|
|
|
return e.executeInfoDBStatement(ast)
|
2016-11-23 12:53:27 +00:00
|
|
|
case sql.TABLE:
|
2017-02-09 20:43:24 +00:00
|
|
|
return e.executeInfoTBStatement(ast)
|
2016-11-23 12:53:27 +00:00
|
|
|
}
|
2016-10-18 13:27:17 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeInfoNSStatement(ast *sql.InfoStatement) (out []interface{}, err error) {
|
2016-11-23 12:53:27 +00:00
|
|
|
|
|
|
|
res := data.New()
|
|
|
|
res.Array("logins")
|
|
|
|
res.Array("tokens")
|
|
|
|
res.Array("databs")
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
out = append(out, res.Data())
|
2016-09-20 23:36:37 +00:00
|
|
|
}
|
2016-11-23 12:53:27 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
db := mem.GetNS(ast.NS)
|
|
|
|
|
|
|
|
for _, v := range db.AC {
|
|
|
|
res.Inc(v, "logins")
|
|
|
|
}
|
2016-09-20 23:36:37 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
for _, v := range db.TK {
|
|
|
|
res.Inc(v, "tokens")
|
|
|
|
}
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
for _, v := range db.DB {
|
|
|
|
res.Inc(v, "databs")
|
|
|
|
}
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
out = append(out, res.Data())
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
return
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeInfoDBStatement(ast *sql.InfoStatement) (out []interface{}, err error) {
|
2016-11-23 12:53:27 +00:00
|
|
|
|
|
|
|
res := data.New()
|
|
|
|
res.Array("logins")
|
|
|
|
res.Array("tokens")
|
|
|
|
res.Array("scopes")
|
|
|
|
res.Array("tables")
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
out = append(out, res.Data())
|
2016-09-19 10:08:44 +00:00
|
|
|
}
|
2016-11-23 12:53:27 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
db := mem.GetNS(ast.NS).GetDB(ast.DB)
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
for _, v := range db.AC {
|
|
|
|
res.Inc(v, "logins")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range db.TK {
|
|
|
|
res.Inc(v, "tokens")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range db.SC {
|
|
|
|
res.Inc(v, "scopes")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range db.TB {
|
|
|
|
res.Inc(v, "tables")
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, res.Data())
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:43:24 +00:00
|
|
|
func (e *executor) executeInfoTBStatement(ast *sql.InfoStatement) (out []interface{}, err error) {
|
2016-11-23 12:53:27 +00:00
|
|
|
|
|
|
|
res := data.New()
|
|
|
|
res.Array("fields")
|
|
|
|
res.Array("indexs")
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
out = append(out, res.Data())
|
2016-09-19 10:08:44 +00:00
|
|
|
}
|
2016-11-23 12:53:27 +00:00
|
|
|
}()
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
tb := mem.GetNS(ast.NS).GetDB(ast.DB).GetTB(ast.What)
|
2016-09-19 10:08:44 +00:00
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
for _, v := range tb.RU {
|
|
|
|
res.Inc(v, "rules")
|
2016-09-19 10:08:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 12:53:27 +00:00
|
|
|
for _, v := range tb.FD {
|
|
|
|
res.Inc(v, "fields")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range tb.IX {
|
|
|
|
res.Inc(v, "indexs")
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, res.Data())
|
|
|
|
|
2016-09-19 10:08:44 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
}
|