Changeset 439
- Timestamp:
- 04/30/07 22:54:09
- Files:
-
- trunk/arenas.py (modified) (3 diffs)
- trunk/storage/db.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/arenas.py
r438 r439 274 274 self._registered_classes[cls] = new_store 275 275 276 def view(self, cls, attrs, expr=None, **kwargs): 277 """Yield tuples of attrs for the given cls which match the expr. 278 279 cls: The Unit subclass for which to yield property tuples. 276 def view(self, relation, attrs, expr=None, **kwargs): 277 """Yield tuples of attrs for the given relation which match the expr. 278 279 relation: The Unit class or Join instance for which to yield 280 property tuples. 280 281 attrs: a sequence of strings; each should be the name of 281 282 a UnitProperty on the given cls. … … 304 305 305 306 if self.logflags & logflags.VIEW: 306 self.log("VIEW %s [%s]: %s" % (cls.__name__, attrs, expr)) 307 308 for row in self.storage(cls).view(cls, attrs, expr): 307 self.log("VIEW %s [%s]: %s" % (relation, attrs, expr)) 308 309 store = self._single_store(relation) 310 for row in store.view(relation, attrs, expr): 309 311 yield row 310 312 … … 421 423 self.log("VIEW %s [%s]: %s" % (relation, attributes, restriction)) 422 424 425 for row in self._single_store(relation).multiview(relation, attributes, restriction): 426 yield row 427 428 def _single_store(self, relation): 429 """Return the store for the given relation (or raise ValueError).""" 423 430 if hasattr(relation, "class1"): 424 431 stores = [self.storage(cls) for cls in relation] 425 firststore = stores[0]432 store = stores[0] 426 433 for s in stores: 427 if s is not firststore:428 raise ValueError(u" multiviewdoes not support multiple"434 if s is not store: 435 raise ValueError(u"This operation does not support multiple" 429 436 u" classes in disparate stores.") 430 437 else: 431 firststore = self.storage(relation) 432 433 for row in firststore.multiview(relation, attributes, restriction): 434 yield row 438 store = self.storage(relation) 439 return store 440 441 def insert_into(self, name, relation, attributes, restriction=None, 442 distinct=False): 443 """INSERT matching data INTO a new class and return the class.""" 444 store = self._single_store(relation) 445 return store.insert_into(name, relation, attributes, 446 restriction, distinct) 435 447 436 448 trunk/storage/db.py
r438 r439 111 111 relation = self.schema[classes.__name__] 112 112 return self.db.select(relation, attrs, restriction, distinct) 113 114 def insert_into(self, name, classes, attrs, restriction, distinct=False): 115 """INSERT matching data INTO a new class and return the class.""" 116 if isinstance(classes, dejavu.UnitJoin): 117 relation = self.tablejoin(classes) 118 else: 119 relation = self.schema[classes.__name__] 120 newtable = self.db.insert_into(name, relation, attrs, 121 restriction, distinct) 122 return Modeler(self.schema).make_class(name) 113 123 114 124 def recall(self, cls, expr=None):
