insert returns last_id (closes #4)
This commit is contained in:
parent
393a0b887b
commit
875e0508f2
@ -66,7 +66,8 @@ class Table(object):
|
||||
self._check_dropped()
|
||||
if ensure:
|
||||
self._ensure_columns(row, types=types)
|
||||
self.database.engine.execute(self.table.insert(row))
|
||||
res = self.database.engine.execute(self.table.insert(row))
|
||||
return res.lastrowid
|
||||
|
||||
def insert_many(self, rows, chunk_size=1000, ensure=True, types={}):
|
||||
"""
|
||||
|
||||
@ -42,12 +42,13 @@ class TableTestCase(unittest.TestCase):
|
||||
|
||||
def test_insert(self):
|
||||
assert len(self.tbl) == len(TEST_DATA), len(self.tbl)
|
||||
self.tbl.insert({
|
||||
last_id = self.tbl.insert({
|
||||
'date': datetime(2011, 01, 02),
|
||||
'temperature': -10,
|
||||
'place': 'Berlin'}
|
||||
)
|
||||
assert len(self.tbl) == len(TEST_DATA)+1, len(self.tbl)
|
||||
assert self.tbl.find_one(id=last_id)['place'] == 'Berlin'
|
||||
|
||||
def test_upsert(self):
|
||||
self.tbl.upsert({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user