google/adk-go

Database connections across services

Open

#340 geöffnet am 22. Nov. 2025

Auf GitHub ansehen
 (4 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Go (699 Forks)github user discovery
enhancementgood first issue

Repository-Metriken

Stars
 (8.108 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Was looking at the SessionService database implementation and noticed the database connection is opened by the service. It looks like this prevents me from opening a single database client and passing it to all the services (others still lack implementations)

func NewSessionService(dialector gorm.Dialector, opts ...gorm.Option) (session.Service, error) {
	db, err := gorm.Open(dialector, opts...)
	if err != nil {
		return nil, fmt.Errorf("error creating database session service: %w", err)
	}
	return &databaseService{db: db}, nil
}

so I changed it to look like this

func NewSessionService(db *gorm.DB) (session.Service, error) {
	return &databaseService{db: db}, nil
}

Another benefit to this is that my application can also use the same database connection for any extra tables it needs.

Thoughts on the change and the issue more generally?

Contributor Guide