Removed update/insert/delete

I don't use them and AFAIK this module has no other users
master
Salvo 'LtWorf' Tomaselli 2020-08-13 14:37:55 +07:00
parent 4722c9b0e8
commit 08e5131479
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF
4 changed files with 0 additions and 90 deletions

@ -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):

@ -1,4 +0,0 @@
p1=people.rename({"id":"ido"})
people.insert((123,"lala",0,31))
assert people!=p1
people.delete("id==123")

@ -1,4 +0,0 @@
p1=people.rename({"id":"ido"})
p1.insert((123,"lala",0,31))
assert people!=p1
people.delete("id==123")

@ -1,16 +0,0 @@
p1=people
p2=p1.rename({'id':'i'})
p2=p2.rename({'i':'id'})
assert p1==p2
assert p1._readonly
assert p2._readonly
# It is VERY important to not change the original relations
# or other tests might fail randomly, since the relations are
# only loaded once
p2.update('age==20', {'age':50})
assert p2._readonly == False
assert p1!=p2
p3 = p2.selection('age!=50')
p4 = p1.selection('age!=20')
assert p3==p4