A bit of cleanup
This commit is contained in:
parent
507b0a5a40
commit
9cbdb3772c
@ -2,6 +2,7 @@ from datetime import datetime, date
|
|||||||
|
|
||||||
from sqlalchemy import Integer, UnicodeText, Float, BigInteger
|
from sqlalchemy import Integer, UnicodeText, Float, BigInteger
|
||||||
from sqlalchemy import Boolean, Date, DateTime, Unicode, JSON
|
from sqlalchemy import Boolean, Date, DateTime, Unicode, JSON
|
||||||
|
from sqlalchemy.dialects.postgresql import JSONB
|
||||||
from sqlalchemy.types import TypeEngine
|
from sqlalchemy.types import TypeEngine
|
||||||
|
|
||||||
|
|
||||||
@ -16,25 +17,21 @@ class Types(object):
|
|||||||
date = Date
|
date = Date
|
||||||
datetime = DateTime
|
datetime = DateTime
|
||||||
|
|
||||||
def __init__(self, dialect = None):
|
def __init__(self, dialect=None):
|
||||||
self._dialect = dialect
|
self._dialect = dialect
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def json(self):
|
def json(self):
|
||||||
if self._dialect is not None and self._dialect == 'postgresql':
|
if self._dialect is not None and self._dialect == 'postgresql':
|
||||||
from sqlalchemy.dialects.postgresql import JSONB
|
|
||||||
return JSONB
|
return JSONB
|
||||||
return JSON
|
return JSON
|
||||||
|
|
||||||
def guess(self, sample, dialect = None):
|
def guess(self, sample):
|
||||||
"""Given a single sample, guess the column type for the field.
|
"""Given a single sample, guess the column type for the field.
|
||||||
|
|
||||||
If the sample is an instance of an SQLAlchemy type, the type will be
|
If the sample is an instance of an SQLAlchemy type, the type will be
|
||||||
used instead.
|
used instead.
|
||||||
"""
|
"""
|
||||||
if dialect is not None:
|
|
||||||
self._dialect = dialect
|
|
||||||
|
|
||||||
if isinstance(sample, TypeEngine):
|
if isinstance(sample, TypeEngine):
|
||||||
return sample
|
return sample
|
||||||
if isinstance(sample, bool):
|
if isinstance(sample, bool):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user