From 8be5f93f5b2d4b6f438ca84094937a0f7101c59b Mon Sep 17 00:00:00 2001 From: T Date: Sat, 2 Aug 2025 17:25:59 -0600 Subject: Initial commit of punchcard. Contains working time tracking commands, and the stub of a command to generate reports. --- internal/context/db.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 internal/context/db.go (limited to 'internal/context') diff --git a/internal/context/db.go b/internal/context/db.go new file mode 100644 index 0000000..a9f53d3 --- /dev/null +++ b/internal/context/db.go @@ -0,0 +1,23 @@ +package context + +import ( + "context" + + "punchcard/internal/queries" +) + +type dbContextKey struct{} + +// WithDB returns a new context with the database queries instance +func WithDB(ctx context.Context, q *queries.Queries) context.Context { + return context.WithValue(ctx, dbContextKey{}, q) +} + +// GetDB retrieves the database queries instance from context +func GetDB(ctx context.Context) *queries.Queries { + if q, ok := ctx.Value(dbContextKey{}).(*queries.Queries); ok { + return q + } + return nil +} + -- cgit v1.2.3