Skip to content

Commit

Permalink
refactoring orm manager to use client interface
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelnicolay committed Sep 17, 2012
1 parent f10d72a commit 28df577
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions mongotor/orm/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

from bson.son import SON
from tornado import gen
from mongotor import message
from mongotor.database import Database
from mongotor.cursor import Cursor
from mongotor.client import Client


class Manager(object):
Expand All @@ -29,9 +28,8 @@ def __init__(self, collection):

@gen.engine
def find_one(self, query, callback):

client = getattr(Database(), self.collection.__collection__)
result, error = yield gen.Task(client.find, query, limit=-1)
client = Client(Database(), self.collection.__collection__)
result, error = yield gen.Task(client.find_one, query)

instance = None
if result:
Expand All @@ -41,7 +39,7 @@ def find_one(self, query, callback):

@gen.engine
def find(self, query, callback, **kw):
client = getattr(Database(), self.collection.__collection__)
client = Client(Database(), self.collection.__collection__)
result, error = yield gen.Task(client.find, query, **kw)

items = []
Expand Down Expand Up @@ -162,10 +160,8 @@ def map_reduce(self, map_, reduce_, callback, query=None, out=None):

@gen.engine
def truncate(self, callback=None):
collection_name = Database().get_collection_name(self.collection.__collection__)
message_delete = message.delete(collection_name, {}, True, {})

yield gen.Task(Database().send_message, message_delete)
client = Client(Database(), self.collection.__collection__)
yield gen.Task(client.remove, {})

if callback:
callback()

0 comments on commit 28df577

Please sign in to comment.