@hebcal/geo-sqlite 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/geo-sqlite v4.5.0 */
1
+ /*! @hebcal/geo-sqlite v4.6.0 */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -63,10 +63,12 @@ LIMIT 10`;
63
63
  const ZIP_FULLTEXT_COMPLETE_SQL = `SELECT ZipCode
64
64
  FROM ZIPCodes_CityFullText5
65
65
  WHERE ZIPCodes_CityFullText5 MATCH ?
66
+ ORDER BY Population DESC
66
67
  LIMIT 20`;
67
- const GEONAME_COMPLETE_SQL = `SELECT geonameid
68
+ const GEONAME_COMPLETE_SQL = `SELECT geonameid, longname, city, admin1, country
68
69
  FROM geoname_fulltext
69
70
  WHERE geoname_fulltext MATCH ?
71
+ ORDER BY population DESC
70
72
  LIMIT 20`;
71
73
  const stateNames = {
72
74
  'AK': 'Alaska',
@@ -316,6 +318,7 @@ class GeoDb {
316
318
  admin1: res.State,
317
319
  asciiname: res.CityMixedCase,
318
320
  country: 'United States',
321
+ cc: 'US',
319
322
  latitude: res.Latitude,
320
323
  longitude: res.Longitude,
321
324
  timezone: core.Location.getUsaTzid(res.State, res.TimeZone, res.DayLightSaving),
@@ -369,13 +372,15 @@ class GeoDb {
369
372
 
370
373
  const geoMatches = geoRows.map(res => {
371
374
  const loc = this.lookupGeoname(res.geonameid);
372
- const country = this.countryNames.get(loc.getCountryCode()) || '';
373
- const admin1 = loc.admin1 || '';
375
+ const cc = loc.getCountryCode();
376
+ const country = res.country || this.countryNames.get(cc) || '';
377
+ const admin1 = res.admin || loc.admin1 || '';
374
378
  const obj = {
375
379
  id: res.geonameid,
376
- value: loc.name,
380
+ value: res.longname,
377
381
  admin1,
378
382
  country,
383
+ cc,
379
384
  latitude: loc.latitude,
380
385
  longitude: loc.longitude,
381
386
  timezone: loc.getTzid(),
@@ -386,6 +391,10 @@ class GeoDb {
386
391
  obj.population = loc.population;
387
392
  }
388
393
 
394
+ if (res.city !== loc.asciiname) {
395
+ obj.name = res.city;
396
+ }
397
+
389
398
  if (loc.asciiname) {
390
399
  obj.asciiname = loc.asciiname;
391
400
  }
@@ -415,6 +424,7 @@ class GeoDb {
415
424
  admin1: loc.admin1,
416
425
  asciiname: loc.getShortName(),
417
426
  country: 'United States',
427
+ cc: 'US',
418
428
  latitude: loc.latitude,
419
429
  longitude: loc.longitude,
420
430
  timezone: loc.getTzid(),
@@ -426,7 +436,7 @@ class GeoDb {
426
436
  const map = new Map();
427
437
 
428
438
  for (const obj of zipMatches) {
429
- const key = [obj.asciiname, stateNames[obj.admin1], obj.country].join('|');
439
+ const key = [obj.asciiname, stateNames[obj.admin1], obj.cc].join('|');
430
440
 
431
441
  if (!map.has(key)) {
432
442
  map.set(key, obj);
@@ -435,7 +445,7 @@ class GeoDb {
435
445
 
436
446
 
437
447
  for (const obj of geoMatches) {
438
- const key = [obj.asciiname, obj.admin1, obj.country].join('|');
448
+ const key = [obj.asciiname, obj.admin1, obj.cc].join('|');
439
449
  map.set(key, obj);
440
450
  }
441
451
 
@@ -642,17 +652,34 @@ async function buildGeonamesSqlite(opts) {
642
652
  FROM geoname g, admin1 a, country c
643
653
  WHERE g.country = c.ISO
644
654
  AND g.country <> 'US'
655
+ AND g.country <> 'IL'
656
+ AND g.country <> 'GB'
645
657
  AND g.country||'.'||g.admin1 = a.key
646
658
  `, `INSERT INTO geoname_fulltext
647
659
  SELECT g.geonameid,
648
660
  g.asciiname||', '||a.asciiname||', USA',
649
661
  g.population,
650
- g.asciiname,a.asciiname,'USA'
662
+ g.asciiname,a.asciiname,'United States'
651
663
  FROM geoname g, admin1 a
652
664
  WHERE g.country = 'US'
653
665
  AND g.country||'.'||g.admin1 = a.key
654
666
  `, `INSERT INTO geoname_fulltext
655
667
  SELECT g.geonameid,
668
+ g.asciiname||', '||a.asciiname||', UK',
669
+ g.population,
670
+ g.asciiname,a.asciiname,'UK'
671
+ FROM geoname g, admin1 a
672
+ WHERE g.country = 'GB'
673
+ AND g.country||'.'||g.admin1 = a.key
674
+ `, `INSERT INTO geoname_fulltext
675
+ SELECT g.geonameid,
676
+ g.asciiname||', Israel',
677
+ g.population,
678
+ g.asciiname,NULL,'Israel'
679
+ FROM geoname g
680
+ WHERE g.country = 'IL'
681
+ `, `INSERT INTO geoname_fulltext
682
+ SELECT g.geonameid,
656
683
  g.asciiname||', '||c.Country,
657
684
  g.population,
658
685
  g.asciiname,NULL,c.Country
@@ -679,14 +706,13 @@ async function buildGeonamesSqlite(opts) {
679
706
  AND g.geonameid = alt.geonameid
680
707
  `, `INSERT INTO geoname_fulltext
681
708
  SELECT g.geonameid,
682
- alt.name||', '||a1.asciiname||', Israel',
709
+ alt.name||', Israel',
683
710
  g.population,
684
- alt.name,a1.asciiname,'Israel'
685
- FROM geoname g, admin1 a1, altnames alt
711
+ alt.name,NULL,'Israel'
712
+ FROM geoname g, altnames alt
686
713
  WHERE g.country = 'IL'
687
714
  AND alt.isolanguage = 'en'
688
715
  AND g.geonameid = alt.geonameid
689
- AND g.country||'.'||g.admin1 = a1.key
690
716
  `, 'VACUUM');
691
717
  db.close();
692
718
  return Promise.resolve(true);
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/geo-sqlite v4.5.0 */
1
+ /*! @hebcal/geo-sqlite v4.6.0 */
2
2
  import Database from 'better-sqlite3';
3
3
  import { Location, Locale } from '@hebcal/core';
4
4
  import '@hebcal/cities';
@@ -51,10 +51,12 @@ LIMIT 10`;
51
51
  const ZIP_FULLTEXT_COMPLETE_SQL = `SELECT ZipCode
52
52
  FROM ZIPCodes_CityFullText5
53
53
  WHERE ZIPCodes_CityFullText5 MATCH ?
54
+ ORDER BY Population DESC
54
55
  LIMIT 20`;
55
- const GEONAME_COMPLETE_SQL = `SELECT geonameid
56
+ const GEONAME_COMPLETE_SQL = `SELECT geonameid, longname, city, admin1, country
56
57
  FROM geoname_fulltext
57
58
  WHERE geoname_fulltext MATCH ?
59
+ ORDER BY population DESC
58
60
  LIMIT 20`;
59
61
  const stateNames = {
60
62
  'AK': 'Alaska',
@@ -304,6 +306,7 @@ class GeoDb {
304
306
  admin1: res.State,
305
307
  asciiname: res.CityMixedCase,
306
308
  country: 'United States',
309
+ cc: 'US',
307
310
  latitude: res.Latitude,
308
311
  longitude: res.Longitude,
309
312
  timezone: Location.getUsaTzid(res.State, res.TimeZone, res.DayLightSaving),
@@ -357,13 +360,15 @@ class GeoDb {
357
360
 
358
361
  const geoMatches = geoRows.map(res => {
359
362
  const loc = this.lookupGeoname(res.geonameid);
360
- const country = this.countryNames.get(loc.getCountryCode()) || '';
361
- const admin1 = loc.admin1 || '';
363
+ const cc = loc.getCountryCode();
364
+ const country = res.country || this.countryNames.get(cc) || '';
365
+ const admin1 = res.admin || loc.admin1 || '';
362
366
  const obj = {
363
367
  id: res.geonameid,
364
- value: loc.name,
368
+ value: res.longname,
365
369
  admin1,
366
370
  country,
371
+ cc,
367
372
  latitude: loc.latitude,
368
373
  longitude: loc.longitude,
369
374
  timezone: loc.getTzid(),
@@ -374,6 +379,10 @@ class GeoDb {
374
379
  obj.population = loc.population;
375
380
  }
376
381
 
382
+ if (res.city !== loc.asciiname) {
383
+ obj.name = res.city;
384
+ }
385
+
377
386
  if (loc.asciiname) {
378
387
  obj.asciiname = loc.asciiname;
379
388
  }
@@ -403,6 +412,7 @@ class GeoDb {
403
412
  admin1: loc.admin1,
404
413
  asciiname: loc.getShortName(),
405
414
  country: 'United States',
415
+ cc: 'US',
406
416
  latitude: loc.latitude,
407
417
  longitude: loc.longitude,
408
418
  timezone: loc.getTzid(),
@@ -414,7 +424,7 @@ class GeoDb {
414
424
  const map = new Map();
415
425
 
416
426
  for (const obj of zipMatches) {
417
- const key = [obj.asciiname, stateNames[obj.admin1], obj.country].join('|');
427
+ const key = [obj.asciiname, stateNames[obj.admin1], obj.cc].join('|');
418
428
 
419
429
  if (!map.has(key)) {
420
430
  map.set(key, obj);
@@ -423,7 +433,7 @@ class GeoDb {
423
433
 
424
434
 
425
435
  for (const obj of geoMatches) {
426
- const key = [obj.asciiname, obj.admin1, obj.country].join('|');
436
+ const key = [obj.asciiname, obj.admin1, obj.cc].join('|');
427
437
  map.set(key, obj);
428
438
  }
429
439
 
@@ -630,17 +640,34 @@ async function buildGeonamesSqlite(opts) {
630
640
  FROM geoname g, admin1 a, country c
631
641
  WHERE g.country = c.ISO
632
642
  AND g.country <> 'US'
643
+ AND g.country <> 'IL'
644
+ AND g.country <> 'GB'
633
645
  AND g.country||'.'||g.admin1 = a.key
634
646
  `, `INSERT INTO geoname_fulltext
635
647
  SELECT g.geonameid,
636
648
  g.asciiname||', '||a.asciiname||', USA',
637
649
  g.population,
638
- g.asciiname,a.asciiname,'USA'
650
+ g.asciiname,a.asciiname,'United States'
639
651
  FROM geoname g, admin1 a
640
652
  WHERE g.country = 'US'
641
653
  AND g.country||'.'||g.admin1 = a.key
642
654
  `, `INSERT INTO geoname_fulltext
643
655
  SELECT g.geonameid,
656
+ g.asciiname||', '||a.asciiname||', UK',
657
+ g.population,
658
+ g.asciiname,a.asciiname,'UK'
659
+ FROM geoname g, admin1 a
660
+ WHERE g.country = 'GB'
661
+ AND g.country||'.'||g.admin1 = a.key
662
+ `, `INSERT INTO geoname_fulltext
663
+ SELECT g.geonameid,
664
+ g.asciiname||', Israel',
665
+ g.population,
666
+ g.asciiname,NULL,'Israel'
667
+ FROM geoname g
668
+ WHERE g.country = 'IL'
669
+ `, `INSERT INTO geoname_fulltext
670
+ SELECT g.geonameid,
644
671
  g.asciiname||', '||c.Country,
645
672
  g.population,
646
673
  g.asciiname,NULL,c.Country
@@ -667,14 +694,13 @@ async function buildGeonamesSqlite(opts) {
667
694
  AND g.geonameid = alt.geonameid
668
695
  `, `INSERT INTO geoname_fulltext
669
696
  SELECT g.geonameid,
670
- alt.name||', '||a1.asciiname||', Israel',
697
+ alt.name||', Israel',
671
698
  g.population,
672
- alt.name,a1.asciiname,'Israel'
673
- FROM geoname g, admin1 a1, altnames alt
699
+ alt.name,NULL,'Israel'
700
+ FROM geoname g, altnames alt
674
701
  WHERE g.country = 'IL'
675
702
  AND alt.isolanguage = 'en'
676
703
  AND g.geonameid = alt.geonameid
677
- AND g.country||'.'||g.admin1 = a1.key
678
704
  `, 'VACUUM');
679
705
  db.close();
680
706
  return Promise.resolve(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hebcal/geo-sqlite",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "hebcal"
@@ -31,8 +31,8 @@
31
31
  "@hebcal/cities": "^3.1.2",
32
32
  "@hebcal/core": "^3.38.0",
33
33
  "better-sqlite3": "^7.5.3",
34
- "pino": "^7.11.0",
35
- "pino-pretty": "^7.6.1"
34
+ "pino": "^8.0.0",
35
+ "pino-pretty": "^8.0.0"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "rollup -c",
@@ -60,11 +60,11 @@
60
60
  "@rollup/plugin-commonjs": "^22.0.0",
61
61
  "@rollup/plugin-json": "^4.1.0",
62
62
  "@rollup/plugin-node-resolve": "^13.3.0",
63
- "ava": "^4.2.0",
63
+ "ava": "^4.3.0",
64
64
  "eslint": "^8.16.0",
65
65
  "eslint-config-google": "^0.14.0",
66
66
  "jsdoc": "^3.6.10",
67
67
  "jsdoc-to-markdown": "^7.1.1",
68
- "rollup": "^2.75.4"
68
+ "rollup": "^2.75.5"
69
69
  }
70
70
  }