fix(proxy): new sqla interface for binding params to statements
This commit is contained in:
parent
b1f874eaf3
commit
358e945e34
1 changed files with 8 additions and 4 deletions
|
@ -144,13 +144,15 @@ class ProxyAutomation(TerraformAutomation):
|
|||
@classmethod
|
||||
def get_subgroups(cls) -> Dict[int, Dict[int, int]]:
|
||||
conn = db.engine.connect()
|
||||
result = conn.execute(text("""
|
||||
stmt = text("""
|
||||
SELECT origin.group_id, proxy.psg, COUNT(proxy.id) FROM proxy, origin
|
||||
WHERE proxy.origin_id = origin.id
|
||||
AND proxy.destroyed IS NULL
|
||||
AND proxy.provider = :provider
|
||||
GROUP BY origin.group_id, proxy.psg;
|
||||
"""), provider=cls.provider)
|
||||
""")
|
||||
stmt = stmt.bindparams(provider=cls.provider)
|
||||
result = conn.execute(stmt).all()
|
||||
subgroups: Dict[int, Dict[int, int]] = defaultdict(lambda: defaultdict(lambda: 0))
|
||||
for row in result:
|
||||
subgroups[row[0]][row[1]] = row[2]
|
||||
|
@ -160,14 +162,16 @@ class ProxyAutomation(TerraformAutomation):
|
|||
def next_subgroup(cls, group_id: int) -> Optional[int]:
|
||||
provider = cls() # Some attributes are set by constructor
|
||||
conn = db.engine.connect()
|
||||
result = conn.execute(text("""
|
||||
stmt = text("""
|
||||
SELECT proxy.psg, COUNT(proxy.id) FROM proxy, origin
|
||||
WHERE proxy.origin_id = origin.id
|
||||
AND proxy.destroyed IS NULL
|
||||
AND origin.group_id = :group_id
|
||||
AND proxy.provider = :provider
|
||||
GROUP BY proxy.psg ORDER BY proxy.psg;
|
||||
"""), provider=provider.short_name, group_id=group_id)
|
||||
""")
|
||||
stmt = stmt.bindparams(provider=provider.short_name, group_id=group_id)
|
||||
result = conn.execute(stmt).all()
|
||||
subgroups = {
|
||||
row[0]: row[1] for row in result
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue