Documentation
¶
Overview ¶
Package database provides shared database services for agent-go consumers:
- ADK session.Service (lazy initialized, separate adk_sessions.db)
- GORM-backed main database for common tables + business tables
- MessageMetadataStore / SessionExtStore (GORM-persisted)
- DB() accessor for business-layer queries and migrations
Database layout:
<appDataDir>/data/ ├── <dbFileName> ← main DB (GORM): message_metadata, session_ext + business tables └── adk_sessions.db ← ADK internal: sessions, events, app_states, user_states
Index ¶
- func Checkpoint(db *sql.DB) error
- func CommonModels() []any
- func MigrateCommon(db *gorm.DB) error
- func Vacuum(db *sql.DB) error
- type DBService
- func (s *DBService) DB() *gorm.DB
- func (s *DBService) DeleteADKEvents(sessionID string) error
- func (s *DBService) GetADKMaintenanceDB() (*sql.DB, error)
- func (s *DBService) GetADKSessionEvents(sessionID string) ([]Message, error)
- func (s *DBService) GetDBPath() string
- func (s *DBService) GetSessionService() (session.Service, error)
- func (s *DBService) ListADKSessions(appName string) ([]Session, error)
- type Message
- type Session
- type SessionExtModel
- type SessionExtStore
- func (s *SessionExtStore) Delete(sessionID string) error
- func (s *SessionExtStore) GetApprovalMode(sessionID string) string
- func (s *SessionExtStore) GetSessionExt(sessionID string) *SessionExtModel
- func (s *SessionExtStore) GetSessionExtBatch(sessionIDs []string) map[string]*SessionExtModel
- func (s *SessionExtStore) SaveSessionExt(m *SessionExtModel) error
- func (s *SessionExtStore) SetApprovalMode(sessionID, mode string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Checkpoint ¶
Checkpoint performs a WAL checkpoint (TRUNCATE mode) on a SQLite database.
func CommonModels ¶
func CommonModels() []any
CommonModels returns all framework-level GORM models. Business layers should append their own models when calling AutoMigrate.
func MigrateCommon ¶
MigrateCommon runs AutoMigrate for framework-level tables. Business layers should call this with their own db, then add business tables.
Types ¶
type DBService ¶
type DBService struct {
SessionExt *SessionExtStore
// contains filtered or unexported fields
}
DBService provides ADK session.Service lazy initialization and a shared GORM database for common tables and business-layer extensions.
func NewDBService ¶
NewDBService creates a new DBService. The main database is opened immediately and common tables are migrated.
func (*DBService) DB ¶
DB returns the shared GORM database handle. Business layers use this for custom queries and AutoMigrate of business tables.
func (*DBService) DeleteADKEvents ¶
DeleteADKEvents deletes all ADK events for a given session from adk_sessions.db.
func (*DBService) GetADKMaintenanceDB ¶
GetADKMaintenanceDB opens a temporary read-write connection to adk_sessions.db for maintenance operations (WAL checkpoint, VACUUM). Caller must close the returned *sql.DB.
func (*DBService) GetADKSessionEvents ¶
GetADKSessionEvents returns messages/events for a session from the ADK database.
func (*DBService) GetSessionService ¶
GetSessionService returns the ADK session.Service (lazy initialized).
type Message ¶
type Message struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Seq int64 `json:"seq"`
TurnID string `json:"turn_id"`
ClientMsgID string `json:"client_msg_id,omitempty"`
Role string `json:"role"`
Content string `json:"content"`
Reasoning string `json:"reasoning,omitempty"`
ToolCall json.RawMessage `json:"tool_call,omitempty"`
Metadata json.RawMessage `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
Message is the generic message struct returned by ListHistory. This replaces msgdb.Message after the msgdb removal.
type Session ¶
type Session struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Title string `json:"title"`
ApprovalMode string `json:"approval_mode"`
WorkspaceID string `json:"workspace_id"`
TokenUsage string `json:"token_usage"`
LLMLastSentMsgID string `json:"llm_last_sent_msg_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Session is the generic session struct returned by ListSessions. This replaces msgdb.Session after the msgdb removal.
type SessionExtModel ¶
type SessionExtModel struct {
SessionID string `gorm:"primaryKey;size:64"`
ApprovalMode string `gorm:"size:16;default:default"`
Title string `gorm:"size:256;default:''"`
TokenUsage string `gorm:"type:text;default:'{}'"`
SystemPrompt string `gorm:"type:text;default:''"`
}
SessionExtModel stores extended session data (approval_mode, title, token_usage, system_prompt) that ADK session.Service does not natively support.
func (SessionExtModel) TableName ¶
func (SessionExtModel) TableName() string
type SessionExtStore ¶
type SessionExtStore struct {
// contains filtered or unexported fields
}
SessionExtStore provides GORM-persisted extended session data (title, token_usage, approval_mode, system_prompt) that ADK session.Service does not natively support.
func NewSessionExtStore ¶
func NewSessionExtStore(db *gorm.DB) *SessionExtStore
NewSessionExtStore creates a GORM-backed session extension store.
func (*SessionExtStore) Delete ¶
func (s *SessionExtStore) Delete(sessionID string) error
Delete removes the session extension record for a session.
func (*SessionExtStore) GetApprovalMode ¶
func (s *SessionExtStore) GetApprovalMode(sessionID string) string
GetApprovalMode returns the approval mode for a session. Returns "default" if not set.
func (*SessionExtStore) GetSessionExt ¶
func (s *SessionExtStore) GetSessionExt(sessionID string) *SessionExtModel
GetSessionExt returns the session extension record, creating a default one if not exists.
func (*SessionExtStore) GetSessionExtBatch ¶
func (s *SessionExtStore) GetSessionExtBatch(sessionIDs []string) map[string]*SessionExtModel
GetSessionExtBatch returns multiple session extension records in a single query.
func (*SessionExtStore) SaveSessionExt ¶
func (s *SessionExtStore) SaveSessionExt(m *SessionExtModel) error
SaveSessionExt persists the session extension record (create or update).
func (*SessionExtStore) SetApprovalMode ¶
func (s *SessionExtStore) SetApprovalMode(sessionID, mode string) error
SetApprovalMode sets the approval mode for a session.