Skip to content

Instantly share code, notes, and snippets.

@motorro
Created March 13, 2020 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motorro/39e506f45100b762052f8595241b0483 to your computer and use it in GitHub Desktop.
Save motorro/39e506f45100b762052f8595241b0483 to your computer and use it in GitHub Desktop.
Populating function
/**
* Populates Cities
*/
async function populateCities(db: Database, cities: Array<City>) {
db.serialize();
db.run("begin transaction");
const stmt = db.prepare("REPLACE INTO cities VALUES (?,?,?,?,?,?)");
for (const city of cities) {
stmt.run(
[
city.id,
city.name,
city.state.length > 0 ? city.state : null,
city.country,
city.coord.lat,
city.coord.lon
]
);
}
stmt.finalize();
db.run("commit");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment