From 42534e13a972d99486db20f8fa3f94a56bbd5c42 Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Wed, 31 Aug 2022 01:12:44 +0100 Subject: [PATCH] Added tools to store lists as json --- server/app/tools/models.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 server/app/tools/models.py diff --git a/server/app/tools/models.py b/server/app/tools/models.py new file mode 100644 index 0000000..2bcfdf8 --- /dev/null +++ b/server/app/tools/models.py @@ -0,0 +1,16 @@ +from sqlalchemy import JSON, TypeDecorator +from sqlalchemy.dialects.sqlite import JSON + +from json import dumps, loads + + +class JsonString(TypeDecorator): + """Enables JSON storage by encoding and decoding on the fly.""" + + impl = JSON + + def process_bind_param(self, value, dialect): + return dumps(value) + + def process_result_value(self, value, dialect): + return loads(value) \ No newline at end of file