utils/sqlite_extract_data.js
function extractDB( dbpath ){
    let targetWofIds = Array.isArray(config.importPlace) ? config.importPlace: [config.importPlace];

    // connect to sql db
    let db = new Sqlite3( dbpath, { 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';

    // note: we need to use replace instead of bound params in order to be able
    // to query an array of values using IN.
    let dataQuery = sql.data.replace(/@placefilter/g, placefilter).replace(/@wofids/g, cleanIds.join(','));
    let metaQuery = sql.meta.replace(/@placefilter/g, placefilter).replace(/@wofids/g, cleanIds.join(','));

    // extract all data to disk
    for( let row of db.prepare(dataQuery).iterate() ){
      if( 'postalcode' === row.placetype && true !== config.importPostalcodes ){ return; }
      if( 'venue' === row.placetype && true !== config.importVenues ){ return; }
      if( 'constituency' === row.placetype && true !== config.importConstituencies ){ return; }
      if( 'intersection' === row.placetype && true !== config.importIntersections ){ return; }
      writeJson( row );
    }

    // write meta data to disk
    for( let row of db.prepare(metaQuery).iterate() ){
      if( 'postalcode' === row.placetype && true !== config.importPostalcodes ){ return; }
      if( 'venue' === row.placetype && true !== config.importVenues ){ return; }
      if( 'constituency' === row.placetype && true !== config.importConstituencies ){ return; }
      if( 'intersection' === row.placetype && true !== config.importIntersections ){ return; }
      if( !row.hasOwnProperty('path') ){
        // ensure path property is present (required by some importers)
        row.path = wofIdToPath(row.id).concat(row.id+'.geojson').join(path.sep);
      }
      metafiles.write( row );
    }

    // close connection
    db.close();
  }
function extractDB( dbpath ){
    let targetWofIds = Array.isArray(config.importPlace) ? config.importPlace: [config.importPlace];

    // connect to sql db
    let db = new Sqlite3( dbpath, { 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';

    // note: we need to use replace instead of bound params in order to be able
    // to query an array of values using IN.
    let dataQuery = sql.data.replace(/@placefilter/g, placefilter).replace(/@wofids/g, cleanIds.join(','));
    let metaQuery = sql.meta.replace(/@placefilter/g, placefilter).replace(/@wofids/g, cleanIds.join(','));

    // extract all data to disk
    for( let row of db.prepare(dataQuery).iterate() ){
      if( 'postalcode' === row.placetype && true !== config.importPostalcodes ){ return; }
      if( 'venue' === row.placetype && true !== config.importVenues ){ return; }
      if( 'constituency' === row.placetype && true !== config.importConstituencies ){ return; }
      if( 'intersection' === row.placetype && true !== config.importIntersections ){ return; }
      writeJson( row );
    }

    // write meta data to disk
    for( let row of db.prepare(metaQuery).iterate() ){
      if( 'postalcode' === row.placetype && true !== config.importPostalcodes ){ return; }
      if( 'venue' === row.placetype && true !== config.importVenues ){ return; }
      if( 'constituency' === row.placetype && true !== config.importConstituencies ){ return; }
      if( 'intersection' === row.placetype && true !== config.importIntersections ){ return; }
      if( !row.hasOwnProperty('path') ){
        // ensure path property is present (required by some importers)
        row.path = wofIdToPath(row.id).concat(row.id+'.geojson').join(path.sep);
      }
      metafiles.write( row );
    }

    // close connection
    db.close();
  }
function extractDB ( dbpath ) { let targetWofIds = Array . isArray ( config . importPlace ) ? config . importPlace : [ config . importPlace ] ; // connect to sql db let db = new Sqlite3 ( dbpath , { 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' ; // note: we need to use replace instead of bound params in order to be able // to query an array of values using IN. let dataQuery = sql . data . replace ( / @placefilter / g , placefilter ) . replace ( / @wofids / g , cleanIds . join ( ',' ) ) ; let metaQuery = sql . meta . replace ( / @placefilter / g , placefilter ) . replace ( / @wofids / g , cleanIds . join ( ',' ) ) ; // extract all data to disk for ( let row of db . prepare ( dataQuery ) . iterate ( ) ) { if ( 'postalcode' === row . placetype && true !== config . importPostalcodes ) { return ; } if ( 'venue' === row . placetype && true !== config . importVenues ) { return ; } if ( 'constituency' === row . placetype && true !== config . importConstituencies ) { return ; } if ( 'intersection' === row . placetype && true !== config . importIntersections ) { return ; } writeJson ( row ) ; } // write meta data to disk for ( let row of db . prepare ( metaQuery ) . iterate ( ) ) { if ( 'postalcode' === row . placetype && true !== config . importPostalcodes ) { return ; } if ( 'venue' === row . placetype && true !== config . importVenues ) { return ; } if ( 'constituency' === row . placetype && true !== config . importConstituencies ) { return ; } if ( 'intersection' === row . placetype && true !== config . importIntersections ) { return ; } if ( ! row . hasOwnProperty ( 'path' ) ) { // ensure path property is present (required by some importers) row . path = wofIdToPath ( row . id ) . concat ( row . id + '.geojson' ) . join ( path . sep ) ; } metafiles . write ( row ) ; } // close connection db . close ( ) ; }
extract from a single db file
extract from a single db file