I have to work with a old database which stores almost all information as 
strings (VARCHAR, NCHAR). To create a usable interface, I tought of 
creating a UserDefinedType or a TypeDecorator to convert the values which 
are fed to the database or loaded from the database.

Both versions seem to work when used like this:

class IntegerString(types.UserDefinedType):


    def get_col_spec(self):
        return 'NCHAR'


    def column_expression(self, col):
        return sa.func.CONVERT(sa.literal_column('INT'), col)




class TestType(types.TypeDecorator):


    impl = types.NCHAR


    def process_bind_param(self, value, dialect):
        return str(value)


    def process_result_value(self, value, dialect):
        return int(value)


Where the IntergerString works at the database level and the TestType works 
at the application level. However, what is missing is type conversion if 
the column is used in Where Clauses. Is there a method to apply the type 
conversion at the database level for where clauses?


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to