Skip to content

Instantly share code, notes, and snippets.

@motorro
Created March 12, 2020 16:23
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/0f020bd11923e7442bee805ca09d43b9 to your computer and use it in GitHub Desktop.
Save motorro/0f020bd11923e7442bee805ca09d43b9 to your computer and use it in GitHub Desktop.
Cities database creation script
/**
* 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