@hebcal/geo-sqlite 4.5.2 → 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.2 */
1
+ /*! @hebcal/geo-sqlite v4.6.0 */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -65,7 +65,7 @@ FROM ZIPCodes_CityFullText5
65
65
  WHERE ZIPCodes_CityFullText5 MATCH ?
66
66
  ORDER BY Population DESC
67
67
  LIMIT 20`;
68
- const GEONAME_COMPLETE_SQL = `SELECT geonameid
68
+ const GEONAME_COMPLETE_SQL = `SELECT geonameid, longname, city, admin1, country
69
69
  FROM geoname_fulltext
70
70
  WHERE geoname_fulltext MATCH ?
71
71
  ORDER BY population DESC
@@ -373,11 +373,11 @@ class GeoDb {
373
373
  const geoMatches = geoRows.map(res => {
374
374
  const loc = this.lookupGeoname(res.geonameid);
375
375
  const cc = loc.getCountryCode();
376
- const country = this.countryNames.get(cc) || '';
377
- const admin1 = loc.admin1 || '';
376
+ const country = res.country || this.countryNames.get(cc) || '';
377
+ const admin1 = res.admin || loc.admin1 || '';
378
378
  const obj = {
379
379
  id: res.geonameid,
380
- value: loc.name,
380
+ value: res.longname,
381
381
  admin1,
382
382
  country,
383
383
  cc,
@@ -391,6 +391,10 @@ class GeoDb {
391
391
  obj.population = loc.population;
392
392
  }
393
393
 
394
+ if (res.city !== loc.asciiname) {
395
+ obj.name = res.city;
396
+ }
397
+
394
398
  if (loc.asciiname) {
395
399
  obj.asciiname = loc.asciiname;
396
400
  }
@@ -432,7 +436,7 @@ class GeoDb {
432
436
  const map = new Map();
433
437
 
434
438
  for (const obj of zipMatches) {
435
- const key = [obj.asciiname, stateNames[obj.admin1], obj.country].join('|');
439
+ const key = [obj.asciiname, stateNames[obj.admin1], obj.cc].join('|');
436
440
 
437
441
  if (!map.has(key)) {
438
442
  map.set(key, obj);
@@ -441,7 +445,7 @@ class GeoDb {
441
445
 
442
446
 
443
447
  for (const obj of geoMatches) {
444
- const key = [obj.asciiname, obj.admin1, obj.country].join('|');
448
+ const key = [obj.asciiname, obj.admin1, obj.cc].join('|');
445
449
  map.set(key, obj);
446
450
  }
447
451
 
@@ -648,17 +652,34 @@ async function buildGeonamesSqlite(opts) {
648
652
  FROM geoname g, admin1 a, country c
649
653
  WHERE g.country = c.ISO
650
654
  AND g.country <> 'US'
655
+ AND g.country <> 'IL'
656
+ AND g.country <> 'GB'
651
657
  AND g.country||'.'||g.admin1 = a.key
652
658
  `, `INSERT INTO geoname_fulltext
653
659
  SELECT g.geonameid,
654
660
  g.asciiname||', '||a.asciiname||', USA',
655
661
  g.population,
656
- g.asciiname,a.asciiname,'USA'
662
+ g.asciiname,a.asciiname,'United States'
657
663
  FROM geoname g, admin1 a
658
664
  WHERE g.country = 'US'
659
665
  AND g.country||'.'||g.admin1 = a.key
660
666
  `, `INSERT INTO geoname_fulltext
661
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,
662
683
  g.asciiname||', '||c.Country,
663
684
  g.population,
664
685
  g.asciiname,NULL,c.Country
@@ -685,14 +706,13 @@ async function buildGeonamesSqlite(opts) {
685
706
  AND g.geonameid = alt.geonameid
686
707
  `, `INSERT INTO geoname_fulltext
687
708
  SELECT g.geonameid,
688
- alt.name||', '||a1.asciiname||', Israel',
709
+ alt.name||', Israel',
689
710
  g.population,
690
- alt.name,a1.asciiname,'Israel'
691
- FROM geoname g, admin1 a1, altnames alt
711
+ alt.name,NULL,'Israel'
712
+ FROM geoname g, altnames alt
692
713
  WHERE g.country = 'IL'
693
714
  AND alt.isolanguage = 'en'
694
715
  AND g.geonameid = alt.geonameid
695
- AND g.country||'.'||g.admin1 = a1.key
696
716
  `, 'VACUUM');
697
717
  db.close();
698
718
  return Promise.resolve(true);
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/geo-sqlite v4.5.2 */
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';
@@ -53,7 +53,7 @@ FROM ZIPCodes_CityFullText5
53
53
  WHERE ZIPCodes_CityFullText5 MATCH ?
54
54
  ORDER BY Population DESC
55
55
  LIMIT 20`;
56
- const GEONAME_COMPLETE_SQL = `SELECT geonameid
56
+ const GEONAME_COMPLETE_SQL = `SELECT geonameid, longname, city, admin1, country
57
57
  FROM geoname_fulltext
58
58
  WHERE geoname_fulltext MATCH ?
59
59
  ORDER BY population DESC
@@ -361,11 +361,11 @@ class GeoDb {
361
361
  const geoMatches = geoRows.map(res => {
362
362
  const loc = this.lookupGeoname(res.geonameid);
363
363
  const cc = loc.getCountryCode();
364
- const country = this.countryNames.get(cc) || '';
365
- const admin1 = loc.admin1 || '';
364
+ const country = res.country || this.countryNames.get(cc) || '';
365
+ const admin1 = res.admin || loc.admin1 || '';
366
366
  const obj = {
367
367
  id: res.geonameid,
368
- value: loc.name,
368
+ value: res.longname,
369
369
  admin1,
370
370
  country,
371
371
  cc,
@@ -379,6 +379,10 @@ class GeoDb {
379
379
  obj.population = loc.population;
380
380
  }
381
381
 
382
+ if (res.city !== loc.asciiname) {
383
+ obj.name = res.city;
384
+ }
385
+
382
386
  if (loc.asciiname) {
383
387
  obj.asciiname = loc.asciiname;
384
388
  }
@@ -420,7 +424,7 @@ class GeoDb {
420
424
  const map = new Map();
421
425
 
422
426
  for (const obj of zipMatches) {
423
- const key = [obj.asciiname, stateNames[obj.admin1], obj.country].join('|');
427
+ const key = [obj.asciiname, stateNames[obj.admin1], obj.cc].join('|');
424
428
 
425
429
  if (!map.has(key)) {
426
430
  map.set(key, obj);
@@ -429,7 +433,7 @@ class GeoDb {
429
433
 
430
434
 
431
435
  for (const obj of geoMatches) {
432
- const key = [obj.asciiname, obj.admin1, obj.country].join('|');
436
+ const key = [obj.asciiname, obj.admin1, obj.cc].join('|');
433
437
  map.set(key, obj);
434
438
  }
435
439
 
@@ -636,17 +640,34 @@ async function buildGeonamesSqlite(opts) {
636
640
  FROM geoname g, admin1 a, country c
637
641
  WHERE g.country = c.ISO
638
642
  AND g.country <> 'US'
643
+ AND g.country <> 'IL'
644
+ AND g.country <> 'GB'
639
645
  AND g.country||'.'||g.admin1 = a.key
640
646
  `, `INSERT INTO geoname_fulltext
641
647
  SELECT g.geonameid,
642
648
  g.asciiname||', '||a.asciiname||', USA',
643
649
  g.population,
644
- g.asciiname,a.asciiname,'USA'
650
+ g.asciiname,a.asciiname,'United States'
645
651
  FROM geoname g, admin1 a
646
652
  WHERE g.country = 'US'
647
653
  AND g.country||'.'||g.admin1 = a.key
648
654
  `, `INSERT INTO geoname_fulltext
649
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,
650
671
  g.asciiname||', '||c.Country,
651
672
  g.population,
652
673
  g.asciiname,NULL,c.Country
@@ -673,14 +694,13 @@ async function buildGeonamesSqlite(opts) {
673
694
  AND g.geonameid = alt.geonameid
674
695
  `, `INSERT INTO geoname_fulltext
675
696
  SELECT g.geonameid,
676
- alt.name||', '||a1.asciiname||', Israel',
697
+ alt.name||', Israel',
677
698
  g.population,
678
- alt.name,a1.asciiname,'Israel'
679
- FROM geoname g, admin1 a1, altnames alt
699
+ alt.name,NULL,'Israel'
700
+ FROM geoname g, altnames alt
680
701
  WHERE g.country = 'IL'
681
702
  AND alt.isolanguage = 'en'
682
703
  AND g.geonameid = alt.geonameid
683
- AND g.country||'.'||g.admin1 = a1.key
684
704
  `, 'VACUUM');
685
705
  db.close();
686
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.2",
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
  }