litedbmodel 2.0.2 → 2.2.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 +7 -0
- package/dist/DBConditions.d.ts.map +1 -1
- package/dist/DBConditions.js +16 -1
- package/dist/DBConditions.js.map +1 -1
- package/dist/DBHandler.d.ts.map +1 -1
- package/dist/DBHandler.js +6 -0
- package/dist/DBHandler.js.map +1 -1
- package/dist/DBModel.d.ts +84 -2
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +312 -29
- package/dist/DBModel.js.map +1 -1
- package/dist/decorators.d.ts +52 -0
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +127 -24
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/mysql.d.ts.map +1 -1
- package/dist/drivers/mysql.js +12 -2
- package/dist/drivers/mysql.js.map +1 -1
- package/dist/drivers/postgres.d.ts.map +1 -1
- package/dist/drivers/postgres.js +13 -2
- package/dist/drivers/postgres.js.map +1 -1
- package/dist/drivers/sqlite.d.ts +2 -0
- package/dist/drivers/sqlite.d.ts.map +1 -1
- package/dist/drivers/sqlite.js +49 -4
- package/dist/drivers/sqlite.js.map +1 -1
- package/dist/index.cjs +10741 -0
- package/dist/index.d.cts +1 -0
- package/dist/scp/coltype.d.ts +108 -0
- package/dist/scp/coltype.d.ts.map +1 -1
- package/dist/scp/coltype.js +293 -6
- package/dist/scp/coltype.js.map +1 -1
- package/dist/scp/connection-routing.d.ts +312 -0
- package/dist/scp/connection-routing.d.ts.map +1 -0
- package/dist/scp/connection-routing.js +394 -0
- package/dist/scp/connection-routing.js.map +1 -0
- package/dist/scp/dbmodel-runtime.d.ts +101 -0
- package/dist/scp/dbmodel-runtime.d.ts.map +1 -0
- package/dist/scp/dbmodel-runtime.js +174 -0
- package/dist/scp/dbmodel-runtime.js.map +1 -0
- package/dist/scp/decorator-adapter.d.ts +196 -0
- package/dist/scp/decorator-adapter.d.ts.map +1 -0
- package/dist/scp/decorator-adapter.js +286 -0
- package/dist/scp/decorator-adapter.js.map +1 -0
- package/dist/scp/emit/emitter.d.ts +108 -0
- package/dist/scp/emit/emitter.d.ts.map +1 -0
- package/dist/scp/emit/emitter.js +782 -0
- package/dist/scp/emit/emitter.js.map +1 -0
- package/dist/scp/emit/endpoint.d.ts +248 -0
- package/dist/scp/emit/endpoint.d.ts.map +1 -0
- package/dist/scp/emit/endpoint.js +20 -0
- package/dist/scp/emit/endpoint.js.map +1 -0
- package/dist/scp/emit/index.d.ts +11 -0
- package/dist/scp/emit/index.d.ts.map +1 -0
- package/dist/scp/emit/index.js +13 -0
- package/dist/scp/emit/index.js.map +1 -0
- package/dist/scp/errors.d.ts +45 -1
- package/dist/scp/errors.d.ts.map +1 -1
- package/dist/scp/errors.js +47 -1
- package/dist/scp/errors.js.map +1 -1
- package/dist/scp/exec-context.d.ts +390 -0
- package/dist/scp/exec-context.d.ts.map +1 -0
- package/dist/scp/exec-context.js +540 -0
- package/dist/scp/exec-context.js.map +1 -0
- package/dist/scp/grouping.d.ts +32 -0
- package/dist/scp/grouping.d.ts.map +1 -0
- package/dist/scp/grouping.js +0 -0
- package/dist/scp/grouping.js.map +1 -0
- package/dist/scp/index.cjs +6432 -17579
- package/dist/scp/index.d.cts +1 -0
- package/dist/scp/index.d.mts +1 -0
- package/dist/scp/index.d.ts +51 -52
- package/dist/scp/index.d.ts.map +1 -1
- package/dist/scp/index.js +189 -152
- package/dist/scp/index.js.map +1 -1
- package/dist/scp/index.mjs +6067 -3659
- package/dist/scp/leaf-transport.d.ts +50 -0
- package/dist/scp/leaf-transport.d.ts.map +1 -0
- package/dist/scp/leaf-transport.js +92 -0
- package/dist/scp/leaf-transport.js.map +1 -0
- package/dist/scp/leaves.d.ts +174 -0
- package/dist/scp/leaves.d.ts.map +1 -0
- package/dist/scp/leaves.js +287 -0
- package/dist/scp/leaves.js.map +1 -0
- package/dist/scp/limit-config.d.ts +118 -0
- package/dist/scp/limit-config.d.ts.map +1 -0
- package/dist/scp/limit-config.js +126 -0
- package/dist/scp/limit-config.js.map +1 -0
- package/dist/scp/makesql/compile-relation.d.ts +49 -23
- package/dist/scp/makesql/compile-relation.d.ts.map +1 -1
- package/dist/scp/makesql/compile-relation.js +101 -76
- package/dist/scp/makesql/compile-relation.js.map +1 -1
- package/dist/scp/makesql/compile-select.d.ts +45 -10
- package/dist/scp/makesql/compile-select.d.ts.map +1 -1
- package/dist/scp/makesql/compile-select.js +50 -10
- package/dist/scp/makesql/compile-select.js.map +1 -1
- package/dist/scp/makesql/handler.d.ts +1 -1
- package/dist/scp/makesql/handler.d.ts.map +1 -1
- package/dist/scp/makesql/index.d.ts +7 -10
- package/dist/scp/makesql/index.d.ts.map +1 -1
- package/dist/scp/makesql/index.js +19 -30
- package/dist/scp/makesql/index.js.map +1 -1
- package/dist/scp/makesql/json-array.d.ts +65 -0
- package/dist/scp/makesql/json-array.d.ts.map +1 -1
- package/dist/scp/makesql/json-array.js +99 -10
- package/dist/scp/makesql/json-array.js.map +1 -1
- package/dist/scp/makesql/json-batch.d.ts.map +1 -1
- package/dist/scp/makesql/json-batch.js +21 -19
- package/dist/scp/makesql/json-batch.js.map +1 -1
- package/dist/scp/makesql/makesql.d.ts +1 -1
- package/dist/scp/makesql/makesql.d.ts.map +1 -1
- package/dist/scp/makesql/mysql-returning.d.ts +93 -0
- package/dist/scp/makesql/mysql-returning.d.ts.map +1 -0
- package/dist/scp/makesql/mysql-returning.js +215 -0
- package/dist/scp/makesql/mysql-returning.js.map +1 -0
- package/dist/scp/makesql/outtype.d.ts +75 -34
- package/dist/scp/makesql/outtype.d.ts.map +1 -1
- package/dist/scp/makesql/outtype.js +91 -118
- package/dist/scp/makesql/outtype.js.map +1 -1
- package/dist/scp/makesql/pool-executor.d.ts +135 -13
- package/dist/scp/makesql/pool-executor.d.ts.map +1 -1
- package/dist/scp/makesql/pool-executor.js +229 -21
- package/dist/scp/makesql/pool-executor.js.map +1 -1
- package/dist/scp/makesql/tx.d.ts +107 -22
- package/dist/scp/makesql/tx.d.ts.map +1 -1
- package/dist/scp/makesql/tx.js +451 -97
- package/dist/scp/makesql/tx.js.map +1 -1
- package/dist/scp/makesql/writeouttype.d.ts +7 -8
- package/dist/scp/makesql/writeouttype.d.ts.map +1 -1
- package/dist/scp/makesql/writeouttype.js +8 -7
- package/dist/scp/makesql/writeouttype.js.map +1 -1
- package/dist/scp/middleware.d.ts +287 -0
- package/dist/scp/middleware.d.ts.map +1 -0
- package/dist/scp/middleware.js +358 -0
- package/dist/scp/middleware.js.map +1 -0
- package/dist/scp/relation.d.ts +80 -9
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +198 -78
- package/dist/scp/relation.js.map +1 -1
- package/dist/scp/tx-options.d.ts +136 -0
- package/dist/scp/tx-options.d.ts.map +1 -0
- package/dist/scp/tx-options.js +184 -0
- package/dist/scp/tx-options.js.map +1 -0
- package/dist/scp/write-bundle.d.ts +131 -0
- package/dist/scp/write-bundle.d.ts.map +1 -0
- package/dist/scp/write-bundle.js +160 -0
- package/dist/scp/write-bundle.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/BENCHMARK.md +58 -56
- package/docs/benchmark-chart.svg +166 -166
- package/docs/design/phase-a-execution-context.md +139 -0
- package/package.json +16 -9
- package/dist/scp/authoring-sql.d.ts +0 -134
- package/dist/scp/authoring-sql.d.ts.map +0 -1
- package/dist/scp/authoring-sql.js +0 -191
- package/dist/scp/authoring-sql.js.map +0 -1
- package/dist/scp/authoring.d.ts +0 -155
- package/dist/scp/authoring.d.ts.map +0 -1
- package/dist/scp/authoring.js +0 -162
- package/dist/scp/authoring.js.map +0 -1
- package/dist/scp/catalog.d.ts +0 -94
- package/dist/scp/catalog.d.ts.map +0 -1
- package/dist/scp/catalog.js +0 -234
- package/dist/scp/catalog.js.map +0 -1
- package/dist/scp/codegen.d.ts +0 -189
- package/dist/scp/codegen.d.ts.map +0 -1
- package/dist/scp/codegen.js +0 -421
- package/dist/scp/codegen.js.map +0 -1
- package/dist/scp/find-filter-guard.d.ts +0 -68
- package/dist/scp/find-filter-guard.d.ts.map +0 -1
- package/dist/scp/find-filter-guard.js +0 -88
- package/dist/scp/find-filter-guard.js.map +0 -1
- package/dist/scp/guard.d.ts +0 -43
- package/dist/scp/guard.d.ts.map +0 -1
- package/dist/scp/guard.js +0 -134
- package/dist/scp/guard.js.map +0 -1
- package/dist/scp/makesql/authoring-compile.d.ts +0 -90
- package/dist/scp/makesql/authoring-compile.d.ts.map +0 -1
- package/dist/scp/makesql/authoring-compile.js +0 -494
- package/dist/scp/makesql/authoring-compile.js.map +0 -1
- package/dist/scp/makesql/ir.d.ts +0 -42
- package/dist/scp/makesql/ir.d.ts.map +0 -1
- package/dist/scp/makesql/ir.js +0 -66
- package/dist/scp/makesql/ir.js.map +0 -1
- package/dist/scp/makesql/static-bundle.d.ts +0 -187
- package/dist/scp/makesql/static-bundle.d.ts.map +0 -1
- package/dist/scp/makesql/static-bundle.js +0 -1113
- package/dist/scp/makesql/static-bundle.js.map +0 -1
- package/dist/scp/runtime.d.ts +0 -242
- package/dist/scp/runtime.d.ts.map +0 -1
- package/dist/scp/runtime.js +0 -400
- package/dist/scp/runtime.js.map +0 -1
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* catalog leaf + handler + compile. Pure-JSON bundle, multi-language ready.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
13
|
+
exports.countingDriver = exports.executeTransactionAsync = exports.executeTransaction = exports.literalize = exports.deriveBatchPlan = exports.deriveTransactionPlan = exports.rowsHaveDbToken = exports.mysqlJsonTableColumn = exports.sqliteUpdateManyJson = exports.mysqlUpdateManyJson = exports.sqliteInsertJson = exports.mysqlInsertJson = exports.conditionsFor = exports.JsonArrayConditions = exports.encodeJsonArrayParam = exports.inListPredicate = exports.inListJson = exports.compileCompositeKeyStaticLimited = exports.compileCompositeKeyLimited = exports.compileCompositeKeyStaticUnlimited = exports.compileCompositeKeyUnlimited = exports.compileSingleKeyLimited = exports.compileSingleKeyUnlimited = exports.PG_ARRAY_CAST_TOKEN = exports.resolvePgArrayCast = exports.inferPgArrayType = exports.compileDeleteMany = exports.compileDelete = exports.compileUpdateSingle = exports.compileUpdateMany = exports.compileInsertMany = exports.compileInsert = exports.builderFor = exports.compileSelect = exports.noCastFormatter = exports.pgCastFormatter = exports.formatterFor = exports.andTrailing = exports.whereClause = exports.compileWhere = exports.makeSqlHandlerSync = exports.makeSqlHandler = exports.renderPorts = exports.renderPlaceholders = exports.composeMakeSQL = exports.assembleMakeSQL = exports.isMakeSQL = exports.LITEDBMODEL_MAKESQL_CATALOG = exports.makeSqlCatalogEntry = exports.MAKESQL = void 0;
|
|
14
|
+
exports.mysqlPoolFactory = exports.pgPoolFactory = exports.mysqlConnectionPool = exports.pgConnectionPool = exports.mysqlDeboxPoolOptions = exports.configurePgDeboxTypeParsers = exports.bindReselect = exports.buildMysqlReselect = exports.stripMysqlPkHint = exports.mysqlPkHint = exports.IN_SENTINEL = exports.pgTypeSpecimen = exports.compileWriteNode = exports.renderTxStatement = void 0;
|
|
15
15
|
// Catalog leaf + assembly core.
|
|
16
16
|
var makesql_1 = require("./makesql");
|
|
17
17
|
Object.defineProperty(exports, "MAKESQL", { enumerable: true, get: function () { return makesql_1.MAKESQL; } });
|
|
@@ -61,6 +61,8 @@ Object.defineProperty(exports, "compileCompositeKeyStaticLimited", { enumerable:
|
|
|
61
61
|
// intentional deviation from v1's N-placeholder expansion (server-side JSON expansion).
|
|
62
62
|
var json_array_1 = require("./json-array");
|
|
63
63
|
Object.defineProperty(exports, "inListJson", { enumerable: true, get: function () { return json_array_1.inListJson; } });
|
|
64
|
+
Object.defineProperty(exports, "inListPredicate", { enumerable: true, get: function () { return json_array_1.inListPredicate; } });
|
|
65
|
+
Object.defineProperty(exports, "encodeJsonArrayParam", { enumerable: true, get: function () { return json_array_1.encodeJsonArrayParam; } });
|
|
64
66
|
Object.defineProperty(exports, "JsonArrayConditions", { enumerable: true, get: function () { return json_array_1.JsonArrayConditions; } });
|
|
65
67
|
Object.defineProperty(exports, "conditionsFor", { enumerable: true, get: function () { return json_array_1.conditionsFor; } });
|
|
66
68
|
var json_batch_1 = require("./json-batch");
|
|
@@ -70,45 +72,32 @@ Object.defineProperty(exports, "mysqlUpdateManyJson", { enumerable: true, get: f
|
|
|
70
72
|
Object.defineProperty(exports, "sqliteUpdateManyJson", { enumerable: true, get: function () { return json_batch_1.sqliteUpdateManyJson; } });
|
|
71
73
|
Object.defineProperty(exports, "mysqlJsonTableColumn", { enumerable: true, get: function () { return json_batch_1.mysqlJsonTableColumn; } });
|
|
72
74
|
Object.defineProperty(exports, "rowsHaveDbToken", { enumerable: true, get: function () { return json_batch_1.rowsHaveDbToken; } });
|
|
73
|
-
// bc IR wiring (a query rides runBehavior as a makeSQL component).
|
|
74
|
-
var ir_1 = require("./ir");
|
|
75
|
-
Object.defineProperty(exports, "makeSqlComponentIR", { enumerable: true, get: function () { return ir_1.makeSqlComponentIR; } });
|
|
76
|
-
Object.defineProperty(exports, "makeSqlInput", { enumerable: true, get: function () { return ir_1.makeSqlInput; } });
|
|
77
75
|
// Write-time relations → makeSQL transaction plan + 1-tx runtime (epic #43/#45 Phase B).
|
|
78
76
|
var tx_1 = require("./tx");
|
|
79
77
|
Object.defineProperty(exports, "deriveTransactionPlan", { enumerable: true, get: function () { return tx_1.deriveTransactionPlan; } });
|
|
80
78
|
Object.defineProperty(exports, "deriveBatchPlan", { enumerable: true, get: function () { return tx_1.deriveBatchPlan; } });
|
|
81
79
|
Object.defineProperty(exports, "literalize", { enumerable: true, get: function () { return tx_1.literalize; } });
|
|
82
|
-
Object.defineProperty(exports, "mysqlPkHint", { enumerable: true, get: function () { return tx_1.mysqlPkHint; } });
|
|
83
|
-
Object.defineProperty(exports, "stripMysqlPkHint", { enumerable: true, get: function () { return tx_1.stripMysqlPkHint; } });
|
|
84
80
|
Object.defineProperty(exports, "executeTransaction", { enumerable: true, get: function () { return tx_1.executeTransaction; } });
|
|
81
|
+
Object.defineProperty(exports, "executeTransactionAsync", { enumerable: true, get: function () { return tx_1.executeTransactionAsync; } });
|
|
85
82
|
Object.defineProperty(exports, "countingDriver", { enumerable: true, get: function () { return tx_1.countingDriver; } });
|
|
86
83
|
Object.defineProperty(exports, "renderTxStatement", { enumerable: true, get: function () { return tx_1.renderTxStatement; } });
|
|
87
84
|
Object.defineProperty(exports, "compileWriteNode", { enumerable: true, get: function () { return tx_1.compileWriteNode; } });
|
|
85
|
+
Object.defineProperty(exports, "pgTypeSpecimen", { enumerable: true, get: function () { return tx_1.pgTypeSpecimen; } });
|
|
88
86
|
Object.defineProperty(exports, "IN_SENTINEL", { enumerable: true, get: function () { return tx_1.IN_SENTINEL; } });
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Object.defineProperty(exports, "
|
|
94
|
-
Object.defineProperty(exports, "
|
|
95
|
-
Object.defineProperty(exports, "
|
|
96
|
-
// The STATIC, portable makeSQL bundle + runtime (design #45 owner-confirmed static-bundle):
|
|
97
|
-
// symbolic compile (no concrete input) → deferred value-specs + skip expression, bc-evaluated
|
|
98
|
-
// per-input at runtime. The SOLE makeSQL read/compile path (epic #43/#45 Phase B).
|
|
99
|
-
var static_bundle_1 = require("./static-bundle");
|
|
100
|
-
Object.defineProperty(exports, "compileStaticBundle", { enumerable: true, get: function () { return static_bundle_1.compileStaticBundle; } });
|
|
101
|
-
Object.defineProperty(exports, "compileSelectNode", { enumerable: true, get: function () { return static_bundle_1.compileSelectNode; } });
|
|
102
|
-
Object.defineProperty(exports, "executeStaticBundle", { enumerable: true, get: function () { return static_bundle_1.executeStaticBundle; } });
|
|
103
|
-
Object.defineProperty(exports, "executeStaticWrite", { enumerable: true, get: function () { return static_bundle_1.executeStaticWrite; } });
|
|
104
|
-
Object.defineProperty(exports, "executeReadBehavior", { enumerable: true, get: function () { return static_bundle_1.executeReadBehavior; } });
|
|
105
|
-
Object.defineProperty(exports, "compileReadGraph", { enumerable: true, get: function () { return static_bundle_1.compileReadGraph; } });
|
|
106
|
-
Object.defineProperty(exports, "executeReadGraph", { enumerable: true, get: function () { return static_bundle_1.executeReadGraph; } });
|
|
107
|
-
Object.defineProperty(exports, "executeReadGraphAsync", { enumerable: true, get: function () { return static_bundle_1.executeReadGraphAsync; } });
|
|
108
|
-
Object.defineProperty(exports, "renderReadPrimary", { enumerable: true, get: function () { return static_bundle_1.renderReadPrimary; } });
|
|
87
|
+
// MySQL has no RETURNING: the pk-hint format + the write→re-select derivation the mysql connection
|
|
88
|
+
// adapter (and the 4 native driver ports) share. ONE home for "MySQL cannot RETURN rows".
|
|
89
|
+
var mysql_returning_1 = require("./mysql-returning");
|
|
90
|
+
Object.defineProperty(exports, "mysqlPkHint", { enumerable: true, get: function () { return mysql_returning_1.mysqlPkHint; } });
|
|
91
|
+
Object.defineProperty(exports, "stripMysqlPkHint", { enumerable: true, get: function () { return mysql_returning_1.stripMysqlPkHint; } });
|
|
92
|
+
Object.defineProperty(exports, "buildMysqlReselect", { enumerable: true, get: function () { return mysql_returning_1.buildMysqlReselect; } });
|
|
93
|
+
Object.defineProperty(exports, "bindReselect", { enumerable: true, get: function () { return mysql_returning_1.bindReselect; } });
|
|
109
94
|
// Pooled async executor factories (PG / MySQL) that turn the plan's concurrency into real parallel
|
|
110
95
|
// read-relation DB I/O behind the async seam (#40).
|
|
111
96
|
var pool_executor_1 = require("./pool-executor");
|
|
112
|
-
Object.defineProperty(exports, "
|
|
113
|
-
Object.defineProperty(exports, "
|
|
97
|
+
Object.defineProperty(exports, "configurePgDeboxTypeParsers", { enumerable: true, get: function () { return pool_executor_1.configurePgDeboxTypeParsers; } });
|
|
98
|
+
Object.defineProperty(exports, "mysqlDeboxPoolOptions", { enumerable: true, get: function () { return pool_executor_1.mysqlDeboxPoolOptions; } });
|
|
99
|
+
Object.defineProperty(exports, "pgConnectionPool", { enumerable: true, get: function () { return pool_executor_1.pgConnectionPool; } });
|
|
100
|
+
Object.defineProperty(exports, "mysqlConnectionPool", { enumerable: true, get: function () { return pool_executor_1.mysqlConnectionPool; } });
|
|
101
|
+
Object.defineProperty(exports, "pgPoolFactory", { enumerable: true, get: function () { return pool_executor_1.pgPoolFactory; } });
|
|
102
|
+
Object.defineProperty(exports, "mysqlPoolFactory", { enumerable: true, get: function () { return pool_executor_1.mysqlPoolFactory; } });
|
|
114
103
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scp/makesql/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;AAEH,gCAAgC;AAChC,qCAOmB;AANjB,kGAAA,OAAO,OAAA;AACP,8GAAA,mBAAmB,OAAA;AACnB,sHAAA,2BAA2B,OAAA;AAC3B,oGAAA,SAAS,OAAA;AACT,0GAAA,eAAe,OAAA;AACf,yGAAA,cAAc,OAAA;AAIhB,wCAAwC;AACxC,qCAKmB;AAJjB,6GAAA,kBAAkB,OAAA;AAClB,sGAAA,WAAW,OAAA;AACX,yGAAA,cAAc,OAAA;AACd,6GAAA,kBAAkB,OAAA;AAIpB,yCAAyC;AACzC,qCAOmB;AANjB,uGAAA,YAAY,OAAA;AACZ,sGAAA,WAAW,OAAA;AACX,sGAAA,WAAW,OAAA;AACX,uGAAA,YAAY,OAAA;AACZ,0GAAA,eAAe,OAAA;AACf,0GAAA,eAAe,OAAA;AAGjB,yBAAyB;AACzB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AAGtB,kBAAkB;AAClB,+CAQwB;AAPtB,0GAAA,UAAU,OAAA;AACV,6GAAA,aAAa,OAAA;AACb,iHAAA,iBAAiB,OAAA;AACjB,iHAAA,iBAAiB,OAAA;AACjB,mHAAA,mBAAmB,OAAA;AACnB,6GAAA,aAAa,OAAA;AACb,iH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A;AAAE,iHAAA,gBAAgB,OAAA"}
|
|
@@ -59,6 +59,71 @@ export declare function inListJson(dialect: JsonArrayDialect, col: string, value
|
|
|
59
59
|
sql: string;
|
|
60
60
|
param: string;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* The STATIC, value-length-INDEPENDENT membership predicate for `col` — the ONE place each dialect's
|
|
64
|
+
* single-param IN-list TEXT lives, so a caller never re-spells it:
|
|
65
|
+
*
|
|
66
|
+
* - **PostgreSQL**: `col = ANY(?)` with NO element-type cast (#46). A value-inferred cast is wrong for
|
|
67
|
+
* every column whose type is not recoverable from the values (`inferPgArrayType([])` = `text[]` →
|
|
68
|
+
* `integer = text` on an EMPTY int list; a uuid list is indistinguishable from text) — no-cast lets
|
|
69
|
+
* PG infer the array type FROM THE COLUMN, which is correct for int / uuid / bigint / bool /
|
|
70
|
+
* timestamp / numeric alike. This is the form a GENERATED module needs: one param, fixed text.
|
|
71
|
+
* - **MySQL / SQLite**: the single-JSON `JSON_TABLE` / `json_each` SUBQUERY described above.
|
|
72
|
+
*
|
|
73
|
+
* The IMPERATIVE v1 path is untouched: {@link conditionsFor} still hands PostgreSQL the base
|
|
74
|
+
* `DBConditions`, whose `IN (?, ?, …)` stays byte-identical to v1 (its placeholder count is free to
|
|
75
|
+
* depend on the values because it is built per request).
|
|
76
|
+
*/
|
|
77
|
+
export declare function inListPredicate(dialect: Dialect, col: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* The STATIC composite-key membership predicate — the multi-column sibling of
|
|
80
|
+
* {@link inListPredicate}, with the SAME property: a FIXED number of `?`, independent of how many key
|
|
81
|
+
* tuples are bound.
|
|
82
|
+
*
|
|
83
|
+
* - **PostgreSQL**: `(t.k1, t.k2) IN (SELECT * FROM UNNEST(?::<T1>, ?::<T2>))` — ONE array param PER
|
|
84
|
+
* key column (the constant-param form; v1's `dbTupleIn` binds 2×N params instead, which is the
|
|
85
|
+
* degradation this replaces). `UNNEST` needs its argument types, so `pgElementTypes` supplies one
|
|
86
|
+
* per key column, derived from the SCHEMA (the declared column type). Deriving them from the VALUES
|
|
87
|
+
* is not an option here: an EMPTY key set infers `text[]` and the statement fails
|
|
88
|
+
* `operator does not exist: integer = text` at plan time — the same trap #46 hit on the single-key
|
|
89
|
+
* IN-list, which could drop the cast entirely because `= ANY` infers from the column while `UNNEST`
|
|
90
|
+
* cannot. Omitting them falls back to the deferred
|
|
91
|
+
* {@link import('./compile-relation').PG_ARRAY_CAST_TOKEN} (resolved from the bound values).
|
|
92
|
+
* - **MySQL / SQLite**: ONE JSON array-of-tuples param read back by ORDINAL path — MySQL a
|
|
93
|
+
* `JSON_TABLE` IN-subquery (so it inherits `(k1,k2) IN ((?,?),…)`'s per-column coercion), SQLite a
|
|
94
|
+
* `json_each` IN-subquery projecting the tuple's ordinal paths.
|
|
95
|
+
*
|
|
96
|
+
* Every dialect's form is an IN over a subquery the planner evaluates ONCE — the whole point of binding
|
|
97
|
+
* the key set as a single param. A CORRELATED predicate over the same param (an `EXISTS` whose body
|
|
98
|
+
* compares against the outer row) re-expands the key set for every outer row and leaves the key columns
|
|
99
|
+
* unusable as an index lookup, so the batch load degrades as rows × keys.
|
|
100
|
+
*
|
|
101
|
+
* This is the ONE text for composite membership: the relation batch builders
|
|
102
|
+
* ({@link import('./compile-relation').compileCompositeKeyStaticUnlimited}) consume the same function.
|
|
103
|
+
*/
|
|
104
|
+
export declare function tupleInPredicate(dialect: Dialect, table: string, columns: readonly string[], pgElementTypes?: readonly string[]): string;
|
|
105
|
+
/**
|
|
106
|
+
* Encode an array as the ONE JSON param a server-side form expands — the SINGLE array encoder, shared
|
|
107
|
+
* by {@link inListJson} (the imperative path) and the leaf transport's `encodeParams` (the generated
|
|
108
|
+
* path), so the two can never diverge. MySQL/SQLite bind every array this way; PostgreSQL binds its
|
|
109
|
+
* scalar arrays natively and only its composite key TUPLE sets here ({@link tupleInPredicate} /
|
|
110
|
+
* the composite relation batch):
|
|
111
|
+
*
|
|
112
|
+
* - a bc `int` arrives as a `BigInt`, which `JSON.stringify` cannot emit → coerced to a JSON number
|
|
113
|
+
* (`json_each` / `JSON_TABLE` compare numerically);
|
|
114
|
+
* - a BOOLEAN element serializes to `1`/`0` on MySQL, NOT JSON `true`/`false`: `JSON_UNQUOTE(v)` on
|
|
115
|
+
* JSON `true` yields the STRING `'true'`, which MySQL coerces to `0` against a TINYINT(1) — silently
|
|
116
|
+
* mismatching. `1`/`0` is exactly what v1's `col IN (?)` bound (mysql2 sends a JS bool as `1`/`0`).
|
|
117
|
+
* SQLite's `json_each` coerces JSON booleans natively, so it keeps them as-is.
|
|
118
|
+
*/
|
|
119
|
+
export declare function encodeJsonArrayParam(dialect: Dialect, values: readonly unknown[]): string;
|
|
120
|
+
/**
|
|
121
|
+
* The ONE JSON-param serializer every single-JSON-param form goes through — the array/tuple sets here and
|
|
122
|
+
* the batch record sets in {@link import('./json-batch')} alike. Both bind values that came OFF a read, so
|
|
123
|
+
* both meet the same two cases (a bc `int` is a `BigInt`, which `JSON.stringify` refuses; a MySQL boolean
|
|
124
|
+
* must ride as 1/0), and a second bare `JSON.stringify` would silently diverge on either.
|
|
125
|
+
*/
|
|
126
|
+
export declare function encodeJsonParam(dialect: Dialect, payload: unknown): string;
|
|
62
127
|
/**
|
|
63
128
|
* A dialect-aware `DBConditions` for MySQL/SQLite that replaces the v1 N-placeholder
|
|
64
129
|
* IN-list (`col IN (?, ?, …)`) with the single-JSON-param form (see {@link inListJson}).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-array.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/json-array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"json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AAC,QAAQ,CAAmB;gBAEhC,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,GAAE,KAAK,GAAG,IAAY;IAKlG,SAAS,CAAC,gBAAgB,CACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,OAAO,EAAE,EACjB,SAAS,CAAC,EAAE,gBAAgB,GAC3B,MAAM;CAiBV;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,GAAG,YAAY,CAGzF"}
|
|
@@ -31,9 +31,14 @@
|
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.JsonArrayConditions = void 0;
|
|
33
33
|
exports.inListJson = inListJson;
|
|
34
|
+
exports.inListPredicate = inListPredicate;
|
|
35
|
+
exports.tupleInPredicate = tupleInPredicate;
|
|
36
|
+
exports.encodeJsonArrayParam = encodeJsonArrayParam;
|
|
37
|
+
exports.encodeJsonParam = encodeJsonParam;
|
|
34
38
|
exports.conditionsFor = conditionsFor;
|
|
35
39
|
const DBConditions_1 = require("../../DBConditions");
|
|
36
40
|
const DBValues_1 = require("../../DBValues");
|
|
41
|
+
const compile_relation_1 = require("./compile-relation");
|
|
37
42
|
/**
|
|
38
43
|
* The MySQL/SQLite IN-list JSON form for a plain `col IN [values]` condition — a
|
|
39
44
|
* SUBQUERY form so it inherits the SAME comparison rules as v1's `col IN (list)`
|
|
@@ -58,18 +63,102 @@ const DBValues_1 = require("../../DBValues");
|
|
|
58
63
|
* MySQL 8 + SQLite in `test/scp/json-array-parity.test.ts`.
|
|
59
64
|
*/
|
|
60
65
|
function inListJson(dialect, col, values) {
|
|
66
|
+
return { sql: inListPredicate(dialect, col), param: encodeJsonArrayParam(dialect, values) };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The STATIC, value-length-INDEPENDENT membership predicate for `col` — the ONE place each dialect's
|
|
70
|
+
* single-param IN-list TEXT lives, so a caller never re-spells it:
|
|
71
|
+
*
|
|
72
|
+
* - **PostgreSQL**: `col = ANY(?)` with NO element-type cast (#46). A value-inferred cast is wrong for
|
|
73
|
+
* every column whose type is not recoverable from the values (`inferPgArrayType([])` = `text[]` →
|
|
74
|
+
* `integer = text` on an EMPTY int list; a uuid list is indistinguishable from text) — no-cast lets
|
|
75
|
+
* PG infer the array type FROM THE COLUMN, which is correct for int / uuid / bigint / bool /
|
|
76
|
+
* timestamp / numeric alike. This is the form a GENERATED module needs: one param, fixed text.
|
|
77
|
+
* - **MySQL / SQLite**: the single-JSON `JSON_TABLE` / `json_each` SUBQUERY described above.
|
|
78
|
+
*
|
|
79
|
+
* The IMPERATIVE v1 path is untouched: {@link conditionsFor} still hands PostgreSQL the base
|
|
80
|
+
* `DBConditions`, whose `IN (?, ?, …)` stays byte-identical to v1 (its placeholder count is free to
|
|
81
|
+
* depend on the values because it is built per request).
|
|
82
|
+
*/
|
|
83
|
+
function inListPredicate(dialect, col) {
|
|
84
|
+
if (dialect === 'postgres')
|
|
85
|
+
return `${col} = ANY(?)`;
|
|
86
|
+
if (dialect === 'mysql')
|
|
87
|
+
return `${col} IN (SELECT JSON_UNQUOTE(v) FROM JSON_TABLE(?, '$[*]' COLUMNS(v JSON PATH '$')) jt)`;
|
|
88
|
+
return `${col} IN (SELECT value FROM json_each(?))`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The STATIC composite-key membership predicate — the multi-column sibling of
|
|
92
|
+
* {@link inListPredicate}, with the SAME property: a FIXED number of `?`, independent of how many key
|
|
93
|
+
* tuples are bound.
|
|
94
|
+
*
|
|
95
|
+
* - **PostgreSQL**: `(t.k1, t.k2) IN (SELECT * FROM UNNEST(?::<T1>, ?::<T2>))` — ONE array param PER
|
|
96
|
+
* key column (the constant-param form; v1's `dbTupleIn` binds 2×N params instead, which is the
|
|
97
|
+
* degradation this replaces). `UNNEST` needs its argument types, so `pgElementTypes` supplies one
|
|
98
|
+
* per key column, derived from the SCHEMA (the declared column type). Deriving them from the VALUES
|
|
99
|
+
* is not an option here: an EMPTY key set infers `text[]` and the statement fails
|
|
100
|
+
* `operator does not exist: integer = text` at plan time — the same trap #46 hit on the single-key
|
|
101
|
+
* IN-list, which could drop the cast entirely because `= ANY` infers from the column while `UNNEST`
|
|
102
|
+
* cannot. Omitting them falls back to the deferred
|
|
103
|
+
* {@link import('./compile-relation').PG_ARRAY_CAST_TOKEN} (resolved from the bound values).
|
|
104
|
+
* - **MySQL / SQLite**: ONE JSON array-of-tuples param read back by ORDINAL path — MySQL a
|
|
105
|
+
* `JSON_TABLE` IN-subquery (so it inherits `(k1,k2) IN ((?,?),…)`'s per-column coercion), SQLite a
|
|
106
|
+
* `json_each` IN-subquery projecting the tuple's ordinal paths.
|
|
107
|
+
*
|
|
108
|
+
* Every dialect's form is an IN over a subquery the planner evaluates ONCE — the whole point of binding
|
|
109
|
+
* the key set as a single param. A CORRELATED predicate over the same param (an `EXISTS` whose body
|
|
110
|
+
* compares against the outer row) re-expands the key set for every outer row and leaves the key columns
|
|
111
|
+
* unusable as an index lookup, so the batch load degrades as rows × keys.
|
|
112
|
+
*
|
|
113
|
+
* This is the ONE text for composite membership: the relation batch builders
|
|
114
|
+
* ({@link import('./compile-relation').compileCompositeKeyStaticUnlimited}) consume the same function.
|
|
115
|
+
*/
|
|
116
|
+
function tupleInPredicate(dialect, table, columns, pgElementTypes) {
|
|
117
|
+
const qualified = columns.map((k) => `${table}.${k}`);
|
|
118
|
+
if (dialect === 'postgres') {
|
|
119
|
+
const unnest = columns.map((_, i) => `?::${pgElementTypes?.[i] ?? compile_relation_1.PG_ARRAY_CAST_TOKEN}`).join(', ');
|
|
120
|
+
return `(${qualified.join(', ')}) IN (SELECT * FROM UNNEST(${unnest}))`;
|
|
121
|
+
}
|
|
61
122
|
if (dialect === 'mysql') {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// against a TINYINT(1) — silently mismatching. `1`/`0` is exactly what v1's `col IN (?)`
|
|
67
|
-
// bound (the mysql2 driver sends a JS bool as `1`/`0`), so this keeps v1 RESULT parity. SQL
|
|
68
|
-
// text + PG are untouched; SQLite's `json_each` coerces JSON booleans natively (no change).
|
|
69
|
-
param: JSON.stringify(values.map((v) => (typeof v === 'boolean' ? (v ? 1 : 0) : v))),
|
|
70
|
-
};
|
|
123
|
+
const cols = columns.map((_, i) => `c${i}`);
|
|
124
|
+
const jtCols = cols.map((c, i) => `${c} JSON PATH '$[${i}]'`).join(', ');
|
|
125
|
+
const selectCols = cols.map((c) => `JSON_UNQUOTE(${c})`).join(', ');
|
|
126
|
+
return `(${qualified.join(', ')}) IN (SELECT ${selectCols} FROM JSON_TABLE(?, '$[*]' COLUMNS(${jtCols})) jt)`;
|
|
71
127
|
}
|
|
72
|
-
|
|
128
|
+
const projected = columns.map((_, i) => `json_extract(value, '$[${i}]')`).join(', ');
|
|
129
|
+
return `(${qualified.join(', ')}) IN (SELECT ${projected} FROM json_each(?))`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Encode an array as the ONE JSON param a server-side form expands — the SINGLE array encoder, shared
|
|
133
|
+
* by {@link inListJson} (the imperative path) and the leaf transport's `encodeParams` (the generated
|
|
134
|
+
* path), so the two can never diverge. MySQL/SQLite bind every array this way; PostgreSQL binds its
|
|
135
|
+
* scalar arrays natively and only its composite key TUPLE sets here ({@link tupleInPredicate} /
|
|
136
|
+
* the composite relation batch):
|
|
137
|
+
*
|
|
138
|
+
* - a bc `int` arrives as a `BigInt`, which `JSON.stringify` cannot emit → coerced to a JSON number
|
|
139
|
+
* (`json_each` / `JSON_TABLE` compare numerically);
|
|
140
|
+
* - a BOOLEAN element serializes to `1`/`0` on MySQL, NOT JSON `true`/`false`: `JSON_UNQUOTE(v)` on
|
|
141
|
+
* JSON `true` yields the STRING `'true'`, which MySQL coerces to `0` against a TINYINT(1) — silently
|
|
142
|
+
* mismatching. `1`/`0` is exactly what v1's `col IN (?)` bound (mysql2 sends a JS bool as `1`/`0`).
|
|
143
|
+
* SQLite's `json_each` coerces JSON booleans natively, so it keeps them as-is.
|
|
144
|
+
*/
|
|
145
|
+
function encodeJsonArrayParam(dialect, values) {
|
|
146
|
+
return encodeJsonParam(dialect, values);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The ONE JSON-param serializer every single-JSON-param form goes through — the array/tuple sets here and
|
|
150
|
+
* the batch record sets in {@link import('./json-batch')} alike. Both bind values that came OFF a read, so
|
|
151
|
+
* both meet the same two cases (a bc `int` is a `BigInt`, which `JSON.stringify` refuses; a MySQL boolean
|
|
152
|
+
* must ride as 1/0), and a second bare `JSON.stringify` would silently diverge on either.
|
|
153
|
+
*/
|
|
154
|
+
function encodeJsonParam(dialect, payload) {
|
|
155
|
+
return JSON.stringify(payload, (_key, v) => {
|
|
156
|
+
if (typeof v === 'bigint')
|
|
157
|
+
return Number(v);
|
|
158
|
+
if (dialect === 'mysql' && typeof v === 'boolean')
|
|
159
|
+
return v ? 1 : 0;
|
|
160
|
+
return v;
|
|
161
|
+
});
|
|
73
162
|
}
|
|
74
163
|
/**
|
|
75
164
|
* A dialect-aware `DBConditions` for MySQL/SQLite that replaces the v1 N-placeholder
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-array.js","sourceRoot":"","sources":["../../../src/scp/makesql/json-array.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;
|
|
1
|
+
{"version":3,"file":"json-array.js","sourceRoot":"","sources":["../../../src/scp/makesql/json-array.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAkCH,gCAEC;AAiBD,0CAIC;AA4BD,4CAcC;AAgBD,oDAEC;AAQD,0CAMC;AAkDD,sCAGC;AAtLD,qDAA6F;AAC7F,6CAAyC;AAEzC,yDAAyD;AAMzD;;;;;;;;;;;;;;;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,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACnC,oFAAoF;IACpF,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CA6CxE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAyCzE"}
|
|
@@ -28,6 +28,7 @@ exports.sqliteInsertJson = sqliteInsertJson;
|
|
|
28
28
|
exports.mysqlUpdateManyJson = mysqlUpdateManyJson;
|
|
29
29
|
exports.sqliteUpdateManyJson = sqliteUpdateManyJson;
|
|
30
30
|
const DBValues_1 = require("../../DBValues");
|
|
31
|
+
const json_array_1 = require("./json-array");
|
|
31
32
|
/** True if any row carries a DBToken value (can't be JSON-encoded → v1 fallback). */
|
|
32
33
|
function rowsHaveDbToken(rows, columns) {
|
|
33
34
|
for (const r of rows) {
|
|
@@ -83,14 +84,14 @@ function mysqlJsonTableColumn(col, rows) {
|
|
|
83
84
|
* string element, matching what v1 binds. `undefined` cells are dropped (the group is
|
|
84
85
|
* homogeneous by construction, so every column is present in every row).
|
|
85
86
|
*/
|
|
86
|
-
function rowsToJson(rows, columns) {
|
|
87
|
+
function rowsToJson(dialect, rows, columns) {
|
|
87
88
|
const objects = rows.map((r) => {
|
|
88
89
|
const o = {};
|
|
89
90
|
for (const c of columns)
|
|
90
91
|
o[c] = r[c] === undefined ? null : r[c];
|
|
91
92
|
return o;
|
|
92
93
|
});
|
|
93
|
-
return
|
|
94
|
+
return (0, json_array_1.encodeJsonParam)(dialect, objects);
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* Build the MySQL single-JSON-param batch INSERT. `INSERT [IGNORE] INTO t (cols)
|
|
@@ -105,7 +106,7 @@ function mysqlInsertJson(opts) {
|
|
|
105
106
|
jtCols.push(`${col} ${colType} PATH '$.${col}'`);
|
|
106
107
|
selectExprs.push(selectExpr(`jt.${col}`));
|
|
107
108
|
}
|
|
108
|
-
const jsonParam = rowsToJson(records, columns);
|
|
109
|
+
const jsonParam = rowsToJson('mysql', records, columns);
|
|
109
110
|
const source = `SELECT ${selectExprs.join(', ')} ` +
|
|
110
111
|
`FROM JSON_TABLE(?, '$[*]' COLUMNS(${jtCols.join(', ')})) jt`;
|
|
111
112
|
let sql;
|
|
@@ -132,7 +133,7 @@ function mysqlInsertJson(opts) {
|
|
|
132
133
|
function sqliteInsertJson(opts) {
|
|
133
134
|
const { tableName, columns, records, onConflict, onConflictIgnore, onConflictUpdate, returning } = opts;
|
|
134
135
|
const selectExprs = columns.map((c) => `json_extract(value, '$.${c}')`);
|
|
135
|
-
const jsonParam = rowsToJson(records, columns);
|
|
136
|
+
const jsonParam = rowsToJson('sqlite', records, columns);
|
|
136
137
|
const source = `SELECT ${selectExprs.join(', ')} FROM json_each(?)`;
|
|
137
138
|
let sql;
|
|
138
139
|
if (onConflict && onConflictIgnore) {
|
|
@@ -141,7 +142,12 @@ function sqliteInsertJson(opts) {
|
|
|
141
142
|
else if (onConflict && onConflictUpdate) {
|
|
142
143
|
const updateCols = onConflictUpdate === 'all' ? columns : onConflictUpdate;
|
|
143
144
|
const updateClauses = updateCols.map((c) => `${c} = excluded.${c}`);
|
|
144
|
-
|
|
145
|
+
// SQLite grammar disambiguation (#67): in an `INSERT … SELECT … ON CONFLICT … DO UPDATE`, the
|
|
146
|
+
// parser cannot tell whether `ON CONFLICT` binds to the SELECT's source or is the upsert clause
|
|
147
|
+
// unless a `WHERE` terminates the SELECT — without it SQLite raises `near "DO": syntax error`.
|
|
148
|
+
// A `WHERE true` is the standard, semantically-neutral terminator (SQLite docs "Parsing Ambiguity").
|
|
149
|
+
// Only this SELECT-sourced upsert path needs it; `INSERT OR IGNORE` and the plain INSERT do not.
|
|
150
|
+
sql = `INSERT INTO ${tableName} (${columns.join(', ')}) ${source} WHERE true ON CONFLICT (${onConflict.join(', ')}) DO UPDATE SET ${updateClauses.join(', ')}`;
|
|
145
151
|
}
|
|
146
152
|
else {
|
|
147
153
|
sql = `INSERT INTO ${tableName} (${columns.join(', ')}) ${source}`;
|
|
@@ -176,7 +182,7 @@ function mysqlUpdateManyJson(opts) {
|
|
|
176
182
|
o[`_skip_${c}`] = skipMap.get(i)?.has(c) ? 1 : 0;
|
|
177
183
|
return o;
|
|
178
184
|
});
|
|
179
|
-
const jsonParam =
|
|
185
|
+
const jsonParam = (0, json_array_1.encodeJsonParam)('mysql', payload);
|
|
180
186
|
const jtCols = [];
|
|
181
187
|
const selectExprOf = new Map();
|
|
182
188
|
for (const col of allColumns) {
|
|
@@ -238,7 +244,7 @@ function sqliteUpdateManyJson(opts) {
|
|
|
238
244
|
o[`_skip_${c}`] = skipMap.get(i)?.has(c) ? 1 : 0;
|
|
239
245
|
return o;
|
|
240
246
|
});
|
|
241
|
-
const jsonParam =
|
|
247
|
+
const jsonParam = (0, json_array_1.encodeJsonParam)('sqlite', payload);
|
|
242
248
|
const params = [];
|
|
243
249
|
const keyMatch = keyColumns.map((k) => `json_extract(je.value, '$.${k}') = ${tableName}.${k}`).join(' AND ');
|
|
244
250
|
const setClauses = updateColumns.map((col) => {
|
|
@@ -249,18 +255,14 @@ function sqliteUpdateManyJson(opts) {
|
|
|
249
255
|
return (`${col} = (SELECT ${valueExpr} FROM json_each(?) je ` +
|
|
250
256
|
`WHERE ${keyMatch} LIMIT 1)`);
|
|
251
257
|
});
|
|
252
|
-
// WHERE: restrict to the affected keys
|
|
253
|
-
// EXISTS
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
params.push(jsonParam);
|
|
261
|
-
const match = keyColumns.map((k) => `json_extract(je.value, '$.${k}') = ${tableName}.${k}`).join(' AND ');
|
|
262
|
-
whereClause = `EXISTS (SELECT 1 FROM json_each(?) je WHERE ${match})`;
|
|
263
|
-
}
|
|
258
|
+
// WHERE: restrict to the affected keys — an IN over a subquery evaluated ONCE, single or composite.
|
|
259
|
+
// A correlated `EXISTS (… WHERE json_extract(je.value,'$.k') = t.k)` re-expands the batch for every
|
|
260
|
+
// row of the table and makes the key columns unusable as an index lookup, which is the whole point of
|
|
261
|
+
// restricting by them.
|
|
262
|
+
params.push(jsonParam);
|
|
263
|
+
const projected = keyColumns.map((k) => `json_extract(value, '$.${k}')`).join(', ');
|
|
264
|
+
const target = keyColumns.length === 1 ? keyColumns[0] : `(${keyColumns.map((k) => `${tableName}.${k}`).join(', ')})`;
|
|
265
|
+
const whereClause = `${target} IN (SELECT ${projected} FROM json_each(?))`;
|
|
264
266
|
let sql = `UPDATE ${tableName} SET ${setClauses.join(', ')} WHERE ${whereClause}`;
|
|
265
267
|
if (returning)
|
|
266
268
|
sql += ` RETURNING ${returning}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-batch.js","sourceRoot":"","sources":["../../../src/scp/makesql/json-batch.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;
|
|
1
|
+
{"version":3,"file":"json-batch.js","sourceRoot":"","sources":["../../../src/scp/makesql/json-batch.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAWH,0CAOC;AAgBD,oDA0BC;AAoCD,0CA0BC;AAOD,4CAuBC;AAyBD,kDA6CC;AAmBD,oDAyCC;AAxRD,6CAAyC;AACzC,6CAA+C;AAO/C,qFAAqF;AACrF,SAAgB,eAAe,CAAC,IAA+B,EAAE,OAAiB;IAChF,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,CAAC,CAA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Q,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,WAAW,EAAE,CAAC;IAClF,IAAI,SAAS;QAAE,GAAG,IAAI,cAAc,SAAS,EAAE,CAAC;IAChD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* composition / value-eval / envelope / plan (it comes free once queries are `makeSQL`
|
|
30
30
|
* components). The bundle stays pure JSON (multi-language ready).
|
|
31
31
|
*/
|
|
32
|
-
import type { CatalogEntry } from 'behavior-contracts';
|
|
32
|
+
import type { CatalogEntry } from 'behavior-contracts/runtime';
|
|
33
33
|
/** The single catalog leaf name. Everything SQL is a `makeSQL`. */
|
|
34
34
|
export declare const MAKESQL: "makeSQL";
|
|
35
35
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makesql.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/makesql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"makesql.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/makesql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,mEAAmE;AACnE,eAAO,MAAM,OAAO,EAAG,SAAkB,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,IAAI,OAAO,CAOnD;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,YASjC,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAEpE,CAAC;AAWF,wFAAwF;AACxF,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAwB3D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,YAAY,CAS7D"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* litedbmodel v2 SCP — **MySQL has no `RETURNING`**: the one place that knowledge lives.
|
|
3
|
+
*
|
|
4
|
+
* A write compiled for the `mysql` dialect carries the SAME ` RETURNING <cols>` tail as the PG /
|
|
5
|
+
* SQLite bundles (the compilers are dialect-neutral about it), plus a strip-before-execute
|
|
6
|
+
* `/*scp:pk=…;ai=…[;conflict=…]* /` comment naming the target's REAL primary key. MySQL parses
|
|
7
|
+
* neither, so the driver seam STRIPS both and recovers the written rows with a SELECT keyed on
|
|
8
|
+
* whatever identifies them:
|
|
9
|
+
*
|
|
10
|
+
* | write | the rows are recovered by | when |
|
|
11
|
+
* |------------------|--------------------------------------------------------------------|-----------|
|
|
12
|
+
* | create | the AUTO_INCREMENT range `[LAST_INSERT_ID, +affected)`, or the | after |
|
|
13
|
+
* | | client-supplied PK values pulled from the INSERT params by position | |
|
|
14
|
+
* | createMany | the same AUTO_INCREMENT range (N consecutive ids) | after |
|
|
15
|
+
* | upsert / …Many | the CONFLICT key (MySQL does not report the conflicted-row id, so | after |
|
|
16
|
+
* | | the AUTO_INCREMENT range is wrong when a row was UPDATED) | |
|
|
17
|
+
* | update | the write's OWN WHERE predicate | after |
|
|
18
|
+
* | updateMany | the batch JOIN key, re-bound from the SAME JSON payload | after |
|
|
19
|
+
* | delete/deleteMany| the write's OWN WHERE predicate — **before** the write, since the | BEFORE |
|
|
20
|
+
* | | rows no longer exist once the DELETE has run | |
|
|
21
|
+
*
|
|
22
|
+
* The recovering SELECT runs on the SAME connection as the write, so inside a transaction it sees
|
|
23
|
+
* the not-yet-committed rows — and a `DELETE`'s pre-image SELECT is inside the same transaction as
|
|
24
|
+
* the delete it describes.
|
|
25
|
+
*
|
|
26
|
+
* This module is the TypeScript member of a 5-language SSoT: `rust/litedbmodel_runtime/src/livedb.rs`
|
|
27
|
+
* (`build_mysql_reselect`), `go/litedbmodel_runtime/livedb.go`, `python/litedbmodel_runtime/driver.py`
|
|
28
|
+
* and `php/src/LiveDb.php` derive the identical write/select/bind triple. Both TS execution paths —
|
|
29
|
+
* the generated (codegen) leaf `executeSQL` and the mode-2 transaction plan — reach it through the
|
|
30
|
+
* ONE mysql connection adapter (`pool-executor.mysqlConnection`), so they cannot return different rows.
|
|
31
|
+
*/
|
|
32
|
+
import type { TxOp } from './tx';
|
|
33
|
+
/**
|
|
34
|
+
* Serialize a {@link TxOp.pk} descriptor into a strip-before-execute SQL comment appended to an
|
|
35
|
+
* INSERT…RETURNING op, so the MySQL driver emulation can re-select by the REAL primary key. The
|
|
36
|
+
* comment is STRIPPED (with the RETURNING clause) before the write executes, so the executed SQL
|
|
37
|
+
* stays byte-clean; it is emitted ONLY into the mysql-dialect bundle (PG/SQLite keep native
|
|
38
|
+
* RETURNING and never see it). Format: ` /*scp:pk=col1,col2;ai=<autoIncCol|>[;conflict=<cols>]* /`.
|
|
39
|
+
*
|
|
40
|
+
* `conflict` (the upsert conflict-target column list) is added when the write is an upsert — the mysql
|
|
41
|
+
* driver re-selects the upserted row(s) by that key. Its source is `op.writeMeta.onConflict` (single
|
|
42
|
+
* writes carry it); an ad-hoc TxOp built without writeMeta (the batch createMany/upsertMany path)
|
|
43
|
+
* passes the columns via `onConflict`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mysqlPkHint(op: TxOp, onConflict?: string): TxOp;
|
|
46
|
+
/** Strip a trailing MySQL PK-hint comment from a rendered SQL (defensive; runtimes strip too). */
|
|
47
|
+
export declare function stripMysqlPkHint(sql: string): string;
|
|
48
|
+
/** How ONE `?` of the recovering SELECT is bound. */
|
|
49
|
+
export type ReselectBind =
|
|
50
|
+
/** `LAST_INSERT_ID()` — the FIRST AUTO_INCREMENT id the INSERT allocated. */
|
|
51
|
+
{
|
|
52
|
+
readonly kind: 'lastId';
|
|
53
|
+
}
|
|
54
|
+
/** `LAST_INSERT_ID() + affected` — the EXCLUSIVE upper bound of the inserted id range. */
|
|
55
|
+
| {
|
|
56
|
+
readonly kind: 'highId';
|
|
57
|
+
}
|
|
58
|
+
/** The batch JSON payload (`params[0]`) re-bound to the SELECT's own `JSON_TABLE(?)`. */
|
|
59
|
+
| {
|
|
60
|
+
readonly kind: 'json';
|
|
61
|
+
}
|
|
62
|
+
/** The write's own bound param at this index (a WHERE value, or a conflict/PK value by column position). */
|
|
63
|
+
| {
|
|
64
|
+
readonly kind: 'param';
|
|
65
|
+
readonly index: number;
|
|
66
|
+
};
|
|
67
|
+
/** The MySQL RETURNING recovery derived from a write's baked SQL + its `/*scp:pk=…* /` hint. */
|
|
68
|
+
export interface MysqlReselect {
|
|
69
|
+
/** The write to execute — RETURNING clause and hint removed, byte-clean for the prepared protocol. */
|
|
70
|
+
readonly writeSql: string;
|
|
71
|
+
/** `SELECT <returning cols> FROM <table> WHERE <key predicate>[ ORDER BY <pk>]`. */
|
|
72
|
+
readonly selectSql: string;
|
|
73
|
+
/** How to bind {@link selectSql}'s `?`s. */
|
|
74
|
+
readonly binds: readonly ReselectBind[];
|
|
75
|
+
/**
|
|
76
|
+
* Run the SELECT BEFORE the write instead of after. Only a DELETE needs this: its rows are gone
|
|
77
|
+
* once it has run, so the pre-image IS the written row set (the same rows the DELETE removes).
|
|
78
|
+
*/
|
|
79
|
+
readonly before: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Derive the MySQL RETURNING recovery for `sql`, or `null` when the statement declares no RETURNING
|
|
83
|
+
* (a plain write / a SELECT — the caller runs it unchanged).
|
|
84
|
+
*
|
|
85
|
+
* Fail-closed: a RETURNING write whose key cannot be identified (an upsert with no `conflict=` hint,
|
|
86
|
+
* an INSERT whose declared PK column is not in its column list, an UPDATE/DELETE with no WHERE)
|
|
87
|
+
* THROWS rather than silently returning no rows — returning `[]` for a write the caller asked to
|
|
88
|
+
* describe is exactly the defect this module exists to remove.
|
|
89
|
+
*/
|
|
90
|
+
export declare function buildMysqlReselect(sql: string): MysqlReselect | null;
|
|
91
|
+
/** Bind {@link MysqlReselect.binds} against the write's params + the write's own result. */
|
|
92
|
+
export declare function bindReselect(binds: readonly ReselectBind[], params: readonly unknown[], lastInsertId: number, affected: number): unknown[];
|
|
93
|
+
//# sourceMappingURL=mysql-returning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql-returning.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/mysql-returning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAKjC;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAQ/D;AAED,kGAAkG;AAClG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAID,qDAAqD;AACrD,MAAM,MAAM,YAAY;AACtB,6EAA6E;AAC3E;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE;AAC7B,0FAA0F;GACxF;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,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