You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
551 B
23 lines
551 B
package database
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type ctxDatabaseKey struct{}
|
|
|
|
// GetFromContext function extracts the request data from context
|
|
func GetFromContext(ctx context.Context) (q *Database, ok bool) {
|
|
q, ok = ctx.Value(ctxDatabaseKey{}).(*Database)
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
|
|
return q, true
|
|
}
|
|
|
|
// WithContext creates the new context with a database attached
|
|
func WithContext(ctx context.Context, q *Database) (withQuery context.Context) {
|
|
db := NewDatabase(ctx, q.Client(), q.Name())
|
|
return context.WithValue(ctx, ctxDatabaseKey{}, db)
|
|
}
|
|
|