Reputation: 1329
I am trying to insert 10000 records and its taking 45 secs
this is my code
println(NSDate.new())
for index in 0...10000{
countrys.insert(name <- "abc")
//println(index)
}
println(NSDate.new())
is this way to do it?
Upvotes: 2
Views: 1641
Reputation: 437592
The issue is that SQLite will have to commit each of the INSERT
statements individually. You should consider using transactions. You can start a transaction with transaction
method (which performs BEGIN TRANSACTION
SQL) and then use commit
to commit them (which performs COMMIT
SQL).
For example:
db.transaction(.Deferred) { txn in
for i in 0 ... 10000 {
if countries.insert(name <- "abc").statement.failed {
return .Rollback
}
}
return .Commit
}
Upvotes: 8