web: properly handle null by fdev

This commit is contained in:
norohind 2021-12-17 20:11:08 +03:00
parent 2fea5b477e
commit 3daadc761c
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1
2 changed files with 16 additions and 3 deletions

View File

@ -18,6 +18,7 @@ class SqliteModel:
self.db = sqlite3.connect('squads.sqlite', check_same_thread=False)
self.db.row_factory = lambda c, r: dict(zip([col[0] for col in c.description], r))
self.db.create_function('null_fdev', 1, self.null_fdev, deterministic=True)
def close_model(self) -> None:
"""
@ -27,6 +28,18 @@ class SqliteModel:
self.db.close()
@staticmethod
def null_fdev(value):
print(value)
if value == '':
return None
elif value == 'None':
return None
else:
return value
def list_squads_by_tag(self, tag: str, pretty_keys=False, motd=False, resolve_tags=False, extended=False) -> list:
"""
Take tag and return all squads with tag matches

View File

@ -6,9 +6,9 @@ squads_by_tag_extended_raw_keys = """select
owner_id,
platform,
created,
power_name,
super_power_name,
faction_name,
null_fdev(power_name) as power_name,
null_fdev(super_power_name) as super_power_name,
null_fdev(faction_name) as faction_name,
user_tags,
inserted_timestamp,
squad_id