def create(cls, label, kind, context = None, **attributes): r'''Creates a new symbol_table entry. Updates an existing database row (if found), or inserts a new row. Returns the id of the row. ''' if context is None: id = crud.read1_column('symbol_table', 'id', label=label, context=None, zero_ok=True) if id is not None: crud.update('symbol_table', {'id': id}, kind=kind, **attributes) if id in Symbols_by_id: del Symbols_by_id[id] del Symbols[label, None] return cls(id, label, context, kind=kind, **attributes) id = crud.insert('symbol_table', option='replace', label=label, kind=kind, context=context and context.id, **attributes) return cls(id, label, context, kind=kind, **attributes)
def write(self): r'''Update database to reflect changes on this object. ''' if self.updated_attrs: crud.update('symbol_table', {'label': self.label, 'context': self.context and self.context.id}, **dict((attr, getattr(self, attr)) for attr in self.updated_attrs)) self.updated_attrs.clear()