@nshiab/simple-data-analysis-core 2.0.5 → 2.0.6
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/README.md +118 -12
- package/esm/class/Simple.d.ts +8 -2
- package/esm/class/Simple.d.ts.map +1 -1
- package/esm/class/Simple.js +9 -3
- package/esm/class/SimpleDB.d.ts +72 -1
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +81 -1
- package/esm/class/SimpleTable.d.ts +251 -274
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +248 -325
- package/esm/helpers/LogValue.d.ts +8 -0
- package/esm/helpers/LogValue.d.ts.map +1 -0
- package/esm/helpers/LogValue.js +23 -0
- package/esm/helpers/cacheTableDependencies.d.ts +9 -0
- package/esm/helpers/cacheTableDependencies.d.ts.map +1 -1
- package/esm/helpers/cacheTableDependencies.js +131 -21
- package/esm/helpers/cleanSQL.d.ts +1 -1
- package/esm/helpers/cleanSQL.d.ts.map +1 -1
- package/esm/helpers/cleanSQL.js +268 -23
- package/esm/helpers/flushAllTables.d.ts.map +1 -1
- package/esm/helpers/flushAllTables.js +23 -28
- package/esm/helpers/foldIdentifier.d.ts +3 -0
- package/esm/helpers/foldIdentifier.d.ts.map +1 -0
- package/esm/helpers/foldIdentifier.js +4 -0
- package/esm/helpers/geometryFromJSON.d.ts +3 -0
- package/esm/helpers/geometryFromJSON.d.ts.map +1 -0
- package/esm/helpers/geometryFromJSON.js +4 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.d.ts.map +1 -1
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/logData.d.ts.map +1 -1
- package/esm/helpers/logData.js +45 -44
- package/esm/helpers/makeLogConverter.d.ts +5 -0
- package/esm/helpers/makeLogConverter.d.ts.map +1 -0
- package/esm/helpers/makeLogConverter.js +64 -0
- package/esm/helpers/osmFiles.d.ts.map +1 -1
- package/esm/helpers/parseTypes.d.ts +1 -1
- package/esm/helpers/parseTypes.d.ts.map +1 -1
- package/esm/helpers/parseTypes.js +4 -0
- package/esm/helpers/pendingOps.d.ts +4 -2
- package/esm/helpers/pendingOps.d.ts.map +1 -1
- package/esm/helpers/prepareGeometry.d.ts +3 -0
- package/esm/helpers/prepareGeometry.d.ts.map +1 -0
- package/esm/helpers/prepareGeometry.js +99 -0
- package/esm/helpers/prepareJSON.d.ts +3 -0
- package/esm/helpers/prepareJSON.d.ts.map +1 -0
- package/esm/helpers/prepareJSON.js +50 -0
- package/esm/helpers/printTable.d.ts +5 -4
- package/esm/helpers/printTable.d.ts.map +1 -1
- package/esm/helpers/printTable.js +32 -36
- package/esm/helpers/queryDB.js +1 -1
- package/esm/helpers/queueAsyncBarrier.d.ts +4 -0
- package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/esm/helpers/queueAsyncBarrier.js +4 -0
- package/esm/helpers/queueOp.d.ts.map +1 -1
- package/esm/helpers/queueOp.js +5 -3
- package/esm/helpers/readMutationRows.d.ts +9 -0
- package/esm/helpers/readMutationRows.d.ts.map +1 -0
- package/esm/helpers/readMutationRows.js +94 -0
- package/esm/helpers/referencedTables.d.ts +9 -0
- package/esm/helpers/referencedTables.d.ts.map +1 -0
- package/esm/helpers/referencedTables.js +22 -0
- package/esm/helpers/runQuery.d.ts.map +1 -1
- package/esm/helpers/runQuery.js +11 -13
- package/esm/helpers/scanSQL.d.ts +7 -0
- package/esm/helpers/scanSQL.d.ts.map +1 -0
- package/esm/helpers/scanSQL.js +71 -0
- package/esm/helpers/tableRegistry.d.ts +2 -0
- package/esm/helpers/tableRegistry.d.ts.map +1 -1
- package/esm/helpers/tableRegistry.js +12 -4
- package/esm/helpers/updateColumnsWithJS.d.ts +52 -0
- package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -0
- package/esm/helpers/updateColumnsWithJS.js +139 -0
- package/esm/methods/addColumn.d.ts +1 -1
- package/esm/methods/addColumn.d.ts.map +1 -1
- package/esm/methods/bm25.d.ts.map +1 -1
- package/esm/methods/bm25.js +1 -2
- package/esm/methods/cache.d.ts.map +1 -1
- package/esm/methods/cache.js +4 -6
- package/esm/methods/convert.d.ts +2 -2
- package/esm/methods/convert.d.ts.map +1 -1
- package/esm/methods/convert.js +5 -0
- package/esm/methods/getBottom.d.ts +1 -1
- package/esm/methods/getBottom.d.ts.map +1 -1
- package/esm/methods/getBottom.js +2 -2
- package/esm/methods/getData.d.ts +1 -1
- package/esm/methods/getData.d.ts.map +1 -1
- package/esm/methods/getData.js +2 -2
- package/esm/methods/join.d.ts.map +1 -1
- package/esm/methods/join.js +8 -16
- package/esm/methods/joinGeo.d.ts.map +1 -1
- package/esm/methods/joinGeo.js +10 -19
- package/esm/methods/loadArray.d.ts +1 -1
- package/esm/methods/loadArray.d.ts.map +1 -1
- package/esm/methods/loadArray.js +74 -19
- package/esm/methods/loadData.js +3 -0
- package/esm/methods/log.d.ts +7 -0
- package/esm/methods/log.d.ts.map +1 -0
- package/esm/methods/log.js +58 -0
- package/esm/methods/logBottom.d.ts +5 -0
- package/esm/methods/logBottom.d.ts.map +1 -0
- package/esm/methods/logBottom.js +9 -0
- package/esm/methods/removeTable.d.ts.map +1 -1
- package/esm/methods/removeTable.js +2 -0
- package/esm/methods/removeTables.d.ts.map +1 -1
- package/esm/methods/removeTables.js +7 -0
- package/esm/methods/renameTable.d.ts.map +1 -1
- package/esm/methods/renameTable.js +4 -0
- package/esm/methods/rowToText.js +2 -2
- package/esm/methods/selectTables.d.ts.map +1 -1
- package/esm/methods/selectTables.js +6 -0
- package/esm/methods/setTypes.d.ts +1 -1
- package/esm/methods/setTypes.d.ts.map +1 -1
- package/esm/methods/stream.d.ts.map +1 -1
- package/esm/methods/stream.js +2 -1
- package/esm/methods/updateWithJS.d.ts +1 -3
- package/esm/methods/updateWithJS.d.ts.map +1 -1
- package/esm/methods/updateWithJS.js +123 -37
- package/llm.md +337 -444
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/script/class/Simple.d.ts +8 -2
- package/script/class/Simple.d.ts.map +1 -1
- package/script/class/Simple.js +9 -3
- package/script/class/SimpleDB.d.ts +72 -1
- package/script/class/SimpleDB.d.ts.map +1 -1
- package/script/class/SimpleDB.js +81 -1
- package/script/class/SimpleTable.d.ts +251 -274
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +248 -325
- package/script/helpers/LogValue.d.ts +8 -0
- package/script/helpers/LogValue.d.ts.map +1 -0
- package/script/helpers/LogValue.js +26 -0
- package/script/helpers/cacheTableDependencies.d.ts +9 -0
- package/script/helpers/cacheTableDependencies.d.ts.map +1 -1
- package/script/helpers/cacheTableDependencies.js +170 -20
- package/script/helpers/cleanSQL.d.ts +1 -1
- package/script/helpers/cleanSQL.d.ts.map +1 -1
- package/script/helpers/cleanSQL.js +271 -23
- package/script/helpers/flushAllTables.d.ts.map +1 -1
- package/script/helpers/flushAllTables.js +24 -29
- package/script/helpers/foldIdentifier.d.ts +3 -0
- package/script/helpers/foldIdentifier.d.ts.map +1 -0
- package/script/helpers/foldIdentifier.js +7 -0
- package/script/helpers/geometryFromJSON.d.ts +3 -0
- package/script/helpers/geometryFromJSON.d.ts.map +1 -0
- package/script/helpers/geometryFromJSON.js +7 -0
- package/script/helpers/index.d.ts +1 -0
- package/script/helpers/index.d.ts.map +1 -1
- package/script/helpers/index.js +3 -1
- package/script/helpers/logData.d.ts.map +1 -1
- package/script/helpers/logData.js +45 -44
- package/script/helpers/makeLogConverter.d.ts +5 -0
- package/script/helpers/makeLogConverter.d.ts.map +1 -0
- package/script/helpers/makeLogConverter.js +70 -0
- package/script/helpers/osmFiles.d.ts.map +1 -1
- package/script/helpers/parseTypes.d.ts +1 -1
- package/script/helpers/parseTypes.d.ts.map +1 -1
- package/script/helpers/parseTypes.js +4 -0
- package/script/helpers/pendingOps.d.ts +4 -2
- package/script/helpers/pendingOps.d.ts.map +1 -1
- package/script/helpers/prepareGeometry.d.ts +3 -0
- package/script/helpers/prepareGeometry.d.ts.map +1 -0
- package/script/helpers/prepareGeometry.js +102 -0
- package/script/helpers/prepareJSON.d.ts +3 -0
- package/script/helpers/prepareJSON.d.ts.map +1 -0
- package/script/helpers/prepareJSON.js +53 -0
- package/script/helpers/printTable.d.ts +5 -4
- package/script/helpers/printTable.d.ts.map +1 -1
- package/script/helpers/printTable.js +32 -36
- package/script/helpers/queryDB.js +1 -1
- package/script/helpers/queueAsyncBarrier.d.ts +4 -0
- package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/script/helpers/queueAsyncBarrier.js +4 -0
- package/script/helpers/queueOp.d.ts.map +1 -1
- package/script/helpers/queueOp.js +4 -2
- package/script/helpers/readMutationRows.d.ts +9 -0
- package/script/helpers/readMutationRows.d.ts.map +1 -0
- package/script/helpers/readMutationRows.js +97 -0
- package/script/helpers/referencedTables.d.ts +9 -0
- package/script/helpers/referencedTables.d.ts.map +1 -0
- package/script/helpers/referencedTables.js +28 -0
- package/script/helpers/runQuery.d.ts.map +1 -1
- package/script/helpers/runQuery.js +11 -13
- package/script/helpers/scanSQL.d.ts +7 -0
- package/script/helpers/scanSQL.d.ts.map +1 -0
- package/script/helpers/scanSQL.js +74 -0
- package/script/helpers/tableRegistry.d.ts +2 -0
- package/script/helpers/tableRegistry.d.ts.map +1 -1
- package/script/helpers/tableRegistry.js +16 -4
- package/script/helpers/updateColumnsWithJS.d.ts +52 -0
- package/script/helpers/updateColumnsWithJS.d.ts.map +1 -0
- package/script/helpers/updateColumnsWithJS.js +145 -0
- package/script/methods/addColumn.d.ts +1 -1
- package/script/methods/addColumn.d.ts.map +1 -1
- package/script/methods/bm25.d.ts.map +1 -1
- package/script/methods/bm25.js +1 -2
- package/script/methods/cache.d.ts.map +1 -1
- package/script/methods/cache.js +3 -5
- package/script/methods/convert.d.ts +2 -2
- package/script/methods/convert.d.ts.map +1 -1
- package/script/methods/convert.js +5 -0
- package/script/methods/getBottom.d.ts +1 -1
- package/script/methods/getBottom.d.ts.map +1 -1
- package/script/methods/getBottom.js +2 -2
- package/script/methods/getData.d.ts +1 -1
- package/script/methods/getData.d.ts.map +1 -1
- package/script/methods/getData.js +2 -2
- package/script/methods/join.d.ts.map +1 -1
- package/script/methods/join.js +8 -16
- package/script/methods/joinGeo.d.ts.map +1 -1
- package/script/methods/joinGeo.js +10 -19
- package/script/methods/loadArray.d.ts +1 -1
- package/script/methods/loadArray.d.ts.map +1 -1
- package/script/methods/loadArray.js +74 -19
- package/script/methods/loadData.js +3 -0
- package/script/methods/log.d.ts +7 -0
- package/script/methods/log.d.ts.map +1 -0
- package/script/methods/log.js +64 -0
- package/script/methods/logBottom.d.ts +5 -0
- package/script/methods/logBottom.d.ts.map +1 -0
- package/script/methods/logBottom.js +15 -0
- package/script/methods/removeTable.d.ts.map +1 -1
- package/script/methods/removeTable.js +2 -0
- package/script/methods/removeTables.d.ts.map +1 -1
- package/script/methods/removeTables.js +7 -0
- package/script/methods/renameTable.d.ts.map +1 -1
- package/script/methods/renameTable.js +4 -0
- package/script/methods/rowToText.js +2 -2
- package/script/methods/selectTables.d.ts.map +1 -1
- package/script/methods/selectTables.js +6 -0
- package/script/methods/setTypes.d.ts +1 -1
- package/script/methods/setTypes.d.ts.map +1 -1
- package/script/methods/stream.d.ts.map +1 -1
- package/script/methods/stream.js +2 -1
- package/script/methods/updateWithJS.d.ts +1 -3
- package/script/methods/updateWithJS.d.ts.map +1 -1
- package/script/methods/updateWithJS.js +122 -36
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = updateColumnsWithJS;
|
|
7
|
+
const quoteIdentifier_js_1 = __importDefault(require("./quoteIdentifier.js"));
|
|
8
|
+
const readMutationRows_js_1 = __importDefault(require("./readMutationRows.js"));
|
|
9
|
+
const tableRegistry_js_1 = require("./tableRegistry.js");
|
|
10
|
+
const loadArray_js_1 = require("../methods/loadArray.js");
|
|
11
|
+
/**
|
|
12
|
+
* Generates columns from selected input columns, keeping other SQL values in
|
|
13
|
+
* DuckDB. Call from an asynchronous extension barrier. The callback must return
|
|
14
|
+
* one row per input row in the same order; only the declared output columns are
|
|
15
|
+
* stored. Existing output columns are replaced, with types inferred from the
|
|
16
|
+
* generated values. Generation runs sequentially in bounded batches (1,000 rows
|
|
17
|
+
* by default); callbacks must not depend on receiving the whole table. Non-null
|
|
18
|
+
* output types must agree across batches. All-null batches defer type inference.
|
|
19
|
+
* Only one batch of inputs and outputs is retained by this helper in JavaScript;
|
|
20
|
+
* callers must also bound their own buffering. Reads finish before callbacks or
|
|
21
|
+
* writes use the shared connection. The original table is replaced only after
|
|
22
|
+
* staging succeeds. Empty tables are unchanged and do not invoke the callback;
|
|
23
|
+
* outputs that remain null in every batch use VARCHAR.
|
|
24
|
+
*
|
|
25
|
+
* Untouched geometry columns remain in DuckDB, preserving their values, types
|
|
26
|
+
* and CRS without GeoJSON conversion. Geometry columns cannot be selected as
|
|
27
|
+
* inputs or overwritten as outputs; use updateWithJS() for editable GeoJSON.
|
|
28
|
+
* This SQL-only preservation path accepts any source CRS.
|
|
29
|
+
*
|
|
30
|
+
* @param table - Table to enrich.
|
|
31
|
+
* @param inputColumns - Columns available to the callback.
|
|
32
|
+
* @param outputColumns - Generated columns to add or replace.
|
|
33
|
+
* @param generate - Produces one result per input row, in input order.
|
|
34
|
+
* @param options - Controls the maximum rows read, generated, and staged at once.
|
|
35
|
+
* @returns Resolves after merging the generated columns into the table.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* queueAsyncBarrier(table, {
|
|
39
|
+
* method: "label()",
|
|
40
|
+
* parameters: null,
|
|
41
|
+
* execute: () => updateColumnsWithJS(table, ["name"], ["label"], async (rows) =>
|
|
42
|
+
* rows.map((row) => ({ label: String(row.name).toUpperCase() })),
|
|
43
|
+
* { batchSize: 500 }),
|
|
44
|
+
* });
|
|
45
|
+
* await table.log();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
async function updateColumnsWithJS(table, inputColumns, outputColumns, generate, options = {}) {
|
|
49
|
+
const batchSize = options.batchSize ?? 1000;
|
|
50
|
+
if (!Number.isSafeInteger(batchSize) || batchSize < 1) {
|
|
51
|
+
throw new Error("batchSize must be a positive safe integer.");
|
|
52
|
+
}
|
|
53
|
+
if (inputColumns.length === 0 || outputColumns.length === 0) {
|
|
54
|
+
throw new Error("Input and output columns must not be empty.");
|
|
55
|
+
}
|
|
56
|
+
if (new Set(outputColumns.map((name) => name.toLowerCase())).size !==
|
|
57
|
+
outputColumns.length) {
|
|
58
|
+
throw new Error("Output columns must be unique.");
|
|
59
|
+
}
|
|
60
|
+
const types = await table.getTypes();
|
|
61
|
+
for (const [name, type] of Object.entries(types)) {
|
|
62
|
+
if (type.toUpperCase().startsWith("GEOMETRY") &&
|
|
63
|
+
[...inputColumns, ...outputColumns].some((column) => column.toLowerCase() === name.toLowerCase())) {
|
|
64
|
+
throw new Error(`Geometry column ${JSON.stringify(name)} cannot be an input or output of updateColumnsWithJS(); use updateWithJS() for editable GeoJSON.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const suffix = crypto.randomUUID().replaceAll("-", "");
|
|
68
|
+
const id = `__sda_id_${suffix}`;
|
|
69
|
+
const snapshot = `__sda_source_${suffix}`;
|
|
70
|
+
const staged = table.sdb.newTable(`__sda_generated_${suffix}`);
|
|
71
|
+
const batch = table.sdb.newTable(`__sda_batch_${suffix}`);
|
|
72
|
+
const q = quoteIdentifier_js_1.default;
|
|
73
|
+
try {
|
|
74
|
+
// A SQL snapshot gives every row a stable identity, including duplicate rows
|
|
75
|
+
// and user columns named rowid. No untouched values cross the JS boundary.
|
|
76
|
+
await table.sdb.customQuery(`CREATE TEMP TABLE ${q(snapshot)} AS SELECT *, row_number() OVER () AS ${q(id)} FROM ${q(table.name)}`);
|
|
77
|
+
const knownTypes = new Map();
|
|
78
|
+
let lastId = "0";
|
|
79
|
+
let hasRows = false;
|
|
80
|
+
while (true) {
|
|
81
|
+
const upperId = BigInt(lastId) + BigInt(batchSize);
|
|
82
|
+
const { rows } = await (0, readMutationRows_js_1.default)(table.connection, `SELECT ${q(id)}, ${inputColumns.map(q).join(", ")} FROM ${q(snapshot)} WHERE ${q(id)} > ${lastId} AND ${q(id)} <= ${upperId}
|
|
83
|
+
ORDER BY ${q(id)} LIMIT ${batchSize}`);
|
|
84
|
+
if (rows.length === 0)
|
|
85
|
+
break;
|
|
86
|
+
const ids = rows.map((row) => String(row[id]));
|
|
87
|
+
lastId = ids[ids.length - 1];
|
|
88
|
+
for (const row of rows)
|
|
89
|
+
delete row[id];
|
|
90
|
+
const generated = await generate(rows);
|
|
91
|
+
if (generated.length !== ids.length) {
|
|
92
|
+
throw new Error("Column generation must return one row per input row.");
|
|
93
|
+
}
|
|
94
|
+
// Generated vectors retain this helper's existing inference contract.
|
|
95
|
+
await (0, loadArray_js_1.executePreparedArray)(batch, (0, loadArray_js_1.prepareArray)(generated.map((row, i) => ({
|
|
96
|
+
...Object.fromEntries(outputColumns.map((name) => [name, row[name]])),
|
|
97
|
+
[id]: ids[i],
|
|
98
|
+
}))));
|
|
99
|
+
const batchTypes = await batch.getTypes();
|
|
100
|
+
for (const name of outputColumns) {
|
|
101
|
+
const nonNull = generated.some((row) => row[name] !== null && row[name] !== undefined);
|
|
102
|
+
if (!nonNull)
|
|
103
|
+
continue;
|
|
104
|
+
const previous = knownTypes.get(name);
|
|
105
|
+
const current = batchTypes[name];
|
|
106
|
+
if (previous !== undefined && previous !== current) {
|
|
107
|
+
throw new Error(`Generated column ${JSON.stringify(name)} changed type from ${previous} to ${current}.`);
|
|
108
|
+
}
|
|
109
|
+
if (previous === undefined) {
|
|
110
|
+
knownTypes.set(name, current);
|
|
111
|
+
if (hasRows) {
|
|
112
|
+
await table.sdb.customQuery(`ALTER TABLE ${q(staged.name)} ALTER COLUMN ${q(name)} TYPE ${current} USING NULL`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!hasRows) {
|
|
117
|
+
await table.sdb.customQuery(`CREATE TEMP TABLE ${q(staged.name)} AS SELECT * FROM ${q(batch.name)}`);
|
|
118
|
+
hasRows = true;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
await table.sdb.customQuery(`INSERT INTO ${q(staged.name)} SELECT * FROM ${q(batch.name)}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!hasRows)
|
|
125
|
+
return;
|
|
126
|
+
const outputs = new Map(outputColumns.map((name) => [name.toLowerCase(), name]));
|
|
127
|
+
const columns = Object.keys(types).map((name) => {
|
|
128
|
+
const replacement = outputs.get(name.toLowerCase());
|
|
129
|
+
return replacement === undefined
|
|
130
|
+
? `original.${q(name)}`
|
|
131
|
+
: `generated.${q(replacement)} AS ${q(name)}`;
|
|
132
|
+
});
|
|
133
|
+
const existing = new Set(Object.keys(types).map((name) => name.toLowerCase()));
|
|
134
|
+
for (const name of outputColumns) {
|
|
135
|
+
if (!existing.has(name.toLowerCase())) {
|
|
136
|
+
columns.push(`generated.${q(name)}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
await table.sdb.customQuery(`CREATE OR REPLACE TABLE ${q(table.name)} AS SELECT ${columns.join(", ")} FROM ${q(snapshot)} original JOIN ${q(staged.name)} generated ON original.${q(id)} = CAST(generated.${q(id)} AS BIGINT) ORDER BY original.${q(id)}`);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
await table.sdb.customQuery(`DROP TABLE IF EXISTS ${q(snapshot)}; DROP TABLE IF EXISTS ${q(staged.name)}; DROP TABLE IF EXISTS ${q(batch.name)};`);
|
|
143
|
+
(0, tableRegistry_js_1.retainRegisteredTables)(table.sdb, (item) => item !== staged && item !== batch);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
|
-
export default function addColumn(simpleTable: SimpleTable, newColumn: string, type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | `geometry('${string}')` | `GEOMETRY('${string}')`, definition: string): void;
|
|
2
|
+
export default function addColumn(simpleTable: SimpleTable, newColumn: string, type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`, definition: string): void;
|
|
3
3
|
//# sourceMappingURL=addColumn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addColumn.d.ts","sourceRoot":"","sources":["../../src/methods/addColumn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,IAAI,EACA,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,aAAa,MAAM,IAAI,GACvB,aAAa,MAAM,IAAI,EAC3B,UAAU,EAAE,MAAM,QAuBnB"}
|
|
1
|
+
{"version":3,"file":"addColumn.d.ts","sourceRoot":"","sources":["../../src/methods/addColumn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,IAAI,EACA,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,MAAM,GAAG,GAClB,SAAS,MAAM,GAAG,GAClB,aAAa,MAAM,IAAI,GACvB,aAAa,MAAM,IAAI,EAC3B,UAAU,EAAE,MAAM,QAuBnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../src/methods/bm25.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../src/methods/bm25.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,MAAM,CAAC,OAAO,UAAU,IAAI,CAC1B,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,OAAO,CAAC,EACJ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,OAAO,GACP,WAAW,GACX,YAAY,GACZ,OAAO,GACP,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,OAAO,GACP,SAAS,GACT,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,GACL,WAAW,CA4Bb"}
|
package/script/methods/bm25.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = bm25;
|
|
7
7
|
const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
|
|
8
|
-
const camelCase_js_1 = __importDefault(require("../helpers/camelCase.js"));
|
|
9
8
|
const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
|
|
10
9
|
const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
|
|
11
10
|
const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
|
|
@@ -45,7 +44,7 @@ async function executeBm25(simpleTable, outputTable, text, idColumn, textColumn,
|
|
|
45
44
|
const selectClause = typeof options.scoreColumn === "string"
|
|
46
45
|
? `* EXCLUDE(score), score AS ${(0, quoteIdentifier_js_1.default)(options.scoreColumn)}`
|
|
47
46
|
: `* EXCLUDE(score)`;
|
|
48
|
-
await (0, queryDB_js_1.default)(simpleTable, `CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(outputTable.name)} AS SELECT ${selectClause} FROM (SELECT *, ${(0, quoteIdentifier_js_1.default)(`fts_main_${
|
|
47
|
+
await (0, queryDB_js_1.default)(simpleTable, `CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(outputTable.name)} AS SELECT ${selectClause} FROM (SELECT *, ${(0, quoteIdentifier_js_1.default)(`fts_main_${simpleTable.name}`)}.match_bm25(${(0, quoteIdentifier_js_1.default)(idColumn)}, ?${typeof options.k === "number" ? `, k := ${options.k}` : ""}${typeof options.b === "number" ? `, b := ${options.b}` : ""}${options.conjunctive === true ? `, conjunctive := 1` : ""}) AS score FROM ${(0, quoteIdentifier_js_1.default)(simpleTable.name)}) sq WHERE score NOT NULL${minScoreCondition} ORDER BY score DESC LIMIT ${count};`, (0, mergeOptions_js_1.default)(simpleTable, {
|
|
49
48
|
table: simpleTable.name,
|
|
50
49
|
method: "bm25",
|
|
51
50
|
parameters: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/methods/cache.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/methods/cache.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AA4DvD,wBAA8B,KAAK,CAAC,KAAK,SAAS,WAAW,EAC3D,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC/C,OAAO,GAAE;IACP,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,iBA4LP"}
|
package/script/methods/cache.js
CHANGED
|
@@ -50,6 +50,7 @@ const CACHE_FORMAT_VERSION = "duckdb-v4";
|
|
|
50
50
|
async function cache(table, compute, options = {}) {
|
|
51
51
|
// If cache() is itself called from another cache computation, the outer
|
|
52
52
|
// computation depends on the table produced here.
|
|
53
|
+
(0, cacheTableDependencies_js_1.assertCacheTableMutation)(table);
|
|
53
54
|
(0, cacheTableDependencies_js_1.recordCacheTableAccess)(table);
|
|
54
55
|
options.verbose &&
|
|
55
56
|
console.log(`\ncache() for ${table.name}`);
|
|
@@ -70,12 +71,13 @@ async function cache(table, compute, options = {}) {
|
|
|
70
71
|
const inputs = options.inputs?.filter((input) => input !== table) ?? [];
|
|
71
72
|
const hasInputs = inputs.length > 0;
|
|
72
73
|
const serializedInputs = hasInputs ? (0, serializeCacheInputs_js_1.default)(inputs) : null;
|
|
73
|
-
const codeHash = createHash(functionBody);
|
|
74
|
+
const codeHash = createHash(JSON.stringify([table.sdb.expressionSyntax, functionBody]));
|
|
74
75
|
const inputHashes = hasInputs
|
|
75
76
|
? inputs.map((input) => createHash((0, serializeCacheInputs_js_1.default)([input])))
|
|
76
77
|
: [];
|
|
77
78
|
const hash = createHash(JSON.stringify([
|
|
78
79
|
CACHE_FORMAT_VERSION,
|
|
80
|
+
table.sdb.expressionSyntax,
|
|
79
81
|
table.name,
|
|
80
82
|
entryGeneration,
|
|
81
83
|
functionBody,
|
|
@@ -158,10 +160,6 @@ async function runAndWrite(table, compute, cacheSources, cacheSourcesPath, cache
|
|
|
158
160
|
const start = Date.now();
|
|
159
161
|
const tableDependencies = await (0, cacheTableDependencies_js_1.captureCacheTableDependencies)(table, async () => {
|
|
160
162
|
await compute(table);
|
|
161
|
-
// run() only queues the sync builders in the user's callback; the actual
|
|
162
|
-
// computation happens at the flush, so it must be included in the timing
|
|
163
|
-
// that decides how much the cache saves on later hits.
|
|
164
|
-
await (0, flushAllTables_js_1.default)(table.sdb);
|
|
165
163
|
});
|
|
166
164
|
const end = Date.now();
|
|
167
165
|
const duration = end - start;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
2
|
import type { TableSchema } from "../helpers/pendingOps.js";
|
|
3
3
|
export default function convert(simpleTable: SimpleTable, types: {
|
|
4
|
-
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean"
|
|
4
|
+
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`;
|
|
5
5
|
}, options?: {
|
|
6
6
|
strict?: boolean;
|
|
7
7
|
datetimeFormat?: string;
|
|
8
8
|
}): void;
|
|
9
|
-
export declare function convertSelect(input: string, columns: string[], columnsTypes: ("integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean")[], allColumns: string[], allTypes: TableSchema, options: {
|
|
9
|
+
export declare function convertSelect(input: string, columns: string[], columnsTypes: ("integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`)[], allColumns: string[], allTypes: TableSchema, options: {
|
|
10
10
|
datetimeFormat?: string;
|
|
11
11
|
strict?: boolean;
|
|
12
12
|
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/methods/convert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE;IACL,CAAC,GAAG,EAAE,MAAM,GACR,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/methods/convert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE;IACL,CAAC,GAAG,EAAE,MAAM,GACR,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,MAAM,GAAG,GAClB,SAAS,MAAM,GAAG,GAClB,aAAa,MAAM,IAAI,GACvB,aAAa,MAAM,IAAI,CAAC;CAC7B,EACD,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,QAkDP;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,CACV,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,MAAM,GAAG,GAClB,SAAS,MAAM,GAAG,GAClB,aAAa,MAAM,IAAI,GACvB,aAAa,MAAM,IAAI,CAC1B,EAAE,EACH,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,UAuFvD"}
|
|
@@ -16,6 +16,7 @@ function convert(simpleTable, types, options = {}) {
|
|
|
16
16
|
method: "convert()",
|
|
17
17
|
parameters: { types, options },
|
|
18
18
|
needsSchema: true,
|
|
19
|
+
needsSpatial: Object.values(types).some((type) => type.toLowerCase().startsWith("geometry")),
|
|
19
20
|
outputSchema: (allTypes) => ({
|
|
20
21
|
...allTypes,
|
|
21
22
|
...Object.fromEntries(Object.entries(types).map(([column, type]) => [
|
|
@@ -85,6 +86,10 @@ function convertSelect(input, columns, columnsTypes, allColumns, allTypes, optio
|
|
|
85
86
|
else if (msToTimestamp) {
|
|
86
87
|
query += ` TIMESTAMP '1970-01-01 00:00:00' + to_milliseconds(${(0, quoteIdentifier_js_1.default)(column)}) AS ${(0, quoteIdentifier_js_1.default)(column)},`;
|
|
87
88
|
}
|
|
89
|
+
else if (options.strict === false && expectedType.startsWith("GEOMETRY")) {
|
|
90
|
+
// DuckDB's geometry parser can throw even inside TRY_CAST.
|
|
91
|
+
query += ` TRY(CAST(${(0, quoteIdentifier_js_1.default)(column)} AS ${expectedType})) AS ${(0, quoteIdentifier_js_1.default)(column)},`;
|
|
92
|
+
}
|
|
88
93
|
else if (stringToNumber) {
|
|
89
94
|
// Thousand separators would make the cast fail.
|
|
90
95
|
query += ` ${cast}(REPLACE(${(0, quoteIdentifier_js_1.default)(column)}, ',', '') AS ${(0, parseTypes_js_1.default)(columnsTypes[indexOf])}) AS ${(0, quoteIdentifier_js_1.default)(column)},`;
|
|
@@ -2,7 +2,7 @@ import type SimpleTable from "../class/SimpleTable.js";
|
|
|
2
2
|
export default function getBottom(simpleTable: SimpleTable, count: number, options?: {
|
|
3
3
|
originalOrder?: boolean;
|
|
4
4
|
conditions?: string;
|
|
5
|
-
}): Promise<{
|
|
5
|
+
}, method?: "getBottom()" | "logBottom()"): Promise<{
|
|
6
6
|
[key: string]: unknown;
|
|
7
7
|
}[]>;
|
|
8
8
|
//# sourceMappingURL=getBottom.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBottom.d.ts","sourceRoot":"","sources":["../../src/methods/getBottom.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,SAAS,CACrC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB;;
|
|
1
|
+
{"version":3,"file":"getBottom.d.ts","sourceRoot":"","sources":["../../src/methods/getBottom.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,wBAA8B,SAAS,CACrC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB,EACN,MAAM,GAAE,aAAa,GAAG,aAA6B;;KA6BtD"}
|
|
@@ -7,14 +7,14 @@ exports.default = getBottom;
|
|
|
7
7
|
const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
|
|
8
8
|
const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
|
|
9
9
|
const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
|
|
10
|
-
async function getBottom(simpleTable, count, options = {}) {
|
|
10
|
+
async function getBottom(simpleTable, count, options = {}, method = "getBottom()") {
|
|
11
11
|
const queryResult = await (0, queryDB_js_1.default)(simpleTable, `WITH "numberedRowsForGetBottom" AS (
|
|
12
12
|
SELECT *, row_number() OVER () as "rowNumberForGetBottom" FROM ${(0, quoteIdentifier_js_1.default)(simpleTable.name)}${options.conditions ? ` WHERE ${options.conditions}` : ""}
|
|
13
13
|
)
|
|
14
14
|
SELECT * FROM "numberedRowsForGetBottom" ORDER BY "rowNumberForGetBottom" DESC LIMIT ${count};`, (0, mergeOptions_js_1.default)(simpleTable, {
|
|
15
15
|
table: simpleTable.name,
|
|
16
16
|
returnData: true,
|
|
17
|
-
method
|
|
17
|
+
method,
|
|
18
18
|
parameters: { count, options },
|
|
19
19
|
}));
|
|
20
20
|
if (!queryResult) {
|
|
@@ -3,7 +3,7 @@ export default function getData(simpleTable: SimpleTable, options?: {
|
|
|
3
3
|
columns?: string | string[];
|
|
4
4
|
conditions?: string;
|
|
5
5
|
limit?: number;
|
|
6
|
-
}): Promise<{
|
|
6
|
+
}, method?: "getData()" | "log()"): Promise<{
|
|
7
7
|
[key: string]: unknown;
|
|
8
8
|
}[]>;
|
|
9
9
|
//# sourceMappingURL=getData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../src/methods/getData.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAIvD,wBAA8B,OAAO,CACnC,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX;;
|
|
1
|
+
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../src/methods/getData.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAIvD,wBAA8B,OAAO,CACnC,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX,EACN,MAAM,GAAE,WAAW,GAAG,OAAqB;;KAmC5C"}
|
|
@@ -8,7 +8,7 @@ const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"))
|
|
|
8
8
|
const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
|
|
9
9
|
const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
|
|
10
10
|
const quoteQualifiedIdentifier_js_1 = __importDefault(require("../helpers/quoteQualifiedIdentifier.js"));
|
|
11
|
-
async function getData(simpleTable, options = {}) {
|
|
11
|
+
async function getData(simpleTable, options = {}, method = "getData()") {
|
|
12
12
|
if (options.limit !== undefined &&
|
|
13
13
|
(!Number.isInteger(options.limit) || options.limit < 0)) {
|
|
14
14
|
throw new Error("getData() limit must be an integer greater than or equal to 0.");
|
|
@@ -23,7 +23,7 @@ async function getData(simpleTable, options = {}) {
|
|
|
23
23
|
: "*"} from ${(0, quoteIdentifier_js_1.default)(simpleTable.name)}${options.conditions ? ` WHERE ${options.conditions}` : ""}${options.limit === undefined ? "" : ` LIMIT ${options.limit}`}`, (0, mergeOptions_js_1.default)(simpleTable, {
|
|
24
24
|
returnData: true,
|
|
25
25
|
table: simpleTable.name,
|
|
26
|
-
method
|
|
26
|
+
method,
|
|
27
27
|
parameters: { options },
|
|
28
28
|
})));
|
|
29
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/methods/join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/methods/join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAKvD,MAAM,CAAC,OAAO,UAAU,IAAI,CAC1B,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,GACL,WAAW,CAkBb"}
|
package/script/methods/join.js
CHANGED
|
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = join;
|
|
7
7
|
const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
|
|
8
8
|
const getIdenticalColumns_js_1 = __importDefault(require("../helpers/getIdenticalColumns.js"));
|
|
9
|
-
const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
|
|
10
|
-
const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
|
|
11
9
|
const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
|
|
12
10
|
const assertSameDatabase_js_1 = __importDefault(require("../helpers/assertSameDatabase.js"));
|
|
13
11
|
function join(leftTable, rightTable, options = {}) {
|
|
@@ -19,14 +17,15 @@ function join(leftTable, rightTable, options = {}) {
|
|
|
19
17
|
? leftTable.sdb.newTable(options.outputTable)
|
|
20
18
|
: leftTable;
|
|
21
19
|
(0, queueOp_js_1.default)(outputTable, {
|
|
22
|
-
kind: "
|
|
20
|
+
kind: "source",
|
|
21
|
+
rawSQL: [(0, quoteIdentifier_js_1.default)(leftTable.name), (0, quoteIdentifier_js_1.default)(rightTable.name)],
|
|
23
22
|
method: "join()",
|
|
24
23
|
parameters: { rightTable: rightTable.name, options },
|
|
25
|
-
|
|
24
|
+
buildSelect: () => buildJoinSelect(leftTable, rightTable, options),
|
|
26
25
|
});
|
|
27
26
|
return outputTable;
|
|
28
27
|
}
|
|
29
|
-
async function
|
|
28
|
+
async function buildJoinSelect(leftTable, rightTable, options) {
|
|
30
29
|
const leftTableColumns = await leftTable.getColumns();
|
|
31
30
|
const rightTableColumns = await rightTable.getColumns();
|
|
32
31
|
const identicalColumns = (0, getIdenticalColumns_js_1.default)(leftTableColumns, rightTableColumns);
|
|
@@ -80,17 +79,10 @@ async function executeJoin(leftTable, rightTable, outputTable, options) {
|
|
|
80
79
|
.filter((d) => !on.includes(d))
|
|
81
80
|
.map((d) => `${(0, quoteIdentifier_js_1.default)(rightTable.name)}.${(0, quoteIdentifier_js_1.default)(d)}`),
|
|
82
81
|
].join(", ");
|
|
83
|
-
|
|
84
|
-
table: outputTable.name,
|
|
85
|
-
method: "join()",
|
|
86
|
-
parameters: {
|
|
87
|
-
rightTable: rightTable.name,
|
|
88
|
-
options,
|
|
89
|
-
},
|
|
90
|
-
}));
|
|
82
|
+
return joinQuery(leftTable.name, rightTable.name, on, type, selectList);
|
|
91
83
|
}
|
|
92
|
-
function joinQuery(leftTable, rightTable, on, join,
|
|
93
|
-
let query = `
|
|
84
|
+
function joinQuery(leftTable, rightTable, on, join, selectList) {
|
|
85
|
+
let query = `SELECT ${selectList}`;
|
|
94
86
|
if (join === "inner") {
|
|
95
87
|
query += ` FROM ${(0, quoteIdentifier_js_1.default)(leftTable)} JOIN ${(0, quoteIdentifier_js_1.default)(rightTable)}`;
|
|
96
88
|
}
|
|
@@ -107,6 +99,6 @@ function joinQuery(leftTable, rightTable, on, join, outputTable, selectList) {
|
|
|
107
99
|
throw new Error(`Unknown ${join} join.`);
|
|
108
100
|
}
|
|
109
101
|
query += ` ON (${on.map((d) => `${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(d)} = ${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(d)}`)
|
|
110
|
-
.join(" AND ")})
|
|
102
|
+
.join(" AND ")})`;
|
|
111
103
|
return query;
|
|
112
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joinGeo.d.ts","sourceRoot":"","sources":["../../src/methods/joinGeo.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"joinGeo.d.ts","sourceRoot":"","sources":["../../src/methods/joinGeo.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,gBAAgB,EACjD,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,UAAU,CAAC;IAClD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,GACL,WAAW,CAqBb"}
|
|
@@ -8,8 +8,6 @@ const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier
|
|
|
8
8
|
const capitalize_js_1 = __importDefault(require("../helpers/capitalize.js"));
|
|
9
9
|
const findGeoColumnFromSchema_js_1 = __importDefault(require("../helpers/findGeoColumnFromSchema.js"));
|
|
10
10
|
const getIdenticalColumns_js_1 = __importDefault(require("../helpers/getIdenticalColumns.js"));
|
|
11
|
-
const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
|
|
12
|
-
const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
|
|
13
11
|
const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
|
|
14
12
|
const assertSameDatabase_js_1 = __importDefault(require("../helpers/assertSameDatabase.js"));
|
|
15
13
|
function joinGeo(leftTable, method, rightTable, options = {}) {
|
|
@@ -22,10 +20,12 @@ function joinGeo(leftTable, method, rightTable, options = {}) {
|
|
|
22
20
|
? leftTable.sdb.newTable(options.outputTable)
|
|
23
21
|
: leftTable;
|
|
24
22
|
(0, queueOp_js_1.default)(outputTable, {
|
|
25
|
-
kind: "
|
|
23
|
+
kind: "source",
|
|
24
|
+
rawSQL: [(0, quoteIdentifier_js_1.default)(leftTable.name), (0, quoteIdentifier_js_1.default)(rightTable.name)],
|
|
25
|
+
needsSpatial: true,
|
|
26
26
|
method: "joinGeo()",
|
|
27
27
|
parameters: { method, rightTable: rightTable.name, options },
|
|
28
|
-
|
|
28
|
+
buildSelect: () => buildJoinGeoSelect(leftTable, method, rightTable, options),
|
|
29
29
|
});
|
|
30
30
|
return outputTable;
|
|
31
31
|
}
|
|
@@ -49,7 +49,7 @@ function validateJoinGeoOptions(method, options) {
|
|
|
49
49
|
function formatReceivedValue(value) {
|
|
50
50
|
return JSON.stringify(value) ?? String(value);
|
|
51
51
|
}
|
|
52
|
-
async function
|
|
52
|
+
async function buildJoinGeoSelect(leftTable, method, rightTable, options) {
|
|
53
53
|
const leftTypes = await leftTable.getTypes();
|
|
54
54
|
const rightTypes = await rightTable.getTypes();
|
|
55
55
|
const leftColumn = options.leftColumn ??
|
|
@@ -89,19 +89,10 @@ async function executeJoinGeo(leftTable, method, rightTable, outputTable, option
|
|
|
89
89
|
]),
|
|
90
90
|
].join(", ");
|
|
91
91
|
const type = options.type ?? "left";
|
|
92
|
-
|
|
93
|
-
table: outputTable.name,
|
|
94
|
-
method: "joinGeo()",
|
|
95
|
-
parameters: {
|
|
96
|
-
leftTable: leftTable.name,
|
|
97
|
-
method,
|
|
98
|
-
rightTable: rightTable.name,
|
|
99
|
-
options,
|
|
100
|
-
},
|
|
101
|
-
}));
|
|
92
|
+
return joinGeoQuery(leftTable.name, leftColumn, method, rightTable.name, rightColumn, type, selectList, options.distance, options.distanceMethod);
|
|
102
93
|
}
|
|
103
|
-
function joinGeoQuery(leftTable, leftColumn, method, rightTable, rightColumn, join,
|
|
104
|
-
let query = `
|
|
94
|
+
function joinGeoQuery(leftTable, leftColumn, method, rightTable, rightColumn, join, selectList, distance, distanceMethod) {
|
|
95
|
+
let query = `SELECT ${selectList}`;
|
|
105
96
|
if (join === "inner") {
|
|
106
97
|
query += ` FROM ${(0, quoteIdentifier_js_1.default)(leftTable)} JOIN ${(0, quoteIdentifier_js_1.default)(rightTable)}`;
|
|
107
98
|
}
|
|
@@ -118,11 +109,11 @@ function joinGeoQuery(leftTable, leftColumn, method, rightTable, rightColumn, jo
|
|
|
118
109
|
throw new Error(`Unknown ${join} join.`);
|
|
119
110
|
}
|
|
120
111
|
if (method === "intersect") {
|
|
121
|
-
query += ` ON ST_Intersects(${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)}, ${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)})
|
|
112
|
+
query += ` ON ST_Intersects(${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)}, ${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)})`;
|
|
122
113
|
}
|
|
123
114
|
else if (method === "inside") {
|
|
124
115
|
// Order is important
|
|
125
|
-
query += ` ON ST_Covers(${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)}, ${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)})
|
|
116
|
+
query += ` ON ST_Covers(${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)}, ${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)})`;
|
|
126
117
|
}
|
|
127
118
|
else if (method === "withinDistance") {
|
|
128
119
|
if (typeof distance === "number") {
|
|
@@ -13,7 +13,7 @@ export declare function prepareArray(rows: {
|
|
|
13
13
|
[key: string]: unknown;
|
|
14
14
|
}[], columnTypes?: {
|
|
15
15
|
[key: string]: string;
|
|
16
|
-
}): PreparedArray;
|
|
16
|
+
}, requireExplicitNestedTypes?: boolean): PreparedArray;
|
|
17
17
|
export declare function executePreparedArray(simpleTable: SimpleTable, prepared: PreparedArray): Promise<void>;
|
|
18
18
|
export {};
|
|
19
19
|
//# sourceMappingURL=loadArray.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadArray.d.ts","sourceRoot":"","sources":["../../src/methods/loadArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"loadArray.d.ts","sourceRoot":"","sources":["../../src/methods/loadArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAKvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,EAClC,OAAO,GAAE,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAM,QAiBnE;AAED,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,WAAW,EAAE,EAAE,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAC1B,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,EAClC,WAAW,GAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAO,EAC3C,0BAA0B,UAAQ,GACjC,aAAa,CAsHf;AAED,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,aAAa,iBA4ExB"}
|