support transaction if needed
2 files changed, 27 insertions(+), 0 deletions(-)

M nosqlite.py
M tests.py
M nosqlite.py +14 -0
@@ 46,6 46,8 @@ class Connection(object):
         Terminate the connection to the sqlite database
         """
         if self.db is not None:
+            if self.db.in_transaction:
+                self.db.commit()
             self.db.close()
 
     def __getitem__(self, name):

          
@@ 87,6 89,18 @@ class Collection(object):
         if create:
             self.create()
 
+    def begin(self):
+        if not self.db.in_transaction:
+            self.db.execute('begin')
+
+    def commit(self):
+        if self.db.in_transaction:
+            self.db.commit()
+
+    def rollback(self):
+        if self.db.in_transaction:
+            self.db.rollback()
+
     def clear(self):
         """
         Clears all stored documents in this database. THERE IS NO GOING BACK

          
M tests.py +13 -0
@@ 190,6 190,19 @@ class TestCollection(object):
 
         assert self.collection.delete_one(doc) is None
 
+    def test_insert_bulk_documents_on_a_transaction(self):
+        self.collection.create()
+        self.collection.begin()
+        self.collection.save({'a':1, 'b':'c'})
+        self.collection.save({'a':1, 'b':'a'})
+        self.collection.rollback()
+        assert 0 == self.collection.count({'a':1})
+        self.collection.begin()
+        self.collection.save({'a':1, 'b':'c'})
+        self.collection.save({'a':1, 'b':'a'})
+        self.collection.commit()
+        assert 2 == self.collection.count({'a':1})
+
     def test_create_index(self):
         self.collection.create()
         doc = {'foo':'bar'}