Log sql queries centrally, not separately

This commit is contained in:
Tobie Morgan Hitchcock 2017-02-23 10:11:52 +00:00
parent 98f103cbaf
commit 73c56e4df5
11 changed files with 6 additions and 130 deletions

View file

@ -16,7 +16,6 @@ package db
import (
"fmt"
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/item"
"github.com/abcum/surreal/util/keys"
@ -25,11 +24,6 @@ import (
func (e *executor) executeCreateStatement(ast *sql.CreateStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
for k, w := range ast.What {
if what, ok := w.(*sql.Param); ok {
ast.What[k] = e.ctx.Get(what.ID).Data()

View file

@ -310,6 +310,12 @@ func (e *executor) execute(quit <-chan bool, send chan<- *Response) {
err, now = nil, time.Now()
}
// When in debugging mode, log every sql
// query, along with the query execution
// speed, so we can analyse slow queries.
log.WithPrefix("sql").Debugln(stm)
// Check to see if the current statement is
// a TRANSACTION statement, and if it is
// then deal with it and move on to the next.

View file

@ -15,7 +15,6 @@
package db
import (
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/item"
"github.com/abcum/surreal/util/keys"
@ -24,11 +23,6 @@ import (
func (e *executor) executeDefineNamespaceStatement(ast *sql.DefineNamespaceStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Set the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.Name}
_, err = e.txn.Put(0, nkey.Encode(), ast.Encode())
@ -39,11 +33,6 @@ func (e *executor) executeDefineNamespaceStatement(ast *sql.DefineNamespaceState
func (e *executor) executeDefineDatabaseStatement(ast *sql.DefineDatabaseStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Set the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.NS}
nval := &sql.DefineNamespaceStatement{Name: ast.NS}
@ -59,11 +48,6 @@ func (e *executor) executeDefineDatabaseStatement(ast *sql.DefineDatabaseStateme
func (e *executor) executeDefineLoginStatement(ast *sql.DefineLoginStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
if ast.Kind == sql.NAMESPACE {
// Set the namespace
@ -101,11 +85,6 @@ func (e *executor) executeDefineLoginStatement(ast *sql.DefineLoginStatement) (o
func (e *executor) executeDefineTokenStatement(ast *sql.DefineTokenStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
if ast.Kind == sql.NAMESPACE {
// Set the namespace
@ -143,11 +122,6 @@ func (e *executor) executeDefineTokenStatement(ast *sql.DefineTokenStatement) (o
func (e *executor) executeDefineScopeStatement(ast *sql.DefineScopeStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Set the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.NS}
nval := &sql.DefineNamespaceStatement{Name: ast.NS}
@ -168,11 +142,6 @@ func (e *executor) executeDefineScopeStatement(ast *sql.DefineScopeStatement) (o
func (e *executor) executeDefineTableStatement(ast *sql.DefineTableStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Set the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.NS}
nval := &sql.DefineNamespaceStatement{Name: ast.NS}
@ -199,11 +168,6 @@ func (e *executor) executeDefineTableStatement(ast *sql.DefineTableStatement) (o
func (e *executor) executeDefineFieldStatement(ast *sql.DefineFieldStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Set the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.NS}
nval := &sql.DefineNamespaceStatement{Name: ast.NS}
@ -235,11 +199,6 @@ func (e *executor) executeDefineFieldStatement(ast *sql.DefineFieldStatement) (o
func (e *executor) executeDefineIndexStatement(ast *sql.DefineIndexStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Set the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.NS}
nval := &sql.DefineNamespaceStatement{Name: ast.NS}

View file

@ -16,7 +16,6 @@ package db
import (
"fmt"
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/item"
"github.com/abcum/surreal/util/keys"
@ -24,11 +23,6 @@ import (
func (e *executor) executeDeleteStatement(ast *sql.DeleteStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
for k, w := range ast.What {
if what, ok := w.(*sql.Param); ok {
ast.What[k] = e.ctx.Get(what.ID).Data()

View file

@ -15,18 +15,12 @@
package db
import (
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/data"
)
func (e *executor) executeInfoStatement(ast *sql.InfoStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
switch ast.Kind {
case sql.NAMESPACE:
return e.executeInfoNSStatement(ast)

View file

@ -15,17 +15,11 @@
package db
import (
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
)
func (e *executor) executeLetStatement(ast *sql.LetStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
switch what := ast.What.(type) {
default:
e.Set(ast.Name, what)

View file

@ -15,17 +15,11 @@
package db
import (
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
)
func (e *executor) executeRelateStatement(ast *sql.RelateStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
return nil, nil
}

View file

@ -15,18 +15,12 @@
package db
import (
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/keys"
)
func (e *executor) executeRemoveNamespaceStatement(ast *sql.RemoveNamespaceStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Remove the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.Name}
_, err = e.txn.DelP(0, nkey.Encode(), 0)
@ -37,11 +31,6 @@ func (e *executor) executeRemoveNamespaceStatement(ast *sql.RemoveNamespaceState
func (e *executor) executeRemoveDatabaseStatement(ast *sql.RemoveDatabaseStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Remove the database
dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name}
_, err = e.txn.DelP(0, dkey.Encode(), 0)
@ -52,11 +41,6 @@ func (e *executor) executeRemoveDatabaseStatement(ast *sql.RemoveDatabaseStateme
func (e *executor) executeRemoveLoginStatement(ast *sql.RemoveLoginStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
if ast.Kind == sql.NAMESPACE {
// Remove the login
@ -79,11 +63,6 @@ func (e *executor) executeRemoveLoginStatement(ast *sql.RemoveLoginStatement) (o
func (e *executor) executeRemoveTokenStatement(ast *sql.RemoveTokenStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
if ast.Kind == sql.NAMESPACE {
// Remove the token
@ -106,11 +85,6 @@ func (e *executor) executeRemoveTokenStatement(ast *sql.RemoveTokenStatement) (o
func (e *executor) executeRemoveScopeStatement(ast *sql.RemoveScopeStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
// Remove the scope
skey := &keys.SC{KV: ast.KV, NS: ast.NS, DB: ast.DB, SC: ast.Name}
_, err = e.txn.DelP(0, skey.Encode(), 0)
@ -121,11 +95,6 @@ func (e *executor) executeRemoveScopeStatement(ast *sql.RemoveScopeStatement) (o
func (e *executor) executeRemoveTableStatement(ast *sql.RemoveTableStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
for _, TB := range ast.What {
// Remove the table
@ -140,11 +109,6 @@ func (e *executor) executeRemoveTableStatement(ast *sql.RemoveTableStatement) (o
func (e *executor) executeRemoveFieldStatement(ast *sql.RemoveFieldStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
for _, TB := range ast.What {
// Remove the field
@ -159,11 +123,6 @@ func (e *executor) executeRemoveFieldStatement(ast *sql.RemoveFieldStatement) (o
func (e *executor) executeRemoveIndexStatement(ast *sql.RemoveIndexStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
for _, TB := range ast.What {
// Remove the index

View file

@ -15,17 +15,11 @@
package db
import (
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
)
func (e *executor) executeReturnStatement(ast *sql.ReturnStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
switch what := ast.What.(type) {
default:
out = append(out, what)

View file

@ -15,7 +15,6 @@
package db
import (
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/item"
"github.com/abcum/surreal/util/keys"
@ -23,11 +22,6 @@ import (
func (e *executor) executeSelectStatement(ast *sql.SelectStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
for k, w := range ast.What {
if what, ok := w.(*sql.Param); ok {
ast.What[k] = e.ctx.Get(what.ID).Data()

View file

@ -16,7 +16,6 @@ package db
import (
"fmt"
"github.com/abcum/surreal/log"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/item"
"github.com/abcum/surreal/util/keys"
@ -24,11 +23,6 @@ import (
func (e *executor) executeUpdateStatement(ast *sql.UpdateStatement) (out []interface{}, err error) {
log.WithPrefix("sql").WithFields(map[string]interface{}{
"ns": ast.NS,
"db": ast.DB,
}).Debugln(ast)
for k, w := range ast.What {
if what, ok := w.(*sql.Param); ok {
ast.What[k] = e.ctx.Get(what.ID).Data()