Les choses sérieuses commencent
This commit is contained in:
parent
7a9fe18463
commit
c63f62721b
41 changed files with 1270 additions and 0 deletions
29
erminig/models/upstreams.py
Normal file
29
erminig/models/upstreams.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue