I am working in SQLite3 using DataMapper.
I was populating a table with almost 1.4 million records and it was taking a long time. I found out that inserts in SQLite are inherently slow and can be improved by:
- Setting
pragma Synchronous = OFF
- Doing inserts in bulk by embedding them in
BEGIN..COMMIT
blocks.
There are a lot of ways to do this.
I have been trying to find ways to do the same with DataMapper, but the documentation has not helped so far. I searched the internet and there are ways explained to do the same in other environments but no one has talked about DataMapper in Ruby's context.
My Code so far is :
DataMapper.setup(:default, 'sqlite:///path/to/DataBase.db')
//Definition of Model
File.open(fileName, "r") do |infile|
while (line = infile.gets)
// Populate data in database here
end
end