Read apps and resources from database

This commit is contained in:
JiriUhlir
2026-05-28 10:11:31 +02:00
parent a2edca2fec
commit db039e5988
2 changed files with 29 additions and 64 deletions
+16 -44
View File
@@ -35,51 +35,37 @@ def get_apps():
).fetchall()
con.close()
return [dict(row) for row in rows]
def get_app(app_id: str):
def update_app_resources(app_id: str, memory: str, cpus: str):
con = get_connection()
row = con.execute(
con.execute(
"""
SELECT
id,
name,
language,
version,
status,
COALESCE(memory, '') AS memory,
COALESCE(cpus, '') AS cpus,
updated_at
FROM apps
UPDATE apps
SET memory = ?,
cpus = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
""",
(app_id,),
).fetchone()
(
memory or None,
cpus or None,
app_id,
),
)
con.commit()
con.close()
if not row:
return None
return dict(row)
def get_deployments(limit: int = 100):
con = get_connection()
rows = con.execute(
"""
SELECT
id,
app_id,
kind,
status,
started_at,
finished_at,
returncode
SELECT id, app_id, kind, status, started_at, finished_at, returncode
FROM deployments
ORDER BY id DESC
LIMIT ?
@@ -88,7 +74,6 @@ def get_deployments(limit: int = 100):
).fetchall()
con.close()
return [dict(row) for row in rows]
@@ -97,16 +82,7 @@ def get_deployment(deployment_id: int):
row = con.execute(
"""
SELECT
id,
app_id,
kind,
status,
started_at,
finished_at,
returncode,
stdout,
stderr
SELECT id, app_id, kind, status, started_at, finished_at, returncode, stdout, stderr
FROM deployments
WHERE id = ?
""",
@@ -114,8 +90,4 @@ def get_deployment(deployment_id: int):
).fetchone()
con.close()
if not row:
return None
return dict(row)
return dict(row) if row else None