fix: move SQL query from route handler to SessionStore for better separation of concerns
Extracted SQL query from handleSessionInit route handler into SessionStore.getLatestUserPrompt() method to fix abstraction leak and improve type safety. Changes: - Added getLatestUserPrompt() method to SessionStore with proper return type - Replaced raw SQL query in SessionRoutes with type-safe method call - Removed direct database access through dbManager.getSessionStore().db - Improved separation of concerns (data layer vs HTTP layer) Benefits: - Type safety: Explicit return type instead of 'as any' cast - Maintainability: SQL query logic belongs in data layer - Testability: Can test query logic independently from HTTP layer - Consistency: Follows existing pattern of query methods in SessionStore Phase 3 Complete: SQL abstraction leak fixed in session init endpoint. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -218,7 +218,17 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Obje
|
||||
FROM sdk_sessions
|
||||
WHERE project IS NOT NULL AND project != ''
|
||||
ORDER BY project ASC
|
||||
`).all().map(t=>t.project)}getRecentSessionsWithStatus(e,s=3){return this.db.prepare(`
|
||||
`).all().map(t=>t.project)}getLatestUserPrompt(e){return this.db.prepare(`
|
||||
SELECT
|
||||
up.*,
|
||||
s.sdk_session_id,
|
||||
s.project
|
||||
FROM user_prompts up
|
||||
JOIN sdk_sessions s ON up.claude_session_id = s.claude_session_id
|
||||
WHERE up.claude_session_id = ?
|
||||
ORDER BY up.created_at_epoch DESC
|
||||
LIMIT 1
|
||||
`).get(e)}getRecentSessionsWithStatus(e,s=3){return this.db.prepare(`
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
s.sdk_session_id,
|
||||
|
||||
Reference in New Issue
Block a user