     verbose = true
 }
 
-guard let filename = args.next() else { fatalError("Missing filename") }
 let startTime = getCurrentTime()
 let startSecond = getCurrentDateSeconds()
 var count = 0
 
-if let op = args.next() {
-    if op == "sqlite" {
-        do {
-            let subop = args.next() ?? "serialize"
-            let qs : SQLiteQuadStore
-            if subop == "init" {
-                qs = try SQLiteQuadStore(filename: filename, initialize: true)
-            } else {
-                qs = try SQLiteQuadStore(filename: filename)
-            }
-
-            if subop == "load" {
-                guard let rdfFilename = args.next() else {
-                    warn("Missing RDF filename")
-                    exit(1)
-                }
-                #if os (OSX)
-                guard let path = NSURL(fileURLWithPath: rdfFilename).absoluteString else { throw DatabaseError.DataError("Not a valid graph path: \(rdfFilename)") }
-                #else
-                let path = NSURL(fileURLWithPath: rdfFilename).absoluteString
-                #endif
-                let graph   = Term(value: path, type: .iri)
-                
-                let parser = RDFParserCombined()
-                var quads = [Quad]()
-                print("Parsing RDF...")
-                count = try parser.parse(file: rdfFilename, base: graph.value) { (s, p, o) in
-                    let q = Quad(subject: s, predicate: p, object: o, graph: graph)
-                    quads.append(q)
-                }
-                
-                print("Loading RDF...")
-                let v = try qs.effectiveVersion() ?? 0
-                try qs.load(version: v+1, quads: quads)
-            } else if subop == "query" {
-                guard let sparql = args.next() else {
-                    warn("Missing SPARQL")
-                    exit(1)
-                }
-                guard var p = SPARQLParser(data: sparql.data(using: .utf8)!) else { fatalError("Failed to construct SPARQL parser") }
-                let q = try p.parseQuery()
-                let defaultGraph = qs.graphs().next() ?? Term(iri: "tag:kasei.us,2018:default-graph")
-                let dataset = qs.dataset(withDefault: defaultGraph)
-                let e = SimpleQueryEvaluator(store: qs, dataset: dataset)
-                let r = try e.evaluate(query: q)
-                _ = printResult(r)
-            } else {
-                for q in qs {
-                    print("\(q)")
-                }
-            }
-        } catch {
-            print(error)
-        }
-    } else {
-        guard let database = FilePageDatabase(filename, size: pageSize) else { warn("Failed to open \(filename)"); exit(1) }
-        try setup(database, version: Version(startSecond))
+do {
+    try config.withStore { (qs) throws in
+        if case let .loadFiles(defaultFiles, namedFiles) = config.initialize {
+            if let mqs = qs as? SQLiteQuadStore {
+                count += try parse(into: mqs, files: defaultFiles, version: startSecond, graph: nil)
+                try namedFiles.forEach { (graph, file) throws in
+                    count += try parse(into: mqs, files: [file], version: startSecond, graph: graph)
+                }
+            } else if let mqs = qs as? SQLiteLanguageQuadStore {
+                count += try parse(into: mqs, files: defaultFiles, version: startSecond, graph: nil)
+                try namedFiles.forEach { (graph, file) throws in
+                    count += try parse(into: mqs, files: [file], version: startSecond, graph: graph)
+                }
+            } else if let mqs = qs as? MemoryQuadStore {
+                count += try parse(into: mqs, files: defaultFiles, version: startSecond, graph: nil)
+                try namedFiles.forEach { (graph, file) throws in
+                    count += try parse(into: mqs, files: [file], version: startSecond, graph: graph)
+                }
+            } else if let mqs = qs as? LanguageMemoryQuadStore {
+                count += try parse(into: mqs, files: defaultFiles, version: startSecond, graph: nil)
+                try namedFiles.forEach { (graph, file) throws in
+                    count += try parse(into: mqs, files: [file], version: startSecond, graph: graph)
+                }
+            } else if let mqs = qs as? PageQuadStore<FilePageDatabase> {
+                count += try parse(into: mqs, files: defaultFiles, version: startSecond, graph: nil)
+                try namedFiles.forEach { (graph, file) throws in
+                    count += try parse(into: mqs, files: [file], version: startSecond, graph: graph)
+                }
+            } else if let mqs = qs as? LanguagePageQuadStore<FilePageDatabase> {
+                count += try parse(into: mqs, files: defaultFiles, version: startSecond, graph: nil)
+                try namedFiles.forEach { (graph, file) throws in
+                    count += try parse(into: mqs, files: [file], version: startSecond, graph: graph)
+                }
+            }
+        }
+
+        guard let op = args.next() else {
+            for q in try qs.quads(matching: QuadPattern.all) {
+                print("\(q)")
+            }
+            return
+        }
+        
         if op == "load" {
-            do {
-                var graph: Term? = nil
-                if let next = args.peek(), next == "-g" {
-                    _ = args.next()
-                    guard let iri = args.next() else { fatalError("No IRI value given after -g") }
-                    graph = Term(value: iri, type: .iri)
-                }
-                
-                count = try parse(database, files: args.elements(), startTime: startSecond, graph: graph)
-            } catch let e {
-                warn("*** Failed to load data: \(e)")
-            }
-        } else if op == "terms" {
-            count = try printTerms(from: database)
         } else if op == "graphs" {
-            count = try printGraphs(from: database)
-        } else if op == "indexes" {
-            count = try printIndexes(from: database)
+            count = try printGraphs(in: qs)
         } else if op == "explain" {
             var graph: Term? = nil
             if let next = args.peek(), next == "-g" {

    return (count, mapping)
}

/**
 Parse the supplied RDF files and load the resulting RDF triples into the database's
 QuadStore in the supplied named graph (or into a graph named with the corresponding
 filename, if no graph name is given).
 
 - parameter files: Filenames of Turtle or N-Triples files to parse.
 - parameter startTime: The timestamp to use as the database transaction version number.
 - parameter graph: The graph into which parsed triples should be load.
 */
func parse<D : PageDatabase>(_ database: D, files: [String], startTime: UInt64, graph defaultGraphTerm: Term? = nil) throws -> Int {
    var count   = 0
    let version = Version(startTime)
    try database.update(version: version) { (m) in
        do {
            for filename in files {
                #if os (OSX)
                guard let path = NSURL(fileURLWithPath: filename).absoluteString else { throw DatabaseError.DataError("Not a valid graph path: \(filename)") }
                #else
                let path = NSURL(fileURLWithPath: filename).absoluteString
                #endif
                let graph   = defaultGraphTerm ?? Term(value: path, type: .iri)
                
                let parser = RDFParserCombined()
                var quads = [Quad]()
                print("Parsing RDF...")
                count = try parser.parse(file: filename, base: graph.value) { (s, p, o) in
                    let q = Quad(subject: s, predicate: p, object: o, graph: graph)
                    quads.append(q)
                }
                
                print("Loading RDF...")
                let store = try MediatedPageQuadStore.create(mediator: m)
                try store.load(quads: quads)
            }
        } catch let e {
            warn("*** Failed during load of RDF (\(count) triples handled); \(e)")
            throw DatabaseUpdateError.rollback
        }
    }
    return count
}


        let path = NSURL(fileURLWithPath: filename).absoluteString
        #endif
        let graph   = defaultGraphTerm ?? Term(value: path, type: .iri)

        iris.insert(graph)

        let parser = RDFParserCombined()
        count = try parser.parse(file: filename, base: graph.value) { (s, p, o) in
            for term in [s, p, o] {
