Files
appfactory-portal/app/db/apps.py
T
2026-05-28 09:44:54 +02:00

108 lines
1.8 KiB
Python

from app.db.database import get_connection
def get_apps():
con = get_connection()
rows = con.execute(
"""
SELECT
id,
name,
language,
version,
status,
COALESCE(memory, '') AS memory,
COALESCE(cpus, '') AS cpus,
updated_at
FROM apps
ORDER BY id
"""
).fetchall()
con.close()
return [dict(row) for row in rows]
def get_app(app_id: str):
con = get_connection()
row = con.execute(
"""
SELECT
id,
name,
language,
version,
status,
COALESCE(memory, '') AS memory,
COALESCE(cpus, '') AS cpus,
updated_at
FROM apps
WHERE id = ?
""",
(app_id,),
).fetchone()
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
FROM deployments
ORDER BY id DESC
LIMIT ?
""",
(limit,),
).fetchall()
con.close()
return [dict(row) for row in rows]
def get_deployment(deployment_id: int):
con = get_connection()
row = con.execute(
"""
SELECT
id,
app_id,
kind,
status,
started_at,
finished_at,
returncode,
stdout,
stderr
FROM deployments
WHERE id = ?
""",
(deployment_id,),
).fetchone()
con.close()
if not row:
return None
return dict(row)