text-to-map 1.1.1 → 1.1.3
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.
|
@@ -141,7 +141,7 @@ export const checkStreetExists = (streetName, founder) => __awaiter(void 0, void
|
|
|
141
141
|
const cityCode = yield getFounderCityCode(founder);
|
|
142
142
|
const rowList = yield knex.raw(`SELECT name AS street_name
|
|
143
143
|
FROM street
|
|
144
|
-
WHERE city_code = ? AND name = ? ${isSqlite() ? "COLLATE NOCASE" : ""}`, [cityCode, streetName]);
|
|
144
|
+
WHERE city_code = ? AND name = ? ${isSqlite(knex) ? "COLLATE NOCASE" : ""}`, [cityCode, streetName]);
|
|
145
145
|
if (rowList.length > 0) {
|
|
146
146
|
const row = rowList[0];
|
|
147
147
|
if (row.street_name !== streetName) {
|
|
@@ -190,7 +190,7 @@ export const findAddressPoints = (smdLine, municipality) => __awaiter(void 0, vo
|
|
|
190
190
|
: [smdLine.street, municipality.code];
|
|
191
191
|
const streetJoinCondition = isWholeMunicipalitySmdLine(smdLine)
|
|
192
192
|
? "LEFT JOIN street s ON a.street_code = s.code"
|
|
193
|
-
: `JOIN street s ON a.street_code = s.code AND s.name = ? ${isSqlite() ? "COLLATE NOCASE" : ""}`;
|
|
193
|
+
: `JOIN street s ON a.street_code = s.code AND s.name = ? ${isSqlite(knex) ? "COLLATE NOCASE" : ""}`;
|
|
194
194
|
const queryResult = yield knex.raw(`SELECT a.id, s.name AS street_name, o.name AS object_type_name, a.descriptive_number,
|
|
195
195
|
a.orientational_number, a.orientational_number_letter, c.name AS city_name,
|
|
196
196
|
d.name AS district_name, m.name AS municipality_part_name, p.name AS prague_district_name,
|
package/dist/db/db.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare enum SupportedDbType {
|
|
|
11
11
|
postgres = "postgres"
|
|
12
12
|
}
|
|
13
13
|
export declare const getKnexDb: (config?: Partial<DbConfig>) => Knex;
|
|
14
|
-
export declare const isPostgres: () => boolean;
|
|
15
|
-
export declare const isSqlite: () => boolean;
|
|
14
|
+
export declare const isPostgres: (knex: Knex) => boolean;
|
|
15
|
+
export declare const isSqlite: (knex: Knex) => boolean;
|
|
16
16
|
export declare const initDb: (config?: Partial<DbConfig>) => Promise<Knex>;
|
|
17
17
|
export declare const clearDb: (config?: Partial<DbConfig>) => Promise<Knex>;
|
|
18
18
|
export declare const disconnectKnex: () => Promise<void>;
|
package/dist/db/db.js
CHANGED
|
@@ -18,6 +18,10 @@ export var SupportedDbType;
|
|
|
18
18
|
SupportedDbType["sqlite"] = "sqlite";
|
|
19
19
|
SupportedDbType["postgres"] = "postgres";
|
|
20
20
|
})(SupportedDbType || (SupportedDbType = {}));
|
|
21
|
+
const DbClient = {
|
|
22
|
+
[SupportedDbType.sqlite]: "better-sqlite3",
|
|
23
|
+
[SupportedDbType.postgres]: "pg",
|
|
24
|
+
};
|
|
21
25
|
const defaults = {
|
|
22
26
|
dbType: SupportedDbType.sqlite,
|
|
23
27
|
filePath: "address_points.db",
|
|
@@ -31,7 +35,7 @@ export const getKnexDb = (config = {}) => {
|
|
|
31
35
|
_knexDbConfig = Object.assign(Object.assign(Object.assign({}, defaults), getEnvConfig()), config);
|
|
32
36
|
if (_knexDbConfig.dbType === SupportedDbType.sqlite) {
|
|
33
37
|
_knexDb = knex({
|
|
34
|
-
client:
|
|
38
|
+
client: DbClient[SupportedDbType.sqlite],
|
|
35
39
|
connection: {
|
|
36
40
|
filename: _knexDbConfig.filePath,
|
|
37
41
|
},
|
|
@@ -41,7 +45,7 @@ export const getKnexDb = (config = {}) => {
|
|
|
41
45
|
}
|
|
42
46
|
else if (_knexDbConfig.dbType === SupportedDbType.postgres) {
|
|
43
47
|
_knexDb = knex({
|
|
44
|
-
client:
|
|
48
|
+
client: DbClient[SupportedDbType.postgres],
|
|
45
49
|
connection: _knexDbConfig.pgConnectionString,
|
|
46
50
|
useNullAsDefault: true,
|
|
47
51
|
});
|
|
@@ -52,17 +56,11 @@ export const getKnexDb = (config = {}) => {
|
|
|
52
56
|
}
|
|
53
57
|
return _knexDb;
|
|
54
58
|
};
|
|
55
|
-
export const isPostgres = () => {
|
|
56
|
-
return
|
|
57
|
-
};
|
|
58
|
-
export const isSqlite = () => {
|
|
59
|
-
return isDbType(SupportedDbType.sqlite);
|
|
59
|
+
export const isPostgres = (knex) => {
|
|
60
|
+
return knex.client.config.client === DbClient[SupportedDbType.postgres];
|
|
60
61
|
};
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
throw new Error("DB not initialized");
|
|
64
|
-
}
|
|
65
|
-
return _knexDbConfig.dbType === type;
|
|
62
|
+
export const isSqlite = (knex) => {
|
|
63
|
+
return knex.client.config.client === DbClient[SupportedDbType.sqlite];
|
|
66
64
|
};
|
|
67
65
|
const getMigrationConfig = () => {
|
|
68
66
|
return { directory: join(__dirname, "migrations") };
|
|
@@ -122,7 +120,9 @@ export const insertMultipleRows = (rows, table, columnNames, preventDuplicatesBy
|
|
|
122
120
|
// }
|
|
123
121
|
// }
|
|
124
122
|
const insertPlaceholders = generate2DPlaceholders(columnNames.length, rows.length);
|
|
125
|
-
const onConfict = preventDuplicatesByFirstColumn
|
|
123
|
+
const onConfict = preventDuplicatesByFirstColumn
|
|
124
|
+
? `ON CONFLICT (${columnNames[0]}) DO NOTHING`
|
|
125
|
+
: "";
|
|
126
126
|
yield getKnexDb().raw(`INSERT INTO ${table} (${columnNames.join(",")}) VALUES ${insertPlaceholders} ${onConfict}`, rows.flat());
|
|
127
127
|
return rows.length;
|
|
128
128
|
});
|
|
@@ -218,9 +218,9 @@ export function up(knex) {
|
|
|
218
218
|
yield knex.schema.raw("CREATE INDEX municipality_part_code ON address_point (municipality_part_code);");
|
|
219
219
|
yield knex.schema.raw("CREATE INDEX object_type_id ON address_point (object_type_id);");
|
|
220
220
|
yield knex.schema.raw("CREATE INDEX street_code ON address_point (street_code);");
|
|
221
|
-
yield knex.schema.raw(`CREATE INDEX street_name ON street (name${isSqlite() ? " COLLATE NOCASE" : ""});`);
|
|
221
|
+
yield knex.schema.raw(`CREATE INDEX street_name ON street (name${isSqlite(knex) ? " COLLATE NOCASE" : ""});`);
|
|
222
222
|
yield knex.schema.raw("CREATE INDEX street_sync_feed_url ON street_sync (feed_url);");
|
|
223
|
-
if (isPostgres()) {
|
|
223
|
+
if (isPostgres(knex)) {
|
|
224
224
|
yield knex.schema.raw("CREATE EXTENSION IF NOT EXISTS CITEXT");
|
|
225
225
|
yield knex.schema.alterTable("street", (t) => {
|
|
226
226
|
t.specificType("name", "CITEXT").notNullable().alter();
|
package/package.json
CHANGED
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"clean": "rimraf dist",
|
|
47
47
|
"copyfiles": "copyfiles -u 1 src/address_points_init.db dist",
|
|
48
48
|
"build": "npm-run-all clean -p copyfiles build:*",
|
|
49
|
-
"build:types": "tsc --declaration --emitDeclarationOnly --outDir dist",
|
|
49
|
+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir dist -p tsconfig.declarations.json",
|
|
50
50
|
"build:js": "tsc --outDir dist",
|
|
51
51
|
"prepare": "npm run build"
|
|
52
52
|
},
|
|
53
53
|
"name": "text-to-map",
|
|
54
54
|
"description": "Text To Map usiluje o lepší, strojově zpracovatelné využití částí vyhlášek s výčtem ulic a dalších lokací. Jde o rozšiřitelnou sadu konceptů a nástrojů, které zajistí hladký převod výčtu ulic a jejich rozsahů v lidsky srozumitelném jazyce do strojově zpracovatelného, uchopitelného formátu.",
|
|
55
|
-
"version": "1.1.
|
|
55
|
+
"version": "1.1.3",
|
|
56
56
|
"main": "dist/index.js",
|
|
57
57
|
"types": "dist/index.d.ts",
|
|
58
58
|
"files": [
|