40 lines
778 B
Go
40 lines
778 B
Go
package adapters
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
)
|
|
|
|
var dbTracer = otel.Tracer("adapters.db")
|
|
|
|
var (
|
|
dbSystemAttr = attribute.Key("db.system")
|
|
dbNameAttr = attribute.Key("db.name")
|
|
dbStatementAttr = attribute.Key("db.statement")
|
|
dbOperationAttr = attribute.Key("db.operation")
|
|
dbTableAttr = attribute.Key("db.sql.table")
|
|
)
|
|
|
|
type domainer[T any] interface {
|
|
AsDomain() T
|
|
}
|
|
|
|
func asDomainFunc[T any, U domainer[T]](in U) (out T) {
|
|
return in.AsDomain()
|
|
}
|
|
|
|
func joinColumns(columns []string) string {
|
|
return strings.Join(columns, ",")
|
|
}
|
|
|
|
func namedArgColumns(columns []string) string {
|
|
out := make([]string, len(columns))
|
|
for i, col := range columns {
|
|
out[i] = ":" + col
|
|
}
|
|
|
|
return joinColumns(out)
|
|
}
|