1package db23import "context"45// ContextKey is the key used to store the database in the context.6var ContextKey = struct{ string }{"db"}78// FromContext returns the database from the context.9func FromContext(ctx context.Context) *DB {10 if db, ok := ctx.Value(ContextKey).(*DB); ok {11 return db12 }13 return nil14}1516// WithContext returns a new context with the database.17func WithContext(ctx context.Context, db *DB) context.Context {18 return context.WithValue(ctx, ContextKey, db)19}