I am trying to do bulk insertion using SQLite Swift. However, I am not 100% sure if my code is correct.
The Swift code I installed (because it provided the best performance on time):
do { try DB.transaction { () -> Void in for index in 0...num_docs { table.insert(data <- "test", data_num <- index) } } } catch _ { throw DataAccessError.Transaction_Error }
EDIT ----
If I used the following code in swift, the insertion of 10,000 docs would decrease from +/- 12 seconds to 0.8 s. Which sounds too good to be true.
let docsTrans = DB.prepare("INSERT INTO TEST_DB (data, data_num) VALUES (?,?)") do { try DB.transaction(.Deferred) { () -> Void in for index in 0...num_docs { try docsTrans.run("test", index) } } } catch _ { throw DataAccessError.Insert_Error }
source share