@quereus/quereus 0.6.1 → 0.6.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/dist/src/common/type-inference.d.ts +9 -1
- package/dist/src/common/type-inference.d.ts.map +1 -1
- package/dist/src/common/type-inference.js +11 -3
- package/dist/src/common/type-inference.js.map +1 -1
- package/dist/src/core/database.d.ts +27 -1
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +39 -6
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/param.d.ts +17 -1
- package/dist/src/core/param.d.ts.map +1 -1
- package/dist/src/core/param.js +23 -1
- package/dist/src/core/param.js.map +1 -1
- package/dist/src/core/statement.d.ts +10 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +71 -5
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/planner/scopes/param.d.ts +2 -2
- package/dist/src/planner/scopes/param.d.ts.map +1 -1
- package/dist/src/planner/scopes/param.js +9 -9
- package/dist/src/planner/scopes/param.js.map +1 -1
- package/dist/src/runtime/emit/schema-declarative.js +1 -1
- package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
- package/dist/src/schema/schema-hasher.d.ts +3 -3
- package/dist/src/schema/schema-hasher.d.ts.map +1 -1
- package/dist/src/schema/schema-hasher.js +9 -27
- package/dist/src/schema/schema-hasher.js.map +1 -1
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -1
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/logical-type.d.ts +5 -0
- package/dist/src/types/logical-type.d.ts.map +1 -1
- package/dist/src/types/logical-type.js +15 -0
- package/dist/src/types/logical-type.js.map +1 -1
- package/dist/src/util/hash.d.ts +19 -0
- package/dist/src/util/hash.d.ts.map +1 -0
- package/dist/src/util/hash.js +76 -0
- package/dist/src/util/hash.js.map +1 -0
- package/package.json +1 -1
- package/src/common/type-inference.ts +11 -3
- package/src/core/database.ts +41 -6
- package/src/core/param.ts +23 -1
- package/src/core/statement.ts +89 -5
- package/src/planner/building/delete.ts +214 -214
- package/src/planner/building/insert.ts +428 -428
- package/src/planner/building/update.ts +319 -319
- package/src/planner/scopes/param.ts +9 -9
- package/src/runtime/emit/schema-declarative.ts +1 -1
- package/src/schema/schema-hasher.ts +9 -27
- package/src/types/index.ts +1 -1
- package/src/types/logical-type.ts +16 -0
- package/src/util/ast-stringify.ts +864 -864
- package/src/util/hash.ts +90 -0
- package/src/vtab/memory/table.ts +256 -256
- package/src/vtab/table.ts +162 -162
|
@@ -20,14 +20,14 @@ const DEFAULT_PARAMETER_TYPE: ScalarType = {
|
|
|
20
20
|
export class ParameterScope extends BaseScope {
|
|
21
21
|
private _nextAnonymousIndex: number = 1;
|
|
22
22
|
private readonly _parameters: Map<string | number, ParameterReferenceNode> = new Map();
|
|
23
|
-
private readonly
|
|
23
|
+
private readonly _parameterTypes: ReadonlyMap<string | number, ScalarType>;
|
|
24
24
|
|
|
25
25
|
constructor(
|
|
26
26
|
public readonly parentScope: Scope,
|
|
27
|
-
|
|
27
|
+
parameterTypes?: ReadonlyMap<string | number, ScalarType>
|
|
28
28
|
) {
|
|
29
29
|
super();
|
|
30
|
-
this.
|
|
30
|
+
this._parameterTypes = parameterTypes || new Map();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
resolveSymbol(symbolKey: string, expression: AST.Expression): PlanNode | typeof Ambiguous | undefined {
|
|
@@ -42,9 +42,9 @@ export class ParameterScope extends BaseScope {
|
|
|
42
42
|
// Use the current _nextAnonymousIndex as the potential identifier for this '?'
|
|
43
43
|
const currentAnonymousId = this._nextAnonymousIndex;
|
|
44
44
|
|
|
45
|
-
// Check if this specific anonymous parameter (by its future index) has a type
|
|
46
|
-
if (this.
|
|
47
|
-
resolvedType = this.
|
|
45
|
+
// Check if this specific anonymous parameter (by its future index) has a declared type
|
|
46
|
+
if (this._parameterTypes.has(currentAnonymousId)) {
|
|
47
|
+
resolvedType = this._parameterTypes.get(currentAnonymousId)!;
|
|
48
48
|
}
|
|
49
49
|
// Note: We don't check _parameters here for '?' because each '?' AST node should resolve,
|
|
50
50
|
// potentially creating a new ParameterReferenceNode if it's a new '?' instance in the query,
|
|
@@ -63,10 +63,10 @@ export class ParameterScope extends BaseScope {
|
|
|
63
63
|
|
|
64
64
|
if (this._parameters.has(identifier)) {
|
|
65
65
|
parameterNode = this._parameters.get(identifier)!;
|
|
66
|
-
// If already exists, its type was set at creation
|
|
66
|
+
// If already exists, its type was set at creation
|
|
67
67
|
} else {
|
|
68
|
-
if (this.
|
|
69
|
-
resolvedType = this.
|
|
68
|
+
if (this._parameterTypes.has(identifier)) {
|
|
69
|
+
resolvedType = this._parameterTypes.get(identifier)!;
|
|
70
70
|
}
|
|
71
71
|
parameterNode = new ParameterReferenceNode(this, parameterExpression, identifier, resolvedType);
|
|
72
72
|
this._parameters.set(identifier, parameterNode);
|
|
@@ -195,7 +195,7 @@ export function emitExplainSchema(plan: PlanNode, _ctx: EmissionContext): Instru
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
// Compute hash
|
|
198
|
-
const hash =
|
|
198
|
+
const hash = computeShortSchemaHash(declaredSchema);
|
|
199
199
|
|
|
200
200
|
// Return hash with version if specified
|
|
201
201
|
const result = explainStmt.version
|
|
@@ -1,44 +1,26 @@
|
|
|
1
1
|
import type * as AST from '../parser/ast.js';
|
|
2
2
|
import { generateDeclaredDDL } from './catalog.js';
|
|
3
|
+
import { fnv1aHash, toBase64Url } from '../util/hash.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Computes a hash of a declared schema for versioning
|
|
6
7
|
*/
|
|
7
|
-
export
|
|
8
|
+
export function computeSchemaHash(declaredSchema: AST.DeclareSchemaStmt): string {
|
|
8
9
|
// Generate canonical DDL representation
|
|
9
10
|
const ddlStatements = generateDeclaredDDL(declaredSchema);
|
|
10
11
|
const canonicalText = ddlStatements.join('\n');
|
|
11
12
|
|
|
12
|
-
// Compute
|
|
13
|
-
const
|
|
14
|
-
return
|
|
13
|
+
// Compute hash using FNV-1a algorithm and encode as base64url
|
|
14
|
+
const hashBytes = fnv1aHash(canonicalText);
|
|
15
|
+
return toBase64Url(hashBytes);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* Computes
|
|
19
|
+
* Computes a short hash (first 8 characters) for display
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Web Crypto API
|
|
24
|
-
const encoder = new TextEncoder();
|
|
25
|
-
const data = encoder.encode(message);
|
|
26
|
-
const hashBuffer = await globalThis.crypto.subtle.digest('SHA-256', data);
|
|
27
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
28
|
-
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
29
|
-
} else {
|
|
30
|
-
// Node.js crypto
|
|
31
|
-
const crypto = await import('node:crypto');
|
|
32
|
-
return crypto.createHash('sha256').update(message, 'utf8').digest('hex');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Computes a short hash (first 12 characters) for display
|
|
38
|
-
*/
|
|
39
|
-
export async function computeShortSchemaHash(declaredSchema: AST.DeclareSchemaStmt): Promise<string> {
|
|
40
|
-
const fullHash = await computeSchemaHash(declaredSchema);
|
|
41
|
-
return fullHash.substring(0, 12);
|
|
21
|
+
export function computeShortSchemaHash(declaredSchema: AST.DeclareSchemaStmt): string {
|
|
22
|
+
const fullHash = computeSchemaHash(declaredSchema);
|
|
23
|
+
return fullHash.substring(0, 8);
|
|
42
24
|
}
|
|
43
25
|
|
|
44
26
|
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Core type system exports
|
|
2
|
-
export { PhysicalType, type LogicalType, getPhysicalType } from './logical-type.js';
|
|
2
|
+
export { PhysicalType, type LogicalType, getPhysicalType, physicalTypeName } from './logical-type.js';
|
|
3
3
|
|
|
4
4
|
// Built-in types
|
|
5
5
|
export { NULL_TYPE, INTEGER_TYPE, REAL_TYPE, TEXT_TYPE, BLOB_TYPE, BOOLEAN_TYPE, NUMERIC_TYPE, ANY_TYPE } from './builtin-types.js';
|
|
@@ -73,3 +73,19 @@ export function getPhysicalType(value: SqlValue): PhysicalType {
|
|
|
73
73
|
return PhysicalType.NULL;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Get a human-readable name for a physical type code.
|
|
78
|
+
* Useful for error messages and debugging.
|
|
79
|
+
*/
|
|
80
|
+
export function physicalTypeName(physicalType: PhysicalType): string {
|
|
81
|
+
switch (physicalType) {
|
|
82
|
+
case PhysicalType.NULL: return 'NULL';
|
|
83
|
+
case PhysicalType.INTEGER: return 'INTEGER';
|
|
84
|
+
case PhysicalType.REAL: return 'REAL';
|
|
85
|
+
case PhysicalType.TEXT: return 'TEXT';
|
|
86
|
+
case PhysicalType.BLOB: return 'BLOB';
|
|
87
|
+
case PhysicalType.BOOLEAN: return 'BOOLEAN';
|
|
88
|
+
default: return 'UNKNOWN';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|