This file looks large and may slow your browser down if we attempt
to syntax highlight it, so we are showing it without any
pretty colors.
Highlight
it anyway.
1 |
# -*- coding utf-8 -*- |
2 |
# classes/types.py |
3 |
# class:: Types |
4 |
# extend SQLAlchemy Types |
5 |
|
6 |
from datetime import datetime |
7 |
import json |
8 |
|
9 |
from sqlalchemy import types |
10 |
|
11 |
class JSONType(types.TypeDecorator): |
12 |
""" |
13 |
An extended type to store JSON as a TEXT in database. |
14 |
This class, converts dict to string while storing to database and |
15 |
similarly, convert string to dict while loading from database |
16 |
""" |
17 |
|
18 |
impl = types.Unicode |
19 |
|
20 |
def process_bind_param(self, value, dialect): |
21 |
return json.dumps(value) |
22 |
|
23 |
def process_result_value(self, value, dialect): |
24 |
return json.loads(value) |