Skip to content

feat(session/database): add NewSessionServiceFromDB constructor#724

Open
nuthalapativarun wants to merge 4 commits intogoogle:mainfrom
nuthalapativarun:feat/340-newsessionservice-from-db
Open

feat(session/database): add NewSessionServiceFromDB constructor#724
nuthalapativarun wants to merge 4 commits intogoogle:mainfrom
nuthalapativarun:feat/340-newsessionservice-from-db

Conversation

@nuthalapativarun
Copy link
Copy Markdown

@nuthalapativarun nuthalapativarun commented Apr 12, 2026

Link to Issue

Fixes #340

Description

Adds a NewSessionServiceFromDB(*gorm.DB) constructor alongside the existing NewSessionService(dialector, opts...). This allows callers who already manage a database connection to share it across multiple services, rather than having the session service open its own connection.

The existing NewSessionService is unchanged for full backward compatibility, as suggested by the maintainer in the issue comments.

Changes:

  • session/database/service.go: Added NewSessionServiceFromDB(db *gorm.DB) (session.Service, error) which returns an error if db is nil.
  • session/database/service_test.go: Added TestNewSessionServiceFromDB (nil guard, valid db, shared connection verification) and Test_databaseServiceFromDB which runs the full service contract suite via the new constructor.

Testing Plan

  • Unit tests added for nil guard, valid construction, and shared-connection assertion
  • Full service contract suite (Test_databaseServiceFromDB) passes via the new constructor
  • All existing tests pass: go test ./session/database/...
  • Build passes: go build ./...

Adds NewSessionServiceFromDB(*gorm.DB) alongside the existing
NewSessionService(dialector, opts...) so callers can pass a
pre-opened *gorm.DB and share a single database connection across
multiple services.

The existing constructor is unchanged for backward compatibility.

Fixes google#340
@nuthalapativarun
Copy link
Copy Markdown
Author

Hi, just checking in on this one — happy to make any adjustments if something needs to change. Let me know if there's anything blocking review. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database connections across services

1 participant