     }
     
     public func load<S: Sequence>(version: Version, quads: S) throws where S.Iterator.Element == Quad {
-        for q in quads {
-            let sid = try assignID(for: q.subject)
-            let pid = try assignID(for: q.predicate)
-            let oid = try assignID(for: q.object)
-            let gid = try assignID(for: q.graph)
-            try db.run(quadsTable.insert(or: .ignore, subjColumn <- sid, predColumn <- pid, objColumn <- oid, graphColumn <- gid))
-        }
-        try db.run(sysTable.insert(or: .replace,
-                                   idColumn <- 0,
-                                   versionColumn <- Int64(version)
-        ))
+        try db.transaction {
+            for q in quads {
+                let sid = try assignID(for: q.subject)
+                let pid = try assignID(for: q.predicate)
+                let oid = try assignID(for: q.object)
+                let gid = try assignID(for: q.graph)
+                try db.run(quadsTable.insert(or: .ignore, subjColumn <- sid, predColumn <- pid, objColumn <- oid, graphColumn <- gid))
+            }
+            try db.run(sysTable.update(versionColumn <- Int64(version)))
+        }
     }
 }
 

// swiftlint:disable:next type_body_length
open class SQLiteQuadStore: Sequence, MutableQuadStoreProtocol {
    typealias TermID = Int64
    let sysTable = SQLite.Table("kineo_sys")
    let versionColumn = Expression<Int64>("version")

    let quadsTable = SQLite.Table("quads")
    let subjColumn = Expression<Int64>("subject")


        try db.run(sysTable.insert(or: .replace,
            idColumn <- 0,
            schemaVersionColumn <- schemaVersion,
            versionColumn <- 0
        ))

