Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions session/database/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ func NewSessionService(dialector gorm.Dialector, opts ...gorm.Option) (session.S
return &databaseService{db: db}, nil
}

// NewSessionServiceGorm creates a new [session.Service] implementation that uses a
// relational database (e.g., PostgreSQL, Spanner, SQLite) via an already initialized GORM DB.
// This allows reusing the same database across multiple ADK services and your application.
//
// It requires an initialized [*gorm.DB] to specify the database connection.
//
// It returns the new [session.Service] or an error if the provided *gorm.DB is nil.
func NewSessionServiceGorm(db *gorm.DB) (session.Service, error) {
if db == nil {
return nil, fmt.Errorf("session service: gorm.DB cannot be nil")
}
return &databaseService{db: db}, nil
}

// AutoMigrate runs the GORM auto-migration tool to ensure the database schema
// matches the internal storage models (e.g., storageSession, storageEvent).
//
Expand Down