from erminig.models.db import ErminigDB def upsert_upstream(db: ErminigDB, name, type_, url, pattern, file): db.cursor.execute( """ INSERT INTO upstreams (name, type, url, pattern, file, created_at) VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP) ON CONFLICT(name) DO UPDATE SET type=excluded.type, url=excluded.url, pattern=excluded.pattern, file=excluded.file RETURNING id """, (name, type_, url, pattern, file), ) row = db.cursor.fetchone() return row[0] if row else None def get_all_upstreams(db: ErminigDB): db.cursor.execute( """ SELECT id, name, type, url, pattern, file FROM upstreams """ ) rows = db.cursor.fetchall() return rows