I'm getting some data in JSON, where boolean values are 0 & 1.
In the postgres table is a boolean field, and expect true & false.
I try this when loading the table:
class PGBool(types.TypeDecorator):
impl = types.BOOLEAN
def process_result_value(self, value, dialect):
#print value
if value is not None:
return bool(value)
return value
def listen(self, table, column_info):
type_ = column_info['type']
print column_info['name'], type_
if str(type_).split('.')[-1] == 'BOOLEAN':
column_info['type'] = PGBool
return column_info
def getTable(self, name):
return sq.Table(
name,
self.meta,
autoload=True,
autoload_with=self.con,
listeners=[
('column_reflect', listen)
]
)
def saveRecord(self, table, data):
..
..
if exist:
self.con.execute(
table.update().where(table.c.id == theGuid),
data
)
else:
self.con.execute(
table.insert(),
data
)
But the data is not converted, and still try to insert 0 & 1.