diff options
author | T <t@tjp.lol> | 2025-08-02 17:25:59 -0600 |
---|---|---|
committer | T <t@tjp.lol> | 2025-08-04 09:34:14 -0600 |
commit | 8be5f93f5b2d4b6f438ca84094937a0f7101c59b (patch) | |
tree | 3cedb6379818a28179e269477c12ae06dd57ca36 /internal/context |
Initial commit of punchcard.
Contains working time tracking commands, and the stub of a command to
generate reports.
Diffstat (limited to 'internal/context')
-rw-r--r-- | internal/context/db.go | 23 |
1 files changed, 23 insertions, 0 deletions
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 +} + |