Removed update/insert/delete
I don't use them and AFAIK this module has no other users
This commit is contained in:
@@ -371,72 +371,6 @@ class Relation(NamedTuple):
|
||||
|
||||
return res
|
||||
|
||||
def update(self, expr: str, dic: dict) -> int:
|
||||
'''
|
||||
Updates certain values of a relation.
|
||||
|
||||
expr must be a valid Python expression that can contain field names.
|
||||
|
||||
This operation will change the relation itself instead of generating a new one,
|
||||
updating all the tuples where expr evaluates as True.
|
||||
|
||||
Dic must be a dictionary that has the form "field name":"new value". Every kind of value
|
||||
will be converted into a string.
|
||||
|
||||
Returns the number of affected rows.
|
||||
'''
|
||||
affected = self.selection(expr)
|
||||
not_affected = self.difference(affected)
|
||||
|
||||
new_values = tuple(
|
||||
zip(self.header.getAttributesId(dic.keys()), dic.values())
|
||||
)
|
||||
|
||||
for i in set(affected.content):
|
||||
li = list(i)
|
||||
|
||||
for column, value in new_values:
|
||||
li[column] = value
|
||||
not_affected.insert(li)
|
||||
|
||||
self.content = not_affected.content
|
||||
return len(affected)
|
||||
|
||||
def insert(self, values: Union[list,tuple]) -> int:
|
||||
'''
|
||||
Inserts a tuple in the relation.
|
||||
This function will not insert duplicate tuples.
|
||||
All the values will be converted in string.
|
||||
Will return the number of inserted rows.
|
||||
|
||||
Will fail if the tuple has the wrong amount of items.
|
||||
'''
|
||||
|
||||
if len(self.header) != len(values):
|
||||
raise Exception(
|
||||
'Tuple has the wrong size. Expected %d, got %d' % (
|
||||
len(self.header),
|
||||
len(values)
|
||||
)
|
||||
)
|
||||
|
||||
prevlen = len(self.content)
|
||||
self.content.add(tuple(map(Rstring, values)))
|
||||
return len(self.content) - prevlen
|
||||
|
||||
def delete(self, expr: str) -> int:
|
||||
'''
|
||||
Delete, expr must be a valid Python expression; can contain field names.
|
||||
|
||||
This operation will change the relation itself instead of generating a new one,
|
||||
deleting all the tuples where expr evaluates as True.
|
||||
|
||||
Returns the number of affected rows.'''
|
||||
|
||||
l = len(self.content)
|
||||
self.content = self.difference(self.selection(expr)).content
|
||||
return len(self.content) - l
|
||||
|
||||
|
||||
class Header(tuple):
|
||||
|
||||
|
Reference in New Issue
Block a user