I have cities
table and trying to insert city, upon database creation. The table structure is pretty simple, it has just id
and name
column.
In onCreate
method of my database class, I create table with this command:
var tblCities = 'cities';
await db.execute('CREATE TABLE $tblCities (id INTEGER PRIMARY KEY, name TEXT)');
I have Cities
model class with fromMap
and toMap
methods.
There are about 350 cities, and I wanted to insert them in the table.
Q. What is the best and easy way to do that?
This comes in my mind:
- creating list of city
- using
for
loop to iterate entire list - creating map of the city using
toMap
method - calling
db.insert
method inside the loop
I'm not sure, but this seem dumb approach so thinking about better and optimized solution...