mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Add VACUUM INTO support to DatabaseWriter
This commit is contained in:
1 parent
e19de4e42e
commit
b28f75c5a2
2 files changed
+39
No files matched your search
@@ -320,6 +320,12 @@ extension DatabaseWriter {
|
||||
try writeWithoutTransaction { try $0.execute(sql: "VACUUM") }
|
||||
}
|
||||
|
||||
public func vacuum(into: String) throws {
|
||||
try writeWithoutTransaction {
|
||||
try $0.execute(sql: "VACUUM INTO ?", arguments: [into])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Database Observation
|
||||
|
||||
/// A write-only observation only uses the serialized writer
|
||||
|
||||
@@ -158,6 +158,11 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
try testEraseAndVacuum(writer: makeDatabaseQueue())
|
||||
try testEraseAndVacuum(writer: makeDatabasePool())
|
||||
}
|
||||
|
||||
func testVacuumInto() throws {
|
||||
try testVacuumInto(writer: makeDatabaseQueue())
|
||||
try testVacuumInto(writer: makeDatabasePool())
|
||||
}
|
||||
|
||||
private func testEraseAndVacuum(writer: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
@@ -194,6 +199,34 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private func testVacuumInto(writer: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("init") { db in
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t1 (id INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
|
||||
INSERT INTO t1 (b, c) VALUES (1, 1);
|
||||
INSERT INTO t1 (b, c) VALUES (2, 2);
|
||||
""")
|
||||
}
|
||||
|
||||
try migrator.migrate(writer)
|
||||
|
||||
try writer.read { db in
|
||||
try XCTAssertTrue(db.tableExists("t1"))
|
||||
XCTAssertEqual(try (Row.fetchOne(db, sql: "SELECT count(*) from t1")![0] as! Int64), 2)
|
||||
}
|
||||
|
||||
let intoPath = NSTemporaryDirectory().appending(ProcessInfo.processInfo.globallyUniqueString).appending("-vacuum-into-db.sqlite")
|
||||
try writer.vacuum(into: intoPath)
|
||||
|
||||
// open newly created file and ensure table was copied
|
||||
let newWriter = try DatabaseQueue(path: intoPath)
|
||||
try newWriter.read { db in
|
||||
try XCTAssertTrue(db.tableExists("t1"))
|
||||
XCTAssertEqual(try (Row.fetchOne(db, sql: "SELECT count(*) from t1")![0] as! Int64), 2)
|
||||
}
|
||||
}
|
||||
|
||||
// See https://github.com/groue/GRDB.swift/issues/424
|
||||
func testIssue424() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
Reference in new issue
Block a user