summaryrefslogtreecommitdiff
path: root/src/backend/querydb.py
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2024-08-31 00:18:59 +0100
committerV3n3RiX <venerix@koprulu.sector>2024-08-31 18:11:30 +0100
commite327ad76cfd12c8d70b8f9bee5f2b86c975ed073 (patch)
tree4a6a288aedc7d82415c9ccbce3754b83412ffc4b /src/backend/querydb.py
parentf9b4ed29fc0b2769f4e2e856e1dbc6d94502c637 (diff)
unify db queryingv6.2408.0
Diffstat (limited to 'src/backend/querydb.py')
-rw-r--r--src/backend/querydb.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/backend/querydb.py b/src/backend/querydb.py
new file mode 100644
index 0000000..bc87123
--- /dev/null
+++ b/src/backend/querydb.py
@@ -0,0 +1,89 @@
+#!usr/bin/python3
+
+def start(filter, cat='', pn='', desc=''):
+ NOVIRT = "AND cat NOT LIKE 'virtual'"
+ SELECTS = {
+ 'all': f'''SELECT
+ i.category AS cat,
+ i.name as pn,
+ i.version as iv,
+ IFNULL(a.version, 'alien') AS av,
+ d.description AS desc
+ FROM local_packages AS i LEFT OUTER JOIN remote_packages as a
+ ON i.category = a.category
+ AND i.name = a.name
+ AND i.slot = i.slot
+ LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category
+ WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}
+ UNION
+ SELECT
+ a.category AS cat,
+ a.name as pn,
+ IFNULL(i.version, 'None') AS iv,
+ a.version as av,
+ d.description AS desc
+ FROM remote_packages AS a LEFT OUTER JOIN local_packages AS i
+ ON a.category = i.category
+ AND a.name = i.name
+ AND a.slot = i.slot
+ LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category
+ WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''',
+ 'installed': f'''SELECT
+ i.category AS cat,
+ i.name AS pn,
+ i.version AS iv,
+ a.version as av,
+ d.description AS desc
+ FROM local_packages AS i
+ LEFT JOIN remote_packages AS a
+ ON i.category = a.category
+ AND i.name = a.name
+ AND i.slot = i.slot
+ LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category
+ WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''',
+ 'alien': f'''SELECT
+ i.category AS cat,
+ i.name AS pn,
+ i.version as iv,
+ IFNULL(a.version, 'alien') AS av,
+ d.description AS desc
+ FROM local_packages AS i
+ LEFT JOIN remote_packages AS a
+ ON a.category = i.category
+ AND a.name = i.name
+ AND a.slot = i.slot
+ LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category
+ WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}
+ AND av IS 'alien' ''',
+ 'available': f'''SELECT
+ a.category AS cat,
+ a.name AS pn,
+ i.version as iv,
+ a.version AS av,
+ d.description AS desc
+ FROM remote_packages AS a
+ LEFT JOIN local_packages AS i
+ ON a.category = i.category
+ AND a.name = i.name
+ AND a.slot = i.slot
+ LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category
+ WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}
+ AND iv IS NULL''',
+ 'upgradable': f'''SELECT
+ i.category AS cat,
+ i.name AS pn,
+ i.version as iv,
+ a.version AS av,
+ d.description AS desc
+ FROM local_packages AS i
+ INNER JOIN remote_packages AS a
+ ON i.category = a.category
+ AND i.name = a.name
+ AND i.slot = i.slot
+ LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category
+ WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}
+ AND iv <> av'''
+ }
+
+ return SELECTS[filter]
+