Commits

Michael Twomey  committed e55cd60

Override the PickleType to use LONGBLOB in MySQL

Applying change from https://github.com/anedos/beaker

  • Participants
  • Parent commits b60a327
  • Branches default

Comments (0)

Files changed (1)

File beaker/ext/database.py

                 meta.bind = engine
                 return meta
             meta = DatabaseNamespaceManager.metadatas.get(meta_key, make_meta)
+
+            # Override the pickletype to use a LONGBLOB in MySQL
+            from sqlalchemy.dialects.mysql import LONGBLOB
+            from sqlalchemy.types import PickleType
+            class MyPickle(PickleType):
+                impl = LONGBLOB
+
             # Create the table object and cache it now
             cache = sa.Table(table_name, meta,
                              sa.Column('id', types.Integer, primary_key=True),
                              sa.Column('namespace', types.String(255), nullable=False),
                              sa.Column('accessed', types.DateTime, nullable=False),
                              sa.Column('created', types.DateTime, nullable=False),
-                             sa.Column('data', types.PickleType, nullable=False),
+                             sa.Column('data', MyPickle, nullable=False),
                              sa.UniqueConstraint('namespace')
-            )
+                             )
             cache.create(checkfirst=True)
             return cache
         self.hash = {}
             return
 
         cache = self.cache
-        result = sa.select([cache.c.data], 
+        result = sa.select([cache.c.data],
                            cache.c.namespace==self.namespace
                           ).execute().fetchone()
         if not result:
         # file is gone this will be a new namespace should it be saved.
         self._is_new = True
 
-    def __getitem__(self, key): 
+    def __getitem__(self, key):
         return self.hash[key]
 
-    def __contains__(self, key): 
+    def __contains__(self, key):
         return self.hash.has_key(key)
 
     def __setitem__(self, key, value):