Created
November 15, 2011 20:04
-
-
Save lxfontes/1368159 to your computer and use it in GitHub Desktop.
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
from storm.locals import * | |
from twisted.internet import task,defer,reactor,threads | |
class User(object): | |
__storm_table__ = "person" | |
id = Int(primary=True) | |
name = Unicode() | |
class TwistedStore(Store): | |
def find(*args,**kwargs): | |
return threads.deferToThread(Store.find,*args,**kwargs) | |
def add(*args,**kwargs): | |
return threads.deferToThread(Store.add,*args,**kwargs) | |
def execute(*args,**kwargs): | |
return threads.deferToThread(Store.execute,*args,**kwargs) | |
def get(*args,**kwargs): | |
return threads.deferToThread(Store.get,*args,**kwargs) | |
def remove(*args,**kwargs): | |
return threads.deferToThread(Store.remove,*args,**kwargs) | |
def remove(*args,**kwargs): | |
return threads.deferToThread(Store.remove,*args,**kwargs) | |
@defer.inlineCallbacks | |
def main(): | |
database = create_database("mysql://root@localhost/test") | |
store = TwistedStore(database) | |
# store.execute("CREATE TABLE person (id INTEGER PRIMARY KEY,name VARCHAR)") | |
joe = User() | |
joe.name = u"Lucas" | |
print "%r,%r" % (joe.id,joe.name) | |
i = yield store.add(joe) | |
store.commit() | |
print "%r,%r" % (joe.id,joe.name) | |
rs = yield store.find(User, User.name == u'Lucas') | |
for u in rs: | |
print(u.name) | |
print(u.id) | |
print("done") | |
if __name__ == "__main__": | |
reactor.callWhenRunning(main) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment