flatsql 1.1.0 → 1.3.0
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 +42 -4
- package/dist/core/database.d.ts +41 -2
- package/dist/core/database.d.ts.map +1 -1
- package/dist/core/database.js +745 -128
- package/dist/core/database.js.map +1 -1
- package/package.json +1 -1
- package/wasm/flatsql-wasi-noeh.wasm +0 -0
- package/wasm/flatsql-wasi.wasm +0 -0
- package/wasm/flatsql.js +1 -1
- package/wasm/flatsql.wasm +0 -0
- package/wasm/index.d.ts +14 -0
- package/wasm/index.js +33 -0
- package/wasm/standalone.d.ts +14 -0
- package/wasm/standalone.js +36 -0
package/README.md
CHANGED
|
@@ -74,6 +74,29 @@ FlatBuffer → Query (via virtual table) → FlatBuffer
|
|
|
74
74
|
|
|
75
75
|
## Runtime Choices & Performance Gates
|
|
76
76
|
|
|
77
|
+
### SDN flow runtime contract
|
|
78
|
+
|
|
79
|
+
Within an SDN module flow, FlatSQL always runs as a signed, pluggable WASM node.
|
|
80
|
+
The exact same artifact bytes and hash run under the browser/JavaScript harness
|
|
81
|
+
and WasmEdge. The pure TypeScript implementation is a library fallback and
|
|
82
|
+
must not substitute for the FlatSQL node in an isomorphic flow.
|
|
83
|
+
|
|
84
|
+
FlatSQL remains independently instantiated and addressable by its signed
|
|
85
|
+
manifest and artifact hash. A flow bundle may carry those bytes, but a compiler
|
|
86
|
+
must not statically fold FlatSQL into the consuming application module.
|
|
87
|
+
|
|
88
|
+
The FlatSQL node owns SQL, tables, rows, indexes, compaction, snapshots, and
|
|
89
|
+
reload semantics. Hosts provide only generic opaque byte persistence,
|
|
90
|
+
shared-arena bounds checking, clocks/wakeups, network byte streams, and module
|
|
91
|
+
lifecycle. They must not expose a FlatSQL service, `storage_engine_link`, or
|
|
92
|
+
schema-aware row/query API.
|
|
93
|
+
|
|
94
|
+
Every FlatSQL module input and output port supports both canonical SDS
|
|
95
|
+
FlatBuffer and aligned-binary representations for the same schema identity.
|
|
96
|
+
`PIV`/`TAB.WIRE_FORMAT` selects per frame. Aligned frames are transient
|
|
97
|
+
shared-memory views; durable, network, and fallback records remain canonical
|
|
98
|
+
size-prefixed FlatBuffers.
|
|
99
|
+
|
|
77
100
|
- Production should prefer the SQLite-backed native/WASM path (`initFlatSQL` → `FlatSQL` → `createDatabase`). The pure TypeScript `FlatSQLDatabase` is preserved only as an explicit fallback/reference implementation for environments that cannot load the WASM module.
|
|
78
101
|
- Standalone deployments use the C++ WASI reactor at `flatsql/wasi.wasm`. Browser hosts load it through `flatsql/standalone`, while Node/WasmEdge hosts use a resident runner from `flatsql/standalone/wasmedge`.
|
|
79
102
|
- Artifact-builder cache behavior belongs to C++: query templates, result-cache keys, invalidation generation, hit/miss counters, SQL execution, and raw FlatBuffer lookup all live in the WASM database instance. JavaScript only marshals bytes and fills host capability gaps.
|
|
@@ -459,14 +482,29 @@ const back = sdm.fromECEF(ecef.x, ecef.y, ecef.z);
|
|
|
459
482
|
|
|
460
483
|
## SQL Support
|
|
461
484
|
|
|
485
|
+
FlatSQL ships two query engines. The WASM engine (`initFlatSQL()`) embeds
|
|
486
|
+
SQLite and speaks full SQL. The pure-JS engine (`FlatSQLDatabase`, used where a
|
|
487
|
+
WASM instance is not available) implements the focused subset below.
|
|
488
|
+
|
|
489
|
+
### Fail-closed guarantee
|
|
490
|
+
|
|
491
|
+
Both engines reject what they cannot execute. In particular the JS engine
|
|
492
|
+
**throws** on a `WHERE`, `ORDER BY`, or `LIMIT` clause its grammar does not
|
|
493
|
+
understand. It never falls back to an unfiltered scan: a caller that asks for a
|
|
494
|
+
subset must get that subset or an error, never the whole table with no
|
|
495
|
+
indication that the filter was dropped.
|
|
496
|
+
|
|
462
497
|
### Supported
|
|
463
498
|
|
|
464
499
|
- `SELECT` with column selection
|
|
465
|
-
- `WHERE` with `=`, `<`, `>`, `<=`, `>=`, `BETWEEN`, `
|
|
466
|
-
|
|
500
|
+
- `WHERE` with `=`, `!=`/`<>`, `<`, `>`, `<=`, `>=`, `BETWEEN`, `IN`, `LIKE`,
|
|
501
|
+
`IS NULL`, and `AND` / `OR` / `NOT` / parentheses
|
|
502
|
+
- `LIKE` with `%` and `_` wildcards, ASCII case-insensitive (the SQLite default)
|
|
503
|
+
- `ORDER BY` (ASC/DESC, multiple terms)
|
|
467
504
|
- `LIMIT` and `OFFSET`
|
|
468
|
-
- `COUNT(*)` aggregate
|
|
469
|
-
- Index-accelerated queries on `(id)` and `(key)` columns
|
|
505
|
+
- `COUNT(*)` aggregate (WASM engine)
|
|
506
|
+
- Index-accelerated queries on `(id)` and `(key)` columns, including as one
|
|
507
|
+
conjunct of a larger `AND` predicate
|
|
470
508
|
|
|
471
509
|
### Not Supported
|
|
472
510
|
|
package/dist/core/database.d.ts
CHANGED
|
@@ -31,9 +31,7 @@ export declare class FlatSQLDatabase {
|
|
|
31
31
|
getStorageBytes(): number;
|
|
32
32
|
query(sql: string): QueryResult;
|
|
33
33
|
private parseSQL;
|
|
34
|
-
private parseValue;
|
|
35
34
|
private enforceRateLimit;
|
|
36
|
-
private evaluateCondition;
|
|
37
35
|
getTableDef(tableName: string): TableDef | undefined;
|
|
38
36
|
listTables(): string[];
|
|
39
37
|
exportData(): Uint8Array;
|
|
@@ -44,4 +42,45 @@ export declare class FlatSQLDatabase {
|
|
|
44
42
|
indexes: string[];
|
|
45
43
|
}[];
|
|
46
44
|
}
|
|
45
|
+
export interface OrderByTerm {
|
|
46
|
+
column: string;
|
|
47
|
+
descending: boolean;
|
|
48
|
+
}
|
|
49
|
+
type ComparisonOperator = '=' | '!=' | '<>' | '<' | '>' | '<=' | '>=';
|
|
50
|
+
export type WhereNode = {
|
|
51
|
+
kind: 'and';
|
|
52
|
+
children: WhereNode[];
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'or';
|
|
55
|
+
children: WhereNode[];
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'not';
|
|
58
|
+
child: WhereNode;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'cmp';
|
|
61
|
+
column: string;
|
|
62
|
+
operator: ComparisonOperator;
|
|
63
|
+
value: any;
|
|
64
|
+
} | {
|
|
65
|
+
kind: 'between';
|
|
66
|
+
column: string;
|
|
67
|
+
minValue: any;
|
|
68
|
+
maxValue: any;
|
|
69
|
+
negated: boolean;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'in';
|
|
72
|
+
column: string;
|
|
73
|
+
values: any[];
|
|
74
|
+
negated: boolean;
|
|
75
|
+
} | {
|
|
76
|
+
kind: 'like';
|
|
77
|
+
column: string;
|
|
78
|
+
matcher: RegExp;
|
|
79
|
+
negated: boolean;
|
|
80
|
+
} | {
|
|
81
|
+
kind: 'isNull';
|
|
82
|
+
column: string;
|
|
83
|
+
negated: boolean;
|
|
84
|
+
};
|
|
85
|
+
export {};
|
|
47
86
|
//# sourceMappingURL=database.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAe,MAAM,oBAAoB,CAAC;AAS3E,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAEjC,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEhD,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC;CACzE;AAED,MAAM,WAAW,eAAe;IAC9B,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,eAAe;IAC1B,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