Changeset 475
- Timestamp:
- 08/30/07 16:50:59
- Files:
-
- trunk/sandboxes.py (modified) (1 diff)
- trunk/storage/__init__.py (modified) (1 diff)
- trunk/storage/db.py (modified) (2 diffs)
- trunk/test/zoo_fixture.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/sandboxes.py
r474 r475 394 394 self.view(dejavu.Query(cls, (attr,), expr, **kwargs))]) 395 395 396 def count(self, cls, expr ):396 def count(self, cls, expr=None): 397 397 """Number of Units of the given cls which match the given expr.""" 398 398 if cls.identifiers: trunk/storage/__init__.py
r474 r475 429 429 return [x for x in self.xview(query, distinct=distinct)] 430 430 431 def count(self, cls, expr ):431 def count(self, cls, expr=None): 432 432 """Number of Units of the given cls which match the given expr.""" 433 433 if cls.identifiers: trunk/storage/db.py
r474 r475 34 34 35 35 import geniusql 36 from geniusql import logic 36 from geniusql import logic, logicfuncs 37 37 38 38 import dejavu … … 261 261 for row in data: 262 262 yield tuple(row) 263 264 def count(self, cls, expr=None): 265 """Number of Units of the given cls which match the given expr.""" 266 if cls.identifiers: 267 uniq = cls.identifiers 268 else: 269 uniq = cls._properties.keys() 270 # TODO: handle multiple args to count() 271 counter = lambda x: [logicfuncs.count(getattr(x, uniq[0]))] 272 273 query = dejavu.Query(cls, counter, expr) 274 275 if self.logflags & logflags.VIEW: 276 self.log(logflags.VIEW.message(query, False)) 277 278 data = self.select(query) 279 if data.statement.imperfect: 280 # ^%$#@! There's no way to handle imperfect queries without 281 # creating all involved Units, which defeats the performance 282 # benefits of view. 283 clsname = self.__class__.__name__ 284 warnings.warn("The requested query cannot produce perfect SQL " 285 "with a %s datasource. It may take an absurdly " 286 "long time to run, since each unit must be fully-" 287 "formed. %s" % (clsname, query), StorageWarning) 288 return storage.StorageManager.count(self, cls, expr) 289 else: 290 return data.scalar() 263 291 264 292 def multirecall(self, relation, expr): trunk/test/zoo_fixture.py
r474 r475 572 572 escapees = box.view((Animal, ['Legs'], f), distinct=True) 573 573 self.assertEqual(escapees, [(4, ), ]) 574 575 # count should use an aggregate function when using DB's 576 fourlegged = root.count(Animal, lambda x: x.Legs == 4) 577 self.assertEqual(fourlegged, 4) 578 topics = root.count(Exhibit) 579 self.assertEqual(topics, 2) 574 580 575 581 # range should return a sorted list
