2025-04-29 17:35:21 +02:00
|
|
|
|
#
|
|
|
|
|
|
# Erminig - Fonctions relatives à la table upstreams
|
|
|
|
|
|
# Copyright (C) 2025 L0m1g
|
|
|
|
|
|
# Sous licence DOUARN - Voir le fichier LICENCE pour les détails
|
|
|
|
|
|
#
|
|
|
|
|
|
# Ce fichier fait partie du projet Erminig.
|
|
|
|
|
|
# Libre comme l’air, stable comme un menhir, et salé comme le beurre.
|
|
|
|
|
|
#
|
|
|
|
|
|
|
2025-04-29 17:15:19 +02:00
|
|
|
|
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
|