mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
Detect subclasses of dict/tuple/list, fixes #87
This commit is contained in:
parent
5e0000609f
commit
685e6a1bb3
4 changed files with 9 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from .utils import sqlite3, OperationalError, suggest_column_types
|
||||
from collections import namedtuple
|
||||
from collections import namedtuple, OrderedDict
|
||||
import datetime
|
||||
import hashlib
|
||||
import itertools
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@ def suggest_column_types(records):
|
|||
for key, types in all_column_types.items():
|
||||
if len(types) == 1:
|
||||
t = list(types)[0]
|
||||
# But if it's list / tuple / dict, use str instead as we
|
||||
# will be storing it as JSON in the table
|
||||
if t in (list, tuple, dict):
|
||||
t = str
|
||||
# But if it's a subclass of list / tuple / dict, use str
|
||||
# instead as we will be storing it as JSON in the table
|
||||
for superclass in (list, tuple, dict):
|
||||
if issubclass(t, superclass):
|
||||
t = str
|
||||
elif {int, bool}.issuperset(types):
|
||||
t = int
|
||||
elif {int, float, bool}.issuperset(types):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue