text-to-map 1.1.4 → 1.1.5

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/db/db.d.ts CHANGED
@@ -21,7 +21,7 @@ export declare const nonEmptyOrNull: (value: string) => string | null;
21
21
  * Efficiently insert multiple rows. If preventDuplicatesByFirstColumn is true, the first
22
22
  * column should be unique (PK or UNIQUE).
23
23
  */
24
- export declare const insertMultipleRows: (rows: string[][], table: string, columnNames: string[], preventDuplicatesByFirstColumn?: boolean) => Promise<number>;
24
+ export declare const insertMultipleRows: (rows: string[][], table: string, columnNames: string[], preventDuplicates?: boolean, keyColumns?: string[]) => Promise<number>;
25
25
  /**
26
26
  * Insert a single row and return the autoincremented ID.
27
27
  */
package/dist/db/db.js CHANGED
@@ -39,6 +39,12 @@ export const getKnexDb = (config = {}) => {
39
39
  connection: {
40
40
  filename: _knexDbConfig.filePath,
41
41
  },
42
+ pool: {
43
+ afterCreate: (db, done) => {
44
+ db.pragma('journal_mode = WAL;');
45
+ done(false, done);
46
+ },
47
+ },
42
48
  useNullAsDefault: true,
43
49
  debug: _knexDbConfig.verbose,
44
50
  });
@@ -109,7 +115,7 @@ export const nonEmptyOrNull = (value) => {
109
115
  * Efficiently insert multiple rows. If preventDuplicatesByFirstColumn is true, the first
110
116
  * column should be unique (PK or UNIQUE).
111
117
  */
112
- export const insertMultipleRows = (rows, table, columnNames, preventDuplicatesByFirstColumn = true) => __awaiter(void 0, void 0, void 0, function* () {
118
+ export const insertMultipleRows = (rows, table, columnNames, preventDuplicates = true, keyColumns = []) => __awaiter(void 0, void 0, void 0, function* () {
113
119
  if (rows.length === 0) {
114
120
  return 0;
115
121
  }
@@ -120,8 +126,11 @@ export const insertMultipleRows = (rows, table, columnNames, preventDuplicatesBy
120
126
  // }
121
127
  // }
122
128
  const insertPlaceholders = generate2DPlaceholders(columnNames.length, rows.length);
123
- const onConfict = preventDuplicatesByFirstColumn
124
- ? `ON CONFLICT (${columnNames[0]}) DO NOTHING`
129
+ if (preventDuplicates && keyColumns.length === 0) {
130
+ keyColumns = [columnNames[0]];
131
+ }
132
+ const onConfict = preventDuplicates
133
+ ? `ON CONFLICT (${keyColumns.join(", ")}) DO NOTHING`
125
134
  : "";
126
135
  yield getKnexDb().raw(`INSERT INTO ${table} (${columnNames.join(",")}) VALUES ${insertPlaceholders} ${onConfict}`, rows.flat());
127
136
  return rows.length;
@@ -85,7 +85,7 @@ export const insertFounders = (founders) => __awaiter(void 0, void 0, void 0, fu
85
85
  });
86
86
  }
87
87
  }
88
- const insertedConnections = yield insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"]);
88
+ const insertedConnections = yield insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"], true, ["school_izo", "founder_id"]);
89
89
  return insertedFounders + insertedConnections;
90
90
  });
91
91
  const getCityOfSchool = (izo) => __awaiter(void 0, void 0, void 0, function* () {
@@ -126,6 +126,7 @@ export function up(knex) {
126
126
  .references("id")
127
127
  .inTable("founder")
128
128
  .notNullable();
129
+ table_13.unique(["school_izo", "founder_id"]);
129
130
  });
130
131
  yield knex.schema.createTable("address_point", function (table) {
131
132
  table.increments("id");
@@ -38,7 +38,7 @@ export const insertSchools = (schools) => __awaiter(void 0, void 0, void 0, func
38
38
  // plus filter out duplicate locations (same address id + izo)
39
39
  for (const location of locations) {
40
40
  try {
41
- insertedLocations += yield insertMultipleRows([location], "school_location", ["school_izo", "address_point_id"], false);
41
+ insertedLocations += yield insertMultipleRows([location], "school_location", ["school_izo", "address_point_id"], true, ["school_izo", "address_point_id"]);
42
42
  }
43
43
  catch (error) {
44
44
  console.log(`Cannot add location with RUIAN code ${location[1]} (school IZO = ${location[0]}): code does not exist.`);
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "name": "text-to-map",
55
55
  "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.",
56
- "version": "1.1.4",
56
+ "version": "1.1.5",
57
57
  "main": "dist/index.js",
58
58
  "types": "dist/index.d.ts",
59
59
  "files": [