Convert BOOLEAN sqlite3 types to bool objects when retrieving them

This commit is contained in:
jesopo 2018-11-27 11:38:13 +00:00
parent fba1dd2271
commit dce050aac5

View file

@ -1,6 +1,8 @@
import json, os, sqlite3, threading, time, typing import json, os, sqlite3, threading, time, typing
from src import Logging from src import Logging
sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v)))
class Table(object): class Table(object):
def __init__(self, database): def __init__(self, database):
self.database = database self.database = database
@ -275,7 +277,8 @@ class Database(object):
self.log = log self.log = log
self.location = location self.location = location
self.database = sqlite3.connect(self.location, self.database = sqlite3.connect(self.location,
check_same_thread=False, isolation_level=None) check_same_thread=False, isolation_level=None,
detect_types=sqlite3.PARSE_DECLTYPES)
self.database.execute("PRAGMA foreign_keys = ON") self.database.execute("PRAGMA foreign_keys = ON")
self._cursor = None self._cursor = None
self._lock = threading.Lock() self._lock = threading.Lock()