summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/hook.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-09-10 14:42:14 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-10 14:42:14 +0200
commitf2e5bedea6fb93fbbf68ed8f7153c353cc57a9f0 (patch)
tree475ae9e7470d0df670ab2a59dce351cd1d07498a /vendor/github.com/uptrace/bun/hook.go
parentfixes + db changes (#204) (diff)
downloadgotosocial-f2e5bedea6fb93fbbf68ed8f7153c353cc57a9f0.tar.xz
migrate go version to 1.17 (#203)
* migrate go version to 1.17 * update contributing
Diffstat (limited to 'vendor/github.com/uptrace/bun/hook.go')
-rw-r--r--vendor/github.com/uptrace/bun/hook.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/vendor/github.com/uptrace/bun/hook.go b/vendor/github.com/uptrace/bun/hook.go
index 4cfa68fa6..88f8adbf2 100644
--- a/vendor/github.com/uptrace/bun/hook.go
+++ b/vendor/github.com/uptrace/bun/hook.go
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"reflect"
+ "strings"
"sync/atomic"
"time"
@@ -13,7 +14,7 @@ import (
type QueryEvent struct {
DB *DB
- QueryAppender schema.QueryAppender
+ QueryAppender schema.Query
Query string
QueryArgs []interface{}
@@ -24,6 +25,23 @@ type QueryEvent struct {
Stash map[interface{}]interface{}
}
+func (e *QueryEvent) Operation() string {
+ if e.QueryAppender != nil {
+ return e.QueryAppender.Operation()
+ }
+ return queryOperation(e.Query)
+}
+
+func queryOperation(query string) string {
+ if idx := strings.IndexByte(query, ' '); idx > 0 {
+ query = query[:idx]
+ }
+ if len(query) > 16 {
+ query = query[:16]
+ }
+ return query
+}
+
type QueryHook interface {
BeforeQuery(context.Context, *QueryEvent) context.Context
AfterQuery(context.Context, *QueryEvent)
@@ -31,7 +49,7 @@ type QueryHook interface {
func (db *DB) beforeQuery(
ctx context.Context,
- queryApp schema.QueryAppender,
+ queryApp schema.Query,
query string,
queryArgs []interface{},
) (context.Context, *QueryEvent) {