         i2tcache = LRUCache(capacity: 1024)
         t2icache = LRUCache(capacity: 1024)
         if initialize {
+            next = (iri: 0, blank: 0, datatype: 0, language: 0)
             try initializeTables()
+        } else {
+            next = try SQLiteQuadStore.loadMaxIDs(from: db)
         }
     }
     

//        db.trace {
//            print("[TRACE] \($0)")
//        }
        i2tcache = LRUCache(capacity: 1024)
        t2icache = LRUCache(capacity: 1024)
        try initializeTables()

        }
    }
    
//    internal func term(for id: TermID) -> Term? {
//        if let t = i2tcache[id] {
//            return t
//        }
//
//        let query = termsTable.select(termsTable[*]).filter(idColumn == id)
//        do {
//            guard let row = try db.pluck(query) else {
//                return nil
//            }
//            guard let t = term(from: row, typeColumn: termTypeColumn, valueColumn: termValueColumn, languageColumn: termLangColumn, datatypeColumn: termDatatypeColumn) else {
//                return nil
//            }
//            i2tcache[id] = t
//            return t
//        } catch {}
//        return nil
//    }
    
    public func makeIterator() -> AnyIterator<Quad> {
        let query = quadsTable.select(quadsTable[*])
