Skip to content

Commit

Permalink
feat(sqlite): add filter to remove alt-geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink authored and orangejulius committed Apr 23, 2020
1 parent 6ba6c1e commit f8b6479
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/components/sqliteStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class SQLiteStream extends Readable {
*/
function findGeoJSON() {
return `
SELECT geojson.id, geojson.body
FROM geojson JOIN spr
ON geojson.id = spr.id
SELECT geojson.id, geojson.body
FROM geojson
JOIN spr ON geojson.id = spr.id
WHERE geojson.id != 1
AND geojson.is_alt != 1
AND spr.is_deprecated = 0
AND spr.is_superseded = 0
AND NOT TRIM( IFNULL(spr.name, '') ) = ''
Expand Down
10 changes: 9 additions & 1 deletion test/components/sqliteStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ tape('SQLiteStream', (test) => {
'Should format correctly array of strings');
t.end();
});
});

test.test('Should ignore alt geometries', t => {
const msg = 'Should ignore alt geometries';
t.ok(SQLiteStream.findGeoJSON().includes('geojson.is_alt != 1'), msg);
t.ok(SQLiteStream.findGeoJSONByPlacetype().includes('geojson.is_alt != 1'), msg);
t.ok(SQLiteStream.findGeoJSONByPlacetypeAndWOFId().includes('geojson.is_alt != 1'), msg);
t.end();
});
});
4 changes: 1 addition & 3 deletions test/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const readStreamModule = require('../src/readStream');
const hierarchyFinder = require('../src/hierarchyFinder');
const peliasDocGenerators = require('../src/peliasDocGenerators');
const sink = require('through2-sink');
const map_stream = require('through2-map');
const event_stream = require('event-stream');
const temp = require('temp').track();
const generateWOFDB = require('./generateWOFDB');
const path = require('path');
Expand Down Expand Up @@ -57,4 +55,4 @@ tape('functional', function(test) {
});
test.end();

});
});
7 changes: 5 additions & 2 deletions test/generateWOFDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ module.exports = (dbPath, entries) => {
const db = new Sqlite3(dbPath)
.exec(`
CREATE TABLE geojson (
id INTEGER NOT NULL PRIMARY KEY,
id INTEGER NOT NULL,
body TEXT,
source TEXT,
is_alt BOOLEAN DEFAULT 0,
lastmodified INTEGER
)`)
.exec(`CREATE UNIQUE INDEX IF NOT EXISTS geojson_by_id ON geojson (id, source)`)
.exec(`
CREATE TABLE spr (
id INTEGER NOT NULL PRIMARY KEY,
Expand Down Expand Up @@ -55,4 +58,4 @@ module.exports = (dbPath, entries) => {
});
}
return db;
};
};

0 comments on commit f8b6479

Please sign in to comment.