feat: add direct database access for scripts (v0.2.0)
Implement persistent SQLite database feature that allows scripts to query schedule data directly via SQL after loading XER files through MCP. Key changes: - Extend load_xer with db_path parameter for persistent database - Add get_database_info tool to retrieve database connection details - Add schema introspection with tables, columns, primary/foreign keys - Support WAL mode for concurrent read access - Use atomic write pattern to prevent corruption New features: - db_path=None: in-memory database (default, backward compatible) - db_path="": auto-generate path from XER filename (.sqlite extension) - db_path="/path/to/db": explicit persistent database path Response includes complete DatabaseInfo: - db_path: absolute path (or :memory:) - is_persistent: boolean - source_file: loaded XER path - loaded_at: ISO timestamp - schema: tables with columns, primary keys, foreign keys, row counts Closes: User Story 1, 2, 3 from 002-direct-db-access spec
This commit is contained in:
@@ -239,16 +239,18 @@ def query_relationships(
|
||||
lag_hours=row[6] or 0.0,
|
||||
pred_type=pred_type,
|
||||
)
|
||||
relationships.append({
|
||||
"task_pred_id": row[0],
|
||||
"task_id": row[1],
|
||||
"task_name": row[2],
|
||||
"pred_task_id": row[3],
|
||||
"pred_task_name": row[4],
|
||||
"pred_type": pred_type,
|
||||
"lag_hr_cnt": row[6],
|
||||
"driving": driving,
|
||||
})
|
||||
relationships.append(
|
||||
{
|
||||
"task_pred_id": row[0],
|
||||
"task_id": row[1],
|
||||
"task_name": row[2],
|
||||
"pred_task_id": row[3],
|
||||
"pred_task_name": row[4],
|
||||
"pred_type": pred_type,
|
||||
"lag_hr_cnt": row[6],
|
||||
"driving": driving,
|
||||
}
|
||||
)
|
||||
|
||||
return relationships, total
|
||||
|
||||
@@ -298,14 +300,16 @@ def get_predecessors(activity_id: str) -> list[dict]:
|
||||
lag_hours=row[4] or 0.0,
|
||||
pred_type=pred_type,
|
||||
)
|
||||
result.append({
|
||||
"task_id": row[0],
|
||||
"task_code": row[1],
|
||||
"task_name": row[2],
|
||||
"relationship_type": pred_type,
|
||||
"lag_hr_cnt": row[4],
|
||||
"driving": driving,
|
||||
})
|
||||
result.append(
|
||||
{
|
||||
"task_id": row[0],
|
||||
"task_code": row[1],
|
||||
"task_name": row[2],
|
||||
"relationship_type": pred_type,
|
||||
"lag_hr_cnt": row[4],
|
||||
"driving": driving,
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
@@ -355,14 +359,16 @@ def get_successors(activity_id: str) -> list[dict]:
|
||||
lag_hours=row[4] or 0.0,
|
||||
pred_type=pred_type,
|
||||
)
|
||||
result.append({
|
||||
"task_id": row[0],
|
||||
"task_code": row[1],
|
||||
"task_name": row[2],
|
||||
"relationship_type": pred_type,
|
||||
"lag_hr_cnt": row[4],
|
||||
"driving": driving,
|
||||
})
|
||||
result.append(
|
||||
{
|
||||
"task_id": row[0],
|
||||
"task_code": row[1],
|
||||
"task_name": row[2],
|
||||
"relationship_type": pred_type,
|
||||
"lag_hr_cnt": row[4],
|
||||
"driving": driving,
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user