mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-10-08 23:24:32 +02:00
.github
api
cmd
configs
init
internal
api
archiver
auth
config
graph
importer
metricDataDispatcher
metricdata
repository
migrations
testdata
dbConnection.go
hooks.go
job.go
jobCreate.go
jobFind.go
jobQuery.go
job_test.go
migration.go
repository_test.go
stats.go
stats_test.go
tags.go
transaction.go
user.go
userConfig.go
userConfig_test.go
routerConfig
taskManager
util
pkg
tools
web
.gitignore
.goreleaser.yaml
LICENSE
Makefile
README.md
ReleaseNotes.md
go.mod
go.sum
gqlgen.yml
startDemo.sh
tools.go
29 lines
960 B
Go
29 lines
960 B
Go
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
|
// All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
|
)
|
|
|
|
// Hooks satisfies the sqlhook.Hooks interface
|
|
type Hooks struct{}
|
|
|
|
// Before hook will print the query with it's args and return the context with the timestamp
|
|
func (h *Hooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
|
|
log.Debugf("SQL query %s %q", query, args)
|
|
return context.WithValue(ctx, "begin", time.Now()), nil
|
|
}
|
|
|
|
// After hook will get the timestamp registered on the Before hook and print the elapsed time
|
|
func (h *Hooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
|
|
begin := ctx.Value("begin").(time.Time)
|
|
log.Debugf("Took: %s\n", time.Since(begin))
|
|
return ctx, nil
|
|
}
|