Created
March 13, 2020 10:52
-
-
Save motorro/39e506f45100b762052f8595241b0483 to your computer and use it in GitHub Desktop.
Populating function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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