id==0 is now a valid id, thanks Paolo
@@ -532,7 +532,7 @@ class Table(Serializable, BasicStorage):
return query
def __getitem__(self, key):
- if not key:
+ if key is None:
return None
elif isinstance(key, dict):
""" for keyed table """
@@ -598,7 +598,9 @@ class Table(Serializable, BasicStorage):
return None
def __setitem__(self, key, value):
- if isinstance(key, dict) and isinstance(value, dict):
+ if key is None:
+ self.insert(**self._filter_fields(value))
+ elif isinstance(key, dict) and isinstance(value, dict):
""" option for keyed table """
if set(key.keys()) == set(self._primarykey):
value = self._filter_fields(value)
@@ -613,9 +615,7 @@ class Table(Serializable, BasicStorage):
'key must have all fields from primary key: %s' %
self._primarykey)
elif str(key).isdigit():
- if key == 0:
- self.insert(**self._filter_fields(value))
- elif self._db(self._id == key)\
+ self._db(self._id == key)\
.update(**self._filter_fields(value)) is None:
raise SyntaxError('No such record: %s' % key)
else:
@@ -642,8 +642,7 @@ class Table(Serializable, BasicStorage):
query = self._build_query(key)
if not self._db(query).delete():
raise SyntaxError('No such record: %s' % key)
- elif not str(key).isdigit() or \
- not self._db(self._id == key).delete():
+ elif not str(key).isdigit() or not self._db(self._id == key).delete():
raise SyntaxError('No such record: %s' % key)
def __iter__(self):
