Adds support for JSONB in PostgresQL
Passes dialect to instances of `Types` for vendor-specific type mappings.
This commit is contained in:
parent
aeaab50043
commit
7fee6da44d
@ -45,9 +45,9 @@ class Database(object):
|
||||
if len(schema_qs):
|
||||
schema = schema_qs.pop()
|
||||
|
||||
self.types = Types()
|
||||
self.schema = schema
|
||||
self.engine = create_engine(url, **engine_kwargs)
|
||||
self.types = Types(self.engine.dialect.name)
|
||||
self.url = url
|
||||
self.row_type = row_type
|
||||
self.ensure_schema = ensure_schema
|
||||
|
||||
@ -15,14 +15,26 @@ class Types(object):
|
||||
boolean = Boolean
|
||||
date = Date
|
||||
datetime = DateTime
|
||||
json = JSON
|
||||
|
||||
def guess(self, sample):
|
||||
def __init__(self, dialect = None):
|
||||
self._dialect = dialect
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
if self._dialect is not None and self._dialect == 'postgresql':
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
return JSONB
|
||||
return JSON
|
||||
|
||||
def guess(self, sample, dialect = None):
|
||||
"""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
|
||||
used instead.
|
||||
"""
|
||||
if dialect is not None:
|
||||
self._dialect = dialect
|
||||
|
||||
if isinstance(sample, TypeEngine):
|
||||
return sample
|
||||
if isinstance(sample, bool):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user