Created
March 12, 2020 16:23
-
-
Save motorro/0f020bd11923e7442bee805ca09d43b9 to your computer and use it in GitHub Desktop.
Cities database creation script
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
/** | |
* Takes cities source files and populates SQLite database | |
* @param schemaPath Where the Room schemas are put | |
* @param dataDir Where the data is put | |
* @return A promise for created database | |
*/ | |
export async function cities(schemaPath: string, dataDir: string): Promise<string> { | |
const schemaFile = await findLatestSchema(schemaPath); | |
const timeStarted = Date.now(); | |
const name: string = Guid.create().toString(); | |
const path = Path.join(os.tmpdir(), `${name}.db`); | |
const db = new Database(path); | |
await populate( | |
Path.join(schemaPath, schemaFile), | |
db, | |
async function(this: Database): Promise<void> { | |
await citiesDb.populate( | |
db, | |
await readJsonData<Array<City>>(Path.join(dataDir, FILE_CITIES)) | |
); | |
} | |
); | |
db.close(); | |
console.log("Total time: ", duration(Date.now() - timeStarted).humanize()); | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment