Fix PostgreSQL

This commit is contained in:
RunasSudo 2018-04-15 19:41:16 +10:00
parent 85b2e6e331
commit f0950effca
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -1,5 +1,5 @@
# Eos - Verifiable elections # Eos - Verifiable elections
# Copyright © 2017 RunasSudo (Yingtong Li) # Copyright © 2017-18 RunasSudo (Yingtong Li)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -35,17 +35,21 @@ class PostgreSQLDBProvider(eos.core.db.DBProvider):
return [x[0] for x in self.cur.fetchall()] return [x[0] for x in self.cur.fetchall()]
def get_all_by_fields(self, table, fields): def get_all_by_fields(self, table, fields):
def does_match(val):
if '_id' in fields and val['_id'] != fields.pop('_id'):
return False
if 'type' in fields and val['type'] != fields.pop('type'):
return False
for field in fields:
if val['value'][field] != fields[field]:
return False
return True
# TODO: Make this much better # TODO: Make this much better
result = [] result = []
for val in self.get_all(table): for val in self.get_all(table):
if '_id' in fields and val['_id'] != fields.pop('_id'): if does_match(val):
continue result.append(val)
if 'type' in fields and val['type'] != fields.pop('type'):
continue
for field in fields:
if val['value'][field] != fields[field]:
continue
result.append(val)
return result return result
def get_by_id(self, table, _id): def get_by_id(self, table, _id):