from sqlalchemy.types import TypeDecorator, VARCHAR


class GType(TypeDecorator):
    impl = VARCHAR
    cache_ok = True

    def process_bind_param(self, value, dialect):
        if value is not None:
            value = str(value)
        return value

    def process_result_value(self, value, dialect):
        if value is not None:
            value = int(value)
        return value

    def process_literal_param(self, value, dialect):
        return value