Created
January 20, 2011 05:23
-
-
Save kijun/787453 to your computer and use it in GitHub Desktop.
Useful sqlalchemy custom types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sqlalchemy.types | |
class JSONType(sqlalchemy.types.PickleType): | |
"""An example | |
>>> class User(declarative_base): | |
... friends = Column(JSONType()) | |
... | |
... def update_friends(self, access_token): | |
... graph = facebook.GraphAPI(access_token) | |
... profile = graph.get_object("me") | |
... friends = graph.get_connections("me", "friends") | |
... if "data" in friends: | |
... self.friends = dict( | |
... [ (f["id"], f["name"]) for f in friends["data"] ] | |
... ) | |
""" | |
impl = sqlalchemy.types.UnicodeText | |
def __init__(self): | |
sqlalchemy.types.PickleType.__init__(self, pickler=json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment