squirreling 0.9.2 → 0.9.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.
- package/README.md +2 -0
- package/package.json +2 -2
- package/src/backend/dataSource.js +2 -2
- package/src/expression/evaluate.js +32 -1
- package/src/expression/spatial.js +1471 -0
- package/src/types.d.ts +16 -0
- package/src/validation.js +39 -2
- package/src/validationErrors.js +16 -0
package/README.md
CHANGED
|
@@ -149,6 +149,8 @@ Squirreling mostly follows the SQL standard. The following features are supporte
|
|
|
149
149
|
- Trig: `SIN`, `COS`, `TAN`, `COT`, `ASIN`, `ACOS`, `ATAN`, `ATAN2`, `DEGREES`, `RADIANS`, `PI`
|
|
150
150
|
- Date: `CURRENT_DATE`, `CURRENT_TIME`, `CURRENT_TIMESTAMP`, `INTERVAL`
|
|
151
151
|
- Json: `JSON_VALUE`, `JSON_QUERY`, `JSON_OBJECT`
|
|
152
|
+
- Array: `ARRAY_LENGTH`, `ARRAY_POSITION`, `ARRAY_SORT`, `CARDINALITY`
|
|
152
153
|
- Regex: `REGEXP_SUBSTR`, `REGEXP_REPLACE`
|
|
154
|
+
- Spatial: `ST_GeomFromText`, `ST_MakeEnvelope`, `ST_AsText`, `ST_Intersects`, `ST_Contains`, `ST_ContainsProperly`, `ST_Within`, `ST_Overlaps`, `ST_Touches`, `ST_Equals`, `ST_Crosses`, `ST_Covers`, `ST_CoveredBy`, `ST_DWithin`
|
|
153
155
|
- Conditional: `COALESCE`, `NULLIF`
|
|
154
156
|
- User-defined functions (UDFs)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squirreling",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Squirreling Async SQL Engine",
|
|
5
5
|
"author": "Hyperparam",
|
|
6
6
|
"homepage": "https://hyperparam.app",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@types/node": "25.3.0",
|
|
41
41
|
"@vitest/coverage-v8": "4.0.18",
|
|
42
42
|
"eslint": "9.39.2",
|
|
43
|
-
"eslint-plugin-jsdoc": "62.
|
|
43
|
+
"eslint-plugin-jsdoc": "62.7.1",
|
|
44
44
|
"typescript": "5.9.3",
|
|
45
45
|
"vitest": "4.0.18"
|
|
46
46
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { AsyncCells, AsyncDataSource, AsyncRow,
|
|
2
|
+
* @import { AsyncCells, AsyncDataSource, AsyncRow, SqlPrimitive } from '../types.js'
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @param {Record<string, SqlPrimitive>} obj - the plain object
|
|
9
9
|
* @returns {AsyncRow} a row accessor interface
|
|
10
10
|
*/
|
|
11
|
-
function asyncRow(obj) {
|
|
11
|
+
export function asyncRow(obj) {
|
|
12
12
|
/** @type {AsyncCells} */
|
|
13
13
|
const cells = {}
|
|
14
14
|
for (const [key, value] of Object.entries(obj)) {
|
|
@@ -2,13 +2,14 @@ import { executeSelect } from '../execute/execute.js'
|
|
|
2
2
|
import { stringify } from '../execute/utils.js'
|
|
3
3
|
import { columnNotFoundError, invalidContextError } from '../executionErrors.js'
|
|
4
4
|
import { unknownFunctionError } from '../parseErrors.js'
|
|
5
|
-
import { isAggregateFunc, isMathFunc, isRegexpFunc, isStringFunc } from '../validation.js'
|
|
5
|
+
import { isAggregateFunc, isMathFunc, isRegexpFunc, isSpatialFunc, isStringFunc } from '../validation.js'
|
|
6
6
|
import { aggregateError, argValueError, castError } from '../validationErrors.js'
|
|
7
7
|
import { derivedAlias } from './alias.js'
|
|
8
8
|
import { applyBinaryOp } from './binary.js'
|
|
9
9
|
import { applyIntervalToDate } from './date.js'
|
|
10
10
|
import { evaluateMathFunc } from './math.js'
|
|
11
11
|
import { evaluateRegexpFunc } from './regexp.js'
|
|
12
|
+
import { evaluateSpatialFunc } from './spatial.js'
|
|
12
13
|
import { evaluateStringFunc } from './strings.js'
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -250,6 +251,10 @@ export async function evaluateExpr({ node, row, rowIndex, rows, context }) {
|
|
|
250
251
|
return evaluateMathFunc({ funcName, args })
|
|
251
252
|
}
|
|
252
253
|
|
|
254
|
+
if (isSpatialFunc(funcName)) {
|
|
255
|
+
return evaluateSpatialFunc({ funcName, args })
|
|
256
|
+
}
|
|
257
|
+
|
|
253
258
|
if (funcName === 'COALESCE') {
|
|
254
259
|
// Short-circuit: evaluate args one at a time, return first non-null
|
|
255
260
|
for (const arg of node.args) {
|
|
@@ -308,6 +313,32 @@ export async function evaluateExpr({ node, row, rowIndex, rows, context }) {
|
|
|
308
313
|
return result
|
|
309
314
|
}
|
|
310
315
|
|
|
316
|
+
if (funcName === 'ARRAY_LENGTH' || funcName === 'CARDINALITY') {
|
|
317
|
+
const arr = args[0]
|
|
318
|
+
if (!Array.isArray(arr)) return null
|
|
319
|
+
return arr.length
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (funcName === 'ARRAY_POSITION') {
|
|
323
|
+
const [arr, target] = args
|
|
324
|
+
if (!Array.isArray(arr)) return null
|
|
325
|
+
const index = arr.indexOf(target)
|
|
326
|
+
return index === -1 ? null : index + 1
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (funcName === 'ARRAY_SORT') {
|
|
330
|
+
const arr = args[0]
|
|
331
|
+
if (!Array.isArray(arr)) return null
|
|
332
|
+
return [...arr].sort((a, b) => {
|
|
333
|
+
if (a == null && b == null) return 0
|
|
334
|
+
if (a == null) return 1
|
|
335
|
+
if (b == null) return -1
|
|
336
|
+
if (a < b) return -1
|
|
337
|
+
if (a > b) return 1
|
|
338
|
+
return 0
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
|
|
311
342
|
if (funcName === 'JSON_VALUE' || funcName === 'JSON_QUERY') {
|
|
312
343
|
let jsonArg = args[0]
|
|
313
344
|
const pathArg = args[1]
|