v1.0.170: fix prompts list — datetime serialization
This commit is contained in:
+13
-2
@@ -2,12 +2,19 @@
|
|||||||
from .connection import query, execute, execute_returning
|
from .connection import query, execute, execute_returning
|
||||||
|
|
||||||
|
|
||||||
|
def _serialize(row):
|
||||||
|
"""Convert datetime fields to strings for JSON serialization."""
|
||||||
|
if row and row.get("created_at"):
|
||||||
|
row["created_at"] = str(row["created_at"])
|
||||||
|
return row
|
||||||
|
|
||||||
|
|
||||||
def get_active(role):
|
def get_active(role):
|
||||||
rows = query(
|
rows = query(
|
||||||
"SELECT * FROM prompts WHERE role = %s AND is_active = true ORDER BY created_at DESC LIMIT 1",
|
"SELECT * FROM prompts WHERE role = %s AND is_active = true ORDER BY created_at DESC LIMIT 1",
|
||||||
(role,),
|
(role,),
|
||||||
)
|
)
|
||||||
return rows[0] if rows else None
|
return _serialize(rows[0]) if rows else None
|
||||||
|
|
||||||
|
|
||||||
def get(prompt_id):
|
def get(prompt_id):
|
||||||
@@ -40,10 +47,14 @@ def seed_defaults():
|
|||||||
|
|
||||||
def list_by_role(role):
|
def list_by_role(role):
|
||||||
"""List all versions for a role, newest first."""
|
"""List all versions for a role, newest first."""
|
||||||
return query(
|
rows = query(
|
||||||
"SELECT id, role, name, is_active, created_by, notes, created_at FROM prompts WHERE role=%s ORDER BY created_at DESC",
|
"SELECT id, role, name, is_active, created_by, notes, created_at FROM prompts WHERE role=%s ORDER BY created_at DESC",
|
||||||
(role,),
|
(role,),
|
||||||
)
|
)
|
||||||
|
for r in rows:
|
||||||
|
if r.get("created_at"):
|
||||||
|
r["created_at"] = str(r["created_at"])
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
def save_new_version(role, name, body, notes="", is_active=True):
|
def save_new_version(role, name, body, notes="", is_active=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user