On Thu, Jun 9, 2011 at 7:21 PM, Michael Bayer <[email protected]> wrote:
>
> On Jun 9, 2011, at 12:37 PM, Eric Lemoine wrote:
>
>> On Thu, Jun 9, 2011 at 6:28 PM, Michael Bayer <[email protected]>
>> wrote:
>>>
>>>
>>> That's the default adaption provided by TypeEngine.adapt(). Provide your
>>> own adapt() that does what's needed. For examples see Interval, Enum.
>>
>> Ok, I'll take a look at adapt(). Note that our Geometry type isn't
>> specific to Oracle though.
>
> When you get it going, if you can show us what you're doing, we can create a
> prototypical version of your type, demonstrating the kind of "add new
> arguments per dialect" functionality it has, and add it to our test suite,
> to ensure those usage patterns don't break. SQLAlchemy usually uses
> distinct type classes per backend to handle backend-specific arguments, so
> your approach of allowing DB-specific keyword arguments to a single type,
> which while entirely appropriate in your case, isn't a pattern we test for at
> the moment.
Hi Michael
Here's our TypeEngine:
class GeometryBase(TypeEngine):
"""Base Geometry column type for all spatial databases.
Converts bind/result values to/from a generic Persistent value.
This is used as a base class and overridden into dialect specific
Persistent values.
"""
name = 'GEOMETRY'
def __init__(self, dimension=2, srid=4326, spatial_index=True, **kwargs):
self.dimension = dimension
self.srid = srid
self.spatial_index = spatial_index
self.kwargs = kwargs
super(GeometryBase, self).__init__()
def bind_processor(self, dialect):
def process(value):
if value is not None:
if isinstance(value, SpatialElement):
if isinstance(value.desc, SpatialElement):
return value.desc.desc
return value.desc
else:
return value
else:
return value
return process
def result_processor(self, dialect, coltype=None):
def process(value):
if value is not None:
return PersistentSpatialElement(value)
else:
return value
return process
def _compiler_dispatch(self, *args):
"""Required for the Cast() operator when used for the compilation
of DBSpatialElement"""
return self.name
def adapt(self, cls, **kwargs):
return cls(dimension=self.dimension, srid=self.srid,
spatial_index=self.spatial_index,
**self.kwargs)
So dialect-specific parameters are stored in self.kwargs.
I can try to add a test to SQLAlchemy if you indicate me where this
test should go.
Cheers
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : [email protected]
http://www.camptocamp.com
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.