utils/sqlite_extract_data.js
function findSubdivisions( filename ){

  // load configuration variables
  const config = require('pelias-config').generate(require('../schema')).imports.whosonfirst;
  const sqliteDir = path.join(config.datapath, 'sqlite');
  let targetWofIds = Array.isArray(config.importPlace) ? config.importPlace: [config.importPlace];

  // connect to sql db
  let db = new Sqlite3( path.join( sqliteDir, filename ), { readonly: true } );

  // convert ids to integers and remove any which fail to convert
  let cleanIds = targetWofIds.map(id => parseInt(id, 10)).filter(id => !isNaN(id));

  // placefilter is used to select only records targeted by the 'importPlace' config option
  // note: if no 'importPlace' ids are provided then we process all ids which aren't 0
  let placefilter = (cleanIds.length > 0) ? sql.placefilter : '!= 0';

  // query db
  // note: we need to use replace instead of using bound params in order to
  // be able to query an array of values using IN.
  let query = sql.subdiv.replace(/@placefilter/g, placefilter).replace(/@wofids/g, cleanIds.join(','));
  return db.prepare(query).all().map( row => row.subdivision.toLowerCase());
}
function findSubdivisions( filename ){

  // load configuration variables
  const config = require('pelias-config').generate(require('../schema')).imports.whosonfirst;
  const sqliteDir = path.join(config.datapath, 'sqlite');
  let targetWofIds = Array.isArray(config.importPlace) ? config.importPlace: [config.importPlace];

  // connect to sql db
  let db = new Sqlite3( path.join( sqliteDir, filename ), { readonly: true } );

  // convert ids to integers and remove any which fail to convert
  let cleanIds = targetWofIds.map(id => parseInt(id, 10)).filter(id => !isNaN(id));

  // placefilter is used to select only records targeted by the 'importPlace' config option
  // note: if no 'importPlace' ids are provided then we process all ids which aren't 0
  let placefilter = (cleanIds.length > 0) ? sql.placefilter : '!= 0';

  // query db
  // note: we need to use replace instead of using bound params in order to
  // be able to query an array of values using IN.
  let query = sql.subdiv.replace(/@placefilter/g, placefilter).replace(/@wofids/g, cleanIds.join(','));
  return db.prepare(query).all().map( row => row.subdivision.toLowerCase());
}
function findSubdivisions ( filename ) { // load configuration variables const config = require ( 'pelias-config' ) . generate ( require ( '../schema' ) ) . imports . whosonfirst ; const sqliteDir = path . join ( config . datapath , 'sqlite' ) ; let targetWofIds = Array . isArray ( config . importPlace ) ? config . importPlace : [ config . importPlace ] ; // connect to sql db let db = new Sqlite3 ( path . join ( sqliteDir , filename ) , { readonly : true } ) ; // convert ids to integers and remove any which fail to convert let cleanIds = targetWofIds . map ( id => parseInt ( id , 10 ) ) . filter ( id => ! isNaN ( id ) ) ; // placefilter is used to select only records targeted by the 'importPlace' config option // note: if no 'importPlace' ids are provided then we process all ids which aren't 0 let placefilter = ( cleanIds . length > 0 ) ? sql . placefilter : '!= 0' ; // query db // note: we need to use replace instead of using bound params in order to // be able to query an array of values using IN. let query = sql . subdiv . replace ( / @placefilter / g , placefilter ) . replace ( / @wofids / g , cleanIds . join ( ',' ) ) ; return db . prepare ( query ) . all ( ) . map ( row => row . subdivision . toLowerCase ( ) ) ; }
return all distinct subdivisions of the data
return all distinct subdivisions of the data