litedbmodel 2.2.7 → 2.2.9

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.
Files changed (120) hide show
  1. package/README.md +2 -1
  2. package/dist/Column.d.ts +13 -2
  3. package/dist/Column.d.ts.map +1 -1
  4. package/dist/Column.js +30 -10
  5. package/dist/Column.js.map +1 -1
  6. package/dist/DBModel.d.ts +15 -2
  7. package/dist/DBModel.d.ts.map +1 -1
  8. package/dist/DBModel.js +40 -25
  9. package/dist/DBModel.js.map +1 -1
  10. package/dist/TypeCast.d.ts +2 -2
  11. package/dist/TypeCast.d.ts.map +1 -1
  12. package/dist/TypeCast.js +7 -9
  13. package/dist/TypeCast.js.map +1 -1
  14. package/dist/decorators.d.ts +10 -1
  15. package/dist/decorators.d.ts.map +1 -1
  16. package/dist/decorators.js +38 -23
  17. package/dist/decorators.js.map +1 -1
  18. package/dist/drivers/MysqlHelper.d.ts +3 -3
  19. package/dist/drivers/MysqlHelper.d.ts.map +1 -1
  20. package/dist/drivers/MysqlHelper.js +3 -17
  21. package/dist/drivers/MysqlHelper.js.map +1 -1
  22. package/dist/drivers/MysqlSqlBuilder.d.ts.map +1 -1
  23. package/dist/drivers/MysqlSqlBuilder.js +2 -13
  24. package/dist/drivers/MysqlSqlBuilder.js.map +1 -1
  25. package/dist/drivers/PostgresHelper.d.ts +3 -2
  26. package/dist/drivers/PostgresHelper.d.ts.map +1 -1
  27. package/dist/drivers/PostgresHelper.js +3 -16
  28. package/dist/drivers/PostgresHelper.js.map +1 -1
  29. package/dist/drivers/PostgresSqlBuilder.d.ts.map +1 -1
  30. package/dist/drivers/PostgresSqlBuilder.js +2 -14
  31. package/dist/drivers/PostgresSqlBuilder.js.map +1 -1
  32. package/dist/drivers/SqliteHelper.d.ts +4 -2
  33. package/dist/drivers/SqliteHelper.d.ts.map +1 -1
  34. package/dist/drivers/SqliteHelper.js +4 -2
  35. package/dist/drivers/SqliteHelper.js.map +1 -1
  36. package/dist/drivers/SqliteSqlBuilder.d.ts.map +1 -1
  37. package/dist/drivers/SqliteSqlBuilder.js +2 -13
  38. package/dist/drivers/SqliteSqlBuilder.js.map +1 -1
  39. package/dist/index.cjs +670 -687
  40. package/dist/scp/decorator-adapter.d.ts +1 -0
  41. package/dist/scp/decorator-adapter.d.ts.map +1 -1
  42. package/dist/scp/decorator-adapter.js +2 -0
  43. package/dist/scp/decorator-adapter.js.map +1 -1
  44. package/dist/scp/index.cjs +63 -52
  45. package/dist/scp/index.mjs +63 -52
  46. package/docs/BENCHMARK.md +1 -1
  47. package/docs/COMPARISON.md +1 -1
  48. package/docs/api/README.md +1 -1
  49. package/docs/api/classes/Conditions.md +10 -10
  50. package/docs/api/classes/DBHandler.md +1 -1
  51. package/docs/api/classes/DBModel.md +81 -81
  52. package/docs/api/classes/LimitExceededError.md +1 -1
  53. package/docs/api/classes/Middleware.md +1 -1
  54. package/docs/api/classes/SqlRaw.md +1 -1
  55. package/docs/api/classes/SqlRef.md +1 -1
  56. package/docs/api/classes/Values.md +6 -6
  57. package/docs/api/classes/WriteInReadOnlyContextError.md +1 -1
  58. package/docs/api/classes/WriteOutsideTransactionError.md +1 -1
  59. package/docs/api/functions/belongsTo.md +2 -2
  60. package/docs/api/functions/closeAllPools.md +1 -1
  61. package/docs/api/functions/condsToRecord.md +4 -3
  62. package/docs/api/functions/createMiddleware.md +1 -1
  63. package/docs/api/functions/createPostgresDriver.md +1 -1
  64. package/docs/api/functions/createSqliteDriver.md +1 -1
  65. package/docs/api/functions/dbCast.md +1 -1
  66. package/docs/api/functions/dbCastIn.md +1 -1
  67. package/docs/api/functions/dbDynamic.md +1 -1
  68. package/docs/api/functions/dbFalse.md +1 -1
  69. package/docs/api/functions/dbImmediate.md +1 -1
  70. package/docs/api/functions/dbIn.md +1 -1
  71. package/docs/api/functions/dbNotNull.md +1 -1
  72. package/docs/api/functions/dbNow.md +1 -1
  73. package/docs/api/functions/dbNull.md +1 -1
  74. package/docs/api/functions/dbRaw.md +1 -1
  75. package/docs/api/functions/dbTrue.md +1 -1
  76. package/docs/api/functions/dbUuid.md +1 -1
  77. package/docs/api/functions/dbUuidIn.md +1 -1
  78. package/docs/api/functions/formatLocalDate.md +2 -2
  79. package/docs/api/functions/formatUTCDate.md +2 -2
  80. package/docs/api/functions/getDBConfig.md +1 -1
  81. package/docs/api/functions/getDBHandler.md +1 -1
  82. package/docs/api/functions/getTransactionConnection.md +2 -2
  83. package/docs/api/functions/getTransactionContext.md +2 -2
  84. package/docs/api/functions/hasMany.md +2 -2
  85. package/docs/api/functions/hasOne.md +2 -2
  86. package/docs/api/functions/initDBHandler.md +1 -1
  87. package/docs/api/functions/isAnySqlFragment.md +1 -1
  88. package/docs/api/functions/isConnectionError.md +1 -1
  89. package/docs/api/functions/isSqlCondition.md +1 -1
  90. package/docs/api/functions/isSqlFragment.md +1 -1
  91. package/docs/api/functions/isSqlRaw.md +1 -1
  92. package/docs/api/functions/isSqlRef.md +1 -1
  93. package/docs/api/functions/isSqlTypedFragment.md +1 -1
  94. package/docs/api/functions/model.md +4 -4
  95. package/docs/api/functions/parentRef.md +1 -1
  96. package/docs/api/functions/sql.md +1 -1
  97. package/docs/api/globals.md +24 -21
  98. package/docs/api/interfaces/Column.md +32 -31
  99. package/docs/api/interfaces/ColumnDecorator.md +1 -1
  100. package/docs/api/interfaces/ColumnOptions.md +1 -1
  101. package/docs/api/interfaces/CreatedMiddlewareClass.md +1 -1
  102. package/docs/api/interfaces/DBConfig.md +1 -1
  103. package/docs/api/interfaces/DBConfigOptions.md +1 -1
  104. package/docs/api/interfaces/DeleteOptions.md +1 -1
  105. package/docs/api/interfaces/InsertOptions.md +1 -1
  106. package/docs/api/interfaces/LimitConfig.md +1 -1
  107. package/docs/api/interfaces/MiddlewareConfig.md +1 -1
  108. package/docs/api/interfaces/ModelClassDecorator.md +4 -4
  109. package/docs/api/interfaces/ModelOptions.md +1 -1
  110. package/docs/api/interfaces/PkeyResult.md +1 -1
  111. package/docs/api/interfaces/RelationDecorator.md +1 -1
  112. package/docs/api/interfaces/SelectOptions.md +1 -1
  113. package/docs/api/interfaces/SqlCondition.md +1 -1
  114. package/docs/api/interfaces/SqlFragment.md +1 -1
  115. package/docs/api/interfaces/SqlTypedFragment.md +1 -1
  116. package/docs/api/interfaces/TransactionOptions.md +1 -1
  117. package/docs/api/interfaces/UpdateManyOptions.md +1 -1
  118. package/docs/api/interfaces/UpdateOptions.md +1 -1
  119. package/docs/architecture.md +12 -8
  120. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -1158,14 +1158,14 @@ __export(index_exports, {
1158
1158
  _legacyOr: () => or,
1159
1159
  and: () => and,
1160
1160
  belongsTo: () => belongsTo,
1161
- castToBoolean: () => castToBoolean,
1162
- castToBooleanArray: () => castToBooleanArray,
1163
- castToDatetime: () => castToDatetime,
1164
- castToDatetimeArray: () => castToDatetimeArray,
1165
- castToIntegerArray: () => castToIntegerArray,
1166
- castToJson: () => castToJson,
1167
- castToNumericArray: () => castToNumericArray,
1168
- castToStringArray: () => castToStringArray,
1161
+ castToBoolean: () => castToBoolean2,
1162
+ castToBooleanArray: () => castToBooleanArray2,
1163
+ castToDatetime: () => castToDatetime2,
1164
+ castToDatetimeArray: () => castToDatetimeArray2,
1165
+ castToIntegerArray: () => castToIntegerArray2,
1166
+ castToJson: () => castToJson2,
1167
+ castToNumericArray: () => castToNumericArray2,
1168
+ castToStringArray: () => castToStringArray2,
1169
1169
  closeAllPools: () => closeAllPools2,
1170
1170
  column: () => column,
1171
1171
  columnsToNames: () => columnsToNames,
@@ -1595,6 +1595,166 @@ var defaultLogger = {
1595
1595
  error: console.error
1596
1596
  };
1597
1597
 
1598
+ // src/drivers/PostgresHelper.ts
1599
+ function castToDatetime(val) {
1600
+ if (val === null || val === void 0) {
1601
+ return null;
1602
+ }
1603
+ if (val instanceof Date) {
1604
+ return val;
1605
+ }
1606
+ if (typeof val === "string" || typeof val === "number") {
1607
+ const date = new Date(val);
1608
+ return isNaN(date.getTime()) ? null : date;
1609
+ }
1610
+ return null;
1611
+ }
1612
+ function castToBoolean(val) {
1613
+ if (val === null || val === void 0) {
1614
+ return null;
1615
+ }
1616
+ if (typeof val === "boolean") {
1617
+ return val;
1618
+ }
1619
+ if (typeof val === "string") {
1620
+ const lower = val.toLowerCase();
1621
+ if (lower === "true" || lower === "t" || lower === "1") {
1622
+ return true;
1623
+ }
1624
+ if (lower === "false" || lower === "f" || lower === "0") {
1625
+ return false;
1626
+ }
1627
+ }
1628
+ if (typeof val === "number") {
1629
+ return val !== 0;
1630
+ }
1631
+ return null;
1632
+ }
1633
+ function castToIntegerArray(val) {
1634
+ if (val === null || val === void 0) {
1635
+ return [];
1636
+ }
1637
+ if (Array.isArray(val)) {
1638
+ return val.map((v) => {
1639
+ if (typeof v === "number") return v;
1640
+ const n = parseInt(String(v), 10);
1641
+ return isNaN(n) ? 0 : n;
1642
+ });
1643
+ }
1644
+ if (typeof val === "string") {
1645
+ return pgArrayParse(val).map((v) => {
1646
+ const n = parseInt(v, 10);
1647
+ return isNaN(n) ? 0 : n;
1648
+ });
1649
+ }
1650
+ return [];
1651
+ }
1652
+ function castToNumericArray(val) {
1653
+ if (val === null || val === void 0) {
1654
+ return [];
1655
+ }
1656
+ if (Array.isArray(val)) {
1657
+ return val.map((v) => {
1658
+ if (v === null || v === void 0) return null;
1659
+ if (typeof v === "number") return v;
1660
+ const n = parseFloat(String(v));
1661
+ return isNaN(n) ? null : n;
1662
+ });
1663
+ }
1664
+ if (typeof val === "string") {
1665
+ return pgArrayParse(val).map((v) => {
1666
+ if (v === "NULL" || v === "") return null;
1667
+ const n = parseFloat(v);
1668
+ return isNaN(n) ? null : n;
1669
+ });
1670
+ }
1671
+ return [];
1672
+ }
1673
+ function castToStringArray(val) {
1674
+ if (val === null || val === void 0) {
1675
+ return [];
1676
+ }
1677
+ if (Array.isArray(val)) {
1678
+ return val.map((v) => String(v));
1679
+ }
1680
+ if (typeof val === "string") {
1681
+ return pgArrayParse(val);
1682
+ }
1683
+ return [];
1684
+ }
1685
+ function castToBooleanArray(val) {
1686
+ if (val === null || val === void 0) {
1687
+ return [];
1688
+ }
1689
+ if (Array.isArray(val)) {
1690
+ return val.map((v) => castToBoolean(v));
1691
+ }
1692
+ if (typeof val === "string") {
1693
+ return pgArrayParse(val).map((v) => castToBoolean(v));
1694
+ }
1695
+ return [];
1696
+ }
1697
+ function castToDatetimeArray(val) {
1698
+ if (val === null || val === void 0) {
1699
+ return [];
1700
+ }
1701
+ if (Array.isArray(val)) {
1702
+ return val.map((v) => castToDatetime(v));
1703
+ }
1704
+ if (typeof val === "string") {
1705
+ return pgArrayParse(val).map((v) => castToDatetime(v));
1706
+ }
1707
+ return [];
1708
+ }
1709
+ function castToJson(val) {
1710
+ return val ?? null;
1711
+ }
1712
+ function pgArrayParse(literal) {
1713
+ if (!literal || literal === "{}") {
1714
+ return [];
1715
+ }
1716
+ let content = literal.trim();
1717
+ if (content.startsWith("{") && content.endsWith("}")) {
1718
+ content = content.slice(1, -1);
1719
+ }
1720
+ if (content === "") {
1721
+ return [];
1722
+ }
1723
+ const result = [];
1724
+ let current = "";
1725
+ let inQuotes = false;
1726
+ let escaped = false;
1727
+ for (let i = 0; i < content.length; i++) {
1728
+ const char = content[i];
1729
+ if (escaped) {
1730
+ current += char;
1731
+ escaped = false;
1732
+ continue;
1733
+ }
1734
+ if (char === "\\") {
1735
+ escaped = true;
1736
+ continue;
1737
+ }
1738
+ if (char === '"') {
1739
+ inQuotes = !inQuotes;
1740
+ continue;
1741
+ }
1742
+ if (char === "," && !inQuotes) {
1743
+ result.push(current);
1744
+ current = "";
1745
+ continue;
1746
+ }
1747
+ current += char;
1748
+ }
1749
+ if (current !== "" || result.length > 0) {
1750
+ result.push(current);
1751
+ }
1752
+ return result;
1753
+ }
1754
+ function formatSqlCast(placeholder, sqlCast) {
1755
+ return `${placeholder}::${sqlCast}`;
1756
+ }
1757
+
1598
1758
  // src/TypeCast.ts
1599
1759
  var defaultTypeCast = {
1600
1760
  castToDatetime(val) {
@@ -1719,17 +1879,15 @@ var defaultTypeCast = {
1719
1879
  }
1720
1880
  return [];
1721
1881
  },
1882
+ // A string is JSON text to decode; any other value is already a JSON value
1722
1883
  castToJson(val) {
1723
1884
  if (val === null || val === void 0) return null;
1724
- if (typeof val === "object") return val;
1725
- if (typeof val === "string") {
1726
- try {
1727
- return JSON.parse(val);
1728
- } catch {
1729
- return null;
1730
- }
1885
+ if (typeof val !== "string") return val;
1886
+ try {
1887
+ return JSON.parse(val);
1888
+ } catch {
1889
+ return null;
1731
1890
  }
1732
- return null;
1733
1891
  }
1734
1892
  };
1735
1893
  function parsePostgresArray(literal) {
@@ -1780,28 +1938,28 @@ function resetTypeCastImpl() {
1780
1938
  function getTypeCast() {
1781
1939
  return currentTypeCast;
1782
1940
  }
1783
- function castToDatetime(val) {
1941
+ function castToDatetime2(val) {
1784
1942
  return currentTypeCast.castToDatetime(val);
1785
1943
  }
1786
- function castToBoolean(val) {
1944
+ function castToBoolean2(val) {
1787
1945
  return currentTypeCast.castToBoolean(val);
1788
1946
  }
1789
- function castToIntegerArray(val) {
1947
+ function castToIntegerArray2(val) {
1790
1948
  return currentTypeCast.castToIntegerArray(val);
1791
1949
  }
1792
- function castToNumericArray(val) {
1950
+ function castToNumericArray2(val) {
1793
1951
  return currentTypeCast.castToNumericArray(val);
1794
1952
  }
1795
- function castToStringArray(val) {
1953
+ function castToStringArray2(val) {
1796
1954
  return currentTypeCast.castToStringArray(val);
1797
1955
  }
1798
- function castToBooleanArray(val) {
1956
+ function castToBooleanArray2(val) {
1799
1957
  return currentTypeCast.castToBooleanArray(val);
1800
1958
  }
1801
- function castToDatetimeArray(val) {
1959
+ function castToDatetimeArray2(val) {
1802
1960
  return currentTypeCast.castToDatetimeArray(val);
1803
1961
  }
1804
- function castToJson(val) {
1962
+ function castToJson2(val) {
1805
1963
  return currentTypeCast.castToJson(val);
1806
1964
  }
1807
1965
  function formatLocalDate(d) {
@@ -1845,16 +2003,7 @@ var postgresTypeCast = {
1845
2003
  return JSON.stringify(val);
1846
2004
  },
1847
2005
  deserializeJson(val) {
1848
- if (val === null || val === void 0) return null;
1849
- if (typeof val === "object") return val;
1850
- if (typeof val === "string") {
1851
- try {
1852
- return JSON.parse(val);
1853
- } catch {
1854
- return null;
1855
- }
1856
- }
1857
- return null;
2006
+ return castToJson(val);
1858
2007
  },
1859
2008
  serializeBooleanArray(val) {
1860
2009
  if (val === null || val === void 0) return null;
@@ -2158,73 +2307,151 @@ var postgresSqlBuilder = {
2158
2307
  inferPgType
2159
2308
  };
2160
2309
 
2161
- // src/drivers/MysqlSqlBuilder.ts
2162
- var mysqlTypeCast = {
2163
- driverName: "mysql",
2164
- serializeArray(val) {
2165
- if (val === null || val === void 0) return null;
2166
- return JSON.stringify(val);
2167
- },
2168
- deserializeArray(val) {
2169
- if (val === null || val === void 0) return null;
2170
- if (Array.isArray(val)) return val;
2171
- if (typeof val === "string") {
2172
- try {
2173
- const parsed = JSON.parse(val);
2174
- return Array.isArray(parsed) ? parsed : null;
2175
- } catch {
2176
- return null;
2177
- }
2178
- }
2179
- return null;
2180
- },
2181
- serializeJson(val) {
2182
- if (val === null || val === void 0) return null;
2183
- return JSON.stringify(val);
2184
- },
2185
- deserializeJson(val) {
2186
- if (val === null || val === void 0) return null;
2187
- if (typeof val === "object") return val;
2188
- if (typeof val === "string") {
2189
- try {
2190
- return JSON.parse(val);
2191
- } catch {
2192
- return null;
2193
- }
2194
- }
2195
- return null;
2196
- },
2197
- serializeBooleanArray(val) {
2198
- if (val === null || val === void 0) return null;
2199
- return JSON.stringify(val);
2200
- },
2201
- deserializeBooleanArray(val) {
2202
- if (val === null || val === void 0) return null;
2203
- if (Array.isArray(val)) return val;
2204
- if (typeof val === "string") {
2205
- try {
2206
- const parsed = JSON.parse(val);
2207
- return Array.isArray(parsed) ? parsed : null;
2208
- } catch {
2209
- return null;
2210
- }
2211
- }
2310
+ // src/drivers/MysqlHelper.ts
2311
+ function castToDatetime3(val) {
2312
+ if (val === null || val === void 0) {
2212
2313
  return null;
2213
- },
2214
- /**
2215
- * MySQL: return Date object as-is, let mysql2 driver handle conversion
2216
- * Note: MySQL DATETIME has no timezone - values stored/retrieved in server timezone
2217
- */
2218
- serializeDatetime(val) {
2219
- return val;
2220
- },
2221
- /**
2222
- * MySQL: return Date object as-is, let mysql2 driver handle conversion
2223
- */
2224
- serializeDate(val) {
2314
+ }
2315
+ if (val instanceof Date) {
2225
2316
  return val;
2226
2317
  }
2227
- };
2318
+ if (typeof val === "string" || typeof val === "number") {
2319
+ const date = new Date(val);
2320
+ return isNaN(date.getTime()) ? null : date;
2321
+ }
2322
+ return null;
2323
+ }
2324
+ function castToBoolean3(val) {
2325
+ if (val === null || val === void 0) {
2326
+ return null;
2327
+ }
2328
+ if (typeof val === "boolean") {
2329
+ return val;
2330
+ }
2331
+ if (typeof val === "number") {
2332
+ return val !== 0;
2333
+ }
2334
+ if (typeof val === "string") {
2335
+ const lower = val.toLowerCase();
2336
+ if (lower === "true" || lower === "1") {
2337
+ return true;
2338
+ }
2339
+ if (lower === "false" || lower === "0") {
2340
+ return false;
2341
+ }
2342
+ }
2343
+ if (Buffer.isBuffer(val)) {
2344
+ return val[0] !== 0;
2345
+ }
2346
+ return null;
2347
+ }
2348
+ function castToIntegerArray3(val) {
2349
+ if (val === null || val === void 0) {
2350
+ return [];
2351
+ }
2352
+ if (Array.isArray(val)) {
2353
+ return val.map((v) => {
2354
+ const n = parseInt(String(v), 10);
2355
+ return isNaN(n) ? 0 : n;
2356
+ });
2357
+ }
2358
+ if (typeof val === "string") {
2359
+ try {
2360
+ const parsed = JSON.parse(val);
2361
+ if (Array.isArray(parsed)) {
2362
+ return parsed.map((v) => {
2363
+ const n = parseInt(String(v), 10);
2364
+ return isNaN(n) ? 0 : n;
2365
+ });
2366
+ }
2367
+ } catch {
2368
+ }
2369
+ }
2370
+ return [];
2371
+ }
2372
+ function castToStringArray3(val) {
2373
+ if (val === null || val === void 0) {
2374
+ return [];
2375
+ }
2376
+ if (Array.isArray(val)) {
2377
+ return val.map((v) => String(v));
2378
+ }
2379
+ if (typeof val === "string") {
2380
+ try {
2381
+ const parsed = JSON.parse(val);
2382
+ if (Array.isArray(parsed)) {
2383
+ return parsed.map((v) => String(v));
2384
+ }
2385
+ } catch {
2386
+ }
2387
+ }
2388
+ return [];
2389
+ }
2390
+ function castToJson3(val) {
2391
+ return val ?? null;
2392
+ }
2393
+ function formatSqlCast2(placeholder, _sqlCast) {
2394
+ return placeholder;
2395
+ }
2396
+
2397
+ // src/drivers/MysqlSqlBuilder.ts
2398
+ var mysqlTypeCast = {
2399
+ driverName: "mysql",
2400
+ serializeArray(val) {
2401
+ if (val === null || val === void 0) return null;
2402
+ return JSON.stringify(val);
2403
+ },
2404
+ deserializeArray(val) {
2405
+ if (val === null || val === void 0) return null;
2406
+ if (Array.isArray(val)) return val;
2407
+ if (typeof val === "string") {
2408
+ try {
2409
+ const parsed = JSON.parse(val);
2410
+ return Array.isArray(parsed) ? parsed : null;
2411
+ } catch {
2412
+ return null;
2413
+ }
2414
+ }
2415
+ return null;
2416
+ },
2417
+ serializeJson(val) {
2418
+ if (val === null || val === void 0) return null;
2419
+ return JSON.stringify(val);
2420
+ },
2421
+ deserializeJson(val) {
2422
+ return castToJson3(val);
2423
+ },
2424
+ serializeBooleanArray(val) {
2425
+ if (val === null || val === void 0) return null;
2426
+ return JSON.stringify(val);
2427
+ },
2428
+ deserializeBooleanArray(val) {
2429
+ if (val === null || val === void 0) return null;
2430
+ if (Array.isArray(val)) return val;
2431
+ if (typeof val === "string") {
2432
+ try {
2433
+ const parsed = JSON.parse(val);
2434
+ return Array.isArray(parsed) ? parsed : null;
2435
+ } catch {
2436
+ return null;
2437
+ }
2438
+ }
2439
+ return null;
2440
+ },
2441
+ /**
2442
+ * MySQL: return Date object as-is, let mysql2 driver handle conversion
2443
+ * Note: MySQL DATETIME has no timezone - values stored/retrieved in server timezone
2444
+ */
2445
+ serializeDatetime(val) {
2446
+ return val;
2447
+ },
2448
+ /**
2449
+ * MySQL: return Date object as-is, let mysql2 driver handle conversion
2450
+ */
2451
+ serializeDate(val) {
2452
+ return val;
2453
+ }
2454
+ };
2228
2455
  var mysqlSqlBuilder = {
2229
2456
  driverType: "mysql",
2230
2457
  typeCast: mysqlTypeCast,
@@ -2360,6 +2587,103 @@ var mysqlSqlBuilder = {
2360
2587
  }
2361
2588
  };
2362
2589
 
2590
+ // src/drivers/SqliteHelper.ts
2591
+ function castToDatetime4(val) {
2592
+ if (val === null || val === void 0) {
2593
+ return null;
2594
+ }
2595
+ if (val instanceof Date) {
2596
+ return val;
2597
+ }
2598
+ if (typeof val === "string" || typeof val === "number") {
2599
+ const date = new Date(val);
2600
+ return isNaN(date.getTime()) ? null : date;
2601
+ }
2602
+ return null;
2603
+ }
2604
+ function castToBoolean4(val) {
2605
+ if (val === null || val === void 0) {
2606
+ return null;
2607
+ }
2608
+ if (typeof val === "boolean") {
2609
+ return val;
2610
+ }
2611
+ if (typeof val === "number") {
2612
+ return val !== 0;
2613
+ }
2614
+ if (typeof val === "string") {
2615
+ const lower = val.toLowerCase();
2616
+ if (lower === "true" || lower === "1") {
2617
+ return true;
2618
+ }
2619
+ if (lower === "false" || lower === "0") {
2620
+ return false;
2621
+ }
2622
+ }
2623
+ return null;
2624
+ }
2625
+ function castToIntegerArray4(val) {
2626
+ if (val === null || val === void 0) {
2627
+ return [];
2628
+ }
2629
+ if (Array.isArray(val)) {
2630
+ return val.map((v) => {
2631
+ const n = parseInt(String(v), 10);
2632
+ return isNaN(n) ? 0 : n;
2633
+ });
2634
+ }
2635
+ if (typeof val === "string") {
2636
+ try {
2637
+ const parsed = JSON.parse(val);
2638
+ if (Array.isArray(parsed)) {
2639
+ return parsed.map((v) => {
2640
+ const n = parseInt(String(v), 10);
2641
+ return isNaN(n) ? 0 : n;
2642
+ });
2643
+ }
2644
+ } catch {
2645
+ }
2646
+ }
2647
+ return [];
2648
+ }
2649
+ function castToStringArray4(val) {
2650
+ if (val === null || val === void 0) {
2651
+ return [];
2652
+ }
2653
+ if (Array.isArray(val)) {
2654
+ return val.map((v) => String(v));
2655
+ }
2656
+ if (typeof val === "string") {
2657
+ try {
2658
+ const parsed = JSON.parse(val);
2659
+ if (Array.isArray(parsed)) {
2660
+ return parsed.map((v) => String(v));
2661
+ }
2662
+ } catch {
2663
+ }
2664
+ }
2665
+ return [];
2666
+ }
2667
+ function castToJson4(val) {
2668
+ if (val === null || val === void 0) {
2669
+ return null;
2670
+ }
2671
+ if (typeof val === "object" || typeof val === "number") {
2672
+ return val;
2673
+ }
2674
+ if (typeof val === "string") {
2675
+ try {
2676
+ return JSON.parse(val);
2677
+ } catch {
2678
+ return null;
2679
+ }
2680
+ }
2681
+ return null;
2682
+ }
2683
+ function formatSqlCast3(placeholder, _sqlCast) {
2684
+ return placeholder;
2685
+ }
2686
+
2363
2687
  // src/drivers/SqliteSqlBuilder.ts
2364
2688
  var sqliteTypeCast = {
2365
2689
  driverName: "sqlite",
@@ -2385,16 +2709,7 @@ var sqliteTypeCast = {
2385
2709
  return JSON.stringify(val);
2386
2710
  },
2387
2711
  deserializeJson(val) {
2388
- if (val === null || val === void 0) return null;
2389
- if (typeof val === "object") return val;
2390
- if (typeof val === "string") {
2391
- try {
2392
- return JSON.parse(val);
2393
- } catch {
2394
- return null;
2395
- }
2396
- }
2397
- return null;
2712
+ return castToJson4(val);
2398
2713
  },
2399
2714
  serializeBooleanArray(val) {
2400
2715
  if (val === null || val === void 0) return null;
@@ -3475,512 +3790,142 @@ var MysqlDriver = class {
3475
3790
  rowCount: rows.length
3476
3791
  };
3477
3792
  }
3478
- }
3479
- }
3480
- const resultObj = result;
3481
- const rowCount = resultObj.affectedRows ?? 0;
3482
- this.logger.debug(`Retry succeeded in ${duration}ms, affected: ${rowCount}`);
3483
- return {
3484
- rows: [],
3485
- rowCount
3486
- };
3487
- } catch (retryError) {
3488
- this.logger.error(`Retry also failed: ${sqlWithoutReturning}`, retryError);
3489
- throw retryError;
3490
- }
3491
- }
3492
- this.logger.error(`Query failed: ${sqlWithoutReturning}`, error);
3493
- throw error;
3494
- }
3495
- }
3496
- /**
3497
- * Execute a write query (uses writer pool if available)
3498
- */
3499
- async executeWrite(sql2, params = []) {
3500
- const conn = this.writerPool || this.pool;
3501
- const convertedSql = convertOnConflictToMysql(sql2);
3502
- const { sql: sqlWithoutReturning, hasReturning, returningCols } = removeReturning(convertedSql);
3503
- const convertedParams = convertParams2(params);
3504
- this.logger.debug(`SQL: ${sqlWithoutReturning}`, convertedParams);
3505
- const startTime = Date.now();
3506
- try {
3507
- const [result] = await conn.query(sqlWithoutReturning, convertedParams);
3508
- const duration = Date.now() - startTime;
3509
- if (hasReturning) {
3510
- const resultObj2 = result;
3511
- const tableName = extractTableName(sql2);
3512
- if (tableName && sql2.trim().toUpperCase().startsWith("INSERT")) {
3513
- const insertId = resultObj2.insertId;
3514
- const affectedRows = resultObj2.affectedRows ?? 1;
3515
- if (affectedRows > 0 && insertId > 0) {
3516
- const cols = returningCols === "*" ? "*" : returningCols;
3517
- const selectSql = `SELECT ${cols} FROM ${tableName} WHERE id >= ? AND id < ?`;
3518
- const [selectResult] = await conn.query(selectSql, [insertId, insertId + affectedRows]);
3519
- const rows2 = selectResult;
3520
- this.logger.debug(`Insert completed in ${duration}ms, rows: ${rows2.length}`);
3521
- return {
3522
- rows: rows2,
3523
- rowCount: rows2.length
3524
- };
3525
- }
3526
- }
3527
- }
3528
- const resultObj = result;
3529
- const rowCount = resultObj.affectedRows ?? 0;
3530
- const rows = Array.isArray(result) ? result : [];
3531
- this.logger.debug(`Write completed in ${duration}ms, affected: ${rowCount}`);
3532
- return {
3533
- rows,
3534
- rowCount
3535
- };
3536
- } catch (error) {
3537
- if (isConnectionError(error)) {
3538
- this.logger.warn(`Connection error, retrying write: ${sqlWithoutReturning}`);
3539
- try {
3540
- const [result] = await conn.query(sqlWithoutReturning, convertedParams);
3541
- const duration = Date.now() - startTime;
3542
- if (hasReturning) {
3543
- const resultObj2 = result;
3544
- const tableName = extractTableName(sql2);
3545
- if (tableName && sql2.trim().toUpperCase().startsWith("INSERT")) {
3546
- const insertId = resultObj2.insertId;
3547
- const affectedRows = resultObj2.affectedRows ?? 1;
3548
- if (affectedRows > 0 && insertId > 0) {
3549
- const cols = returningCols === "*" ? "*" : returningCols;
3550
- const selectSql = `SELECT ${cols} FROM ${tableName} WHERE id >= ? AND id < ?`;
3551
- const [selectResult] = await conn.query(selectSql, [insertId, insertId + affectedRows]);
3552
- const rows2 = selectResult;
3553
- this.logger.debug(`Retry succeeded in ${duration}ms, rows: ${rows2.length}`);
3554
- return {
3555
- rows: rows2,
3556
- rowCount: rows2.length
3557
- };
3558
- }
3559
- }
3560
- }
3561
- const resultObj = result;
3562
- const rowCount = resultObj.affectedRows ?? 0;
3563
- const rows = Array.isArray(result) ? result : [];
3564
- this.logger.debug(`Retry succeeded in ${duration}ms, affected: ${rowCount}`);
3565
- return {
3566
- rows,
3567
- rowCount
3568
- };
3569
- } catch (retryError) {
3570
- this.logger.error(`Retry also failed: ${sqlWithoutReturning}`, retryError);
3571
- throw retryError;
3572
- }
3573
- }
3574
- this.logger.error(`Write failed: ${sqlWithoutReturning}`, error);
3575
- throw error;
3576
- }
3577
- }
3578
- /**
3579
- * Get a connection for transaction (uses writer pool if available)
3580
- */
3581
- async getConnection() {
3582
- const pool = this.writerPool || this.pool;
3583
- const connection = await pool.getConnection();
3584
- return new MysqlConnection(connection, this.logger);
3585
- }
3586
- /**
3587
- * Close all connections
3588
- */
3589
- async close() {
3590
- await closePool2(this.config);
3591
- if (this.writerConfig) {
3592
- await closePool2(this.writerConfig);
3593
- }
3594
- }
3595
- /**
3596
- * Set logger
3597
- */
3598
- setLogger(logger) {
3599
- this.logger = logger;
3600
- }
3601
- /**
3602
- * Get the underlying pool (for advanced use)
3603
- */
3604
- getPool() {
3605
- return this.pool;
3606
- }
3607
- /**
3608
- * Get the underlying writer pool
3609
- */
3610
- getWriterPool() {
3611
- return this.writerPool;
3612
- }
3613
- };
3614
-
3615
- // src/drivers/PostgresHelper.ts
3616
- function castToDatetime2(val) {
3617
- if (val === null || val === void 0) {
3618
- return null;
3619
- }
3620
- if (val instanceof Date) {
3621
- return val;
3622
- }
3623
- if (typeof val === "string" || typeof val === "number") {
3624
- const date = new Date(val);
3625
- return isNaN(date.getTime()) ? null : date;
3626
- }
3627
- return null;
3628
- }
3629
- function castToBoolean2(val) {
3630
- if (val === null || val === void 0) {
3631
- return null;
3632
- }
3633
- if (typeof val === "boolean") {
3634
- return val;
3635
- }
3636
- if (typeof val === "string") {
3637
- const lower = val.toLowerCase();
3638
- if (lower === "true" || lower === "t" || lower === "1") {
3639
- return true;
3640
- }
3641
- if (lower === "false" || lower === "f" || lower === "0") {
3642
- return false;
3643
- }
3644
- }
3645
- if (typeof val === "number") {
3646
- return val !== 0;
3647
- }
3648
- return null;
3649
- }
3650
- function castToIntegerArray2(val) {
3651
- if (val === null || val === void 0) {
3652
- return [];
3653
- }
3654
- if (Array.isArray(val)) {
3655
- return val.map((v) => {
3656
- if (typeof v === "number") return v;
3657
- const n = parseInt(String(v), 10);
3658
- return isNaN(n) ? 0 : n;
3659
- });
3660
- }
3661
- if (typeof val === "string") {
3662
- return pgArrayParse(val).map((v) => {
3663
- const n = parseInt(v, 10);
3664
- return isNaN(n) ? 0 : n;
3665
- });
3666
- }
3667
- return [];
3668
- }
3669
- function castToNumericArray2(val) {
3670
- if (val === null || val === void 0) {
3671
- return [];
3672
- }
3673
- if (Array.isArray(val)) {
3674
- return val.map((v) => {
3675
- if (v === null || v === void 0) return null;
3676
- if (typeof v === "number") return v;
3677
- const n = parseFloat(String(v));
3678
- return isNaN(n) ? null : n;
3679
- });
3680
- }
3681
- if (typeof val === "string") {
3682
- return pgArrayParse(val).map((v) => {
3683
- if (v === "NULL" || v === "") return null;
3684
- const n = parseFloat(v);
3685
- return isNaN(n) ? null : n;
3686
- });
3687
- }
3688
- return [];
3689
- }
3690
- function castToStringArray2(val) {
3691
- if (val === null || val === void 0) {
3692
- return [];
3693
- }
3694
- if (Array.isArray(val)) {
3695
- return val.map((v) => String(v));
3696
- }
3697
- if (typeof val === "string") {
3698
- return pgArrayParse(val);
3699
- }
3700
- return [];
3701
- }
3702
- function castToBooleanArray2(val) {
3703
- if (val === null || val === void 0) {
3704
- return [];
3705
- }
3706
- if (Array.isArray(val)) {
3707
- return val.map((v) => castToBoolean2(v));
3708
- }
3709
- if (typeof val === "string") {
3710
- return pgArrayParse(val).map((v) => castToBoolean2(v));
3711
- }
3712
- return [];
3713
- }
3714
- function castToDatetimeArray2(val) {
3715
- if (val === null || val === void 0) {
3716
- return [];
3717
- }
3718
- if (Array.isArray(val)) {
3719
- return val.map((v) => castToDatetime2(v));
3720
- }
3721
- if (typeof val === "string") {
3722
- return pgArrayParse(val).map((v) => castToDatetime2(v));
3723
- }
3724
- return [];
3725
- }
3726
- function castToJson2(val) {
3727
- if (val === null || val === void 0) {
3728
- return null;
3729
- }
3730
- if (typeof val === "object") {
3731
- return val;
3732
- }
3733
- if (typeof val === "string") {
3734
- try {
3735
- return JSON.parse(val);
3736
- } catch {
3737
- return null;
3738
- }
3739
- }
3740
- return null;
3741
- }
3742
- function pgArrayParse(literal) {
3743
- if (!literal || literal === "{}") {
3744
- return [];
3745
- }
3746
- let content = literal.trim();
3747
- if (content.startsWith("{") && content.endsWith("}")) {
3748
- content = content.slice(1, -1);
3749
- }
3750
- if (content === "") {
3751
- return [];
3752
- }
3753
- const result = [];
3754
- let current = "";
3755
- let inQuotes = false;
3756
- let escaped = false;
3757
- for (let i = 0; i < content.length; i++) {
3758
- const char = content[i];
3759
- if (escaped) {
3760
- current += char;
3761
- escaped = false;
3762
- continue;
3763
- }
3764
- if (char === "\\") {
3765
- escaped = true;
3766
- continue;
3767
- }
3768
- if (char === '"') {
3769
- inQuotes = !inQuotes;
3770
- continue;
3771
- }
3772
- if (char === "," && !inQuotes) {
3773
- result.push(current);
3774
- current = "";
3775
- continue;
3776
- }
3777
- current += char;
3778
- }
3779
- if (current !== "" || result.length > 0) {
3780
- result.push(current);
3781
- }
3782
- return result;
3783
- }
3784
- function formatSqlCast(placeholder, sqlCast) {
3785
- return `${placeholder}::${sqlCast}`;
3786
- }
3787
-
3788
- // src/drivers/SqliteHelper.ts
3789
- function castToDatetime3(val) {
3790
- if (val === null || val === void 0) {
3791
- return null;
3792
- }
3793
- if (val instanceof Date) {
3794
- return val;
3795
- }
3796
- if (typeof val === "string" || typeof val === "number") {
3797
- const date = new Date(val);
3798
- return isNaN(date.getTime()) ? null : date;
3799
- }
3800
- return null;
3801
- }
3802
- function castToBoolean3(val) {
3803
- if (val === null || val === void 0) {
3804
- return null;
3805
- }
3806
- if (typeof val === "boolean") {
3807
- return val;
3808
- }
3809
- if (typeof val === "number") {
3810
- return val !== 0;
3811
- }
3812
- if (typeof val === "string") {
3813
- const lower = val.toLowerCase();
3814
- if (lower === "true" || lower === "1") {
3815
- return true;
3816
- }
3817
- if (lower === "false" || lower === "0") {
3818
- return false;
3819
- }
3820
- }
3821
- return null;
3822
- }
3823
- function castToIntegerArray3(val) {
3824
- if (val === null || val === void 0) {
3825
- return [];
3826
- }
3827
- if (Array.isArray(val)) {
3828
- return val.map((v) => {
3829
- const n = parseInt(String(v), 10);
3830
- return isNaN(n) ? 0 : n;
3831
- });
3832
- }
3833
- if (typeof val === "string") {
3834
- try {
3835
- const parsed = JSON.parse(val);
3836
- if (Array.isArray(parsed)) {
3837
- return parsed.map((v) => {
3838
- const n = parseInt(String(v), 10);
3839
- return isNaN(n) ? 0 : n;
3840
- });
3841
- }
3842
- } catch {
3843
- }
3844
- }
3845
- return [];
3846
- }
3847
- function castToStringArray3(val) {
3848
- if (val === null || val === void 0) {
3849
- return [];
3850
- }
3851
- if (Array.isArray(val)) {
3852
- return val.map((v) => String(v));
3853
- }
3854
- if (typeof val === "string") {
3855
- try {
3856
- const parsed = JSON.parse(val);
3857
- if (Array.isArray(parsed)) {
3858
- return parsed.map((v) => String(v));
3859
- }
3860
- } catch {
3861
- }
3862
- }
3863
- return [];
3864
- }
3865
- function castToJson3(val) {
3866
- if (val === null || val === void 0) {
3867
- return null;
3868
- }
3869
- if (typeof val === "object") {
3870
- return val;
3871
- }
3872
- if (typeof val === "string") {
3873
- try {
3874
- return JSON.parse(val);
3875
- } catch {
3876
- return null;
3877
- }
3878
- }
3879
- return null;
3880
- }
3881
- function formatSqlCast2(placeholder, _sqlCast) {
3882
- return placeholder;
3883
- }
3884
-
3885
- // src/drivers/MysqlHelper.ts
3886
- function castToDatetime4(val) {
3887
- if (val === null || val === void 0) {
3888
- return null;
3889
- }
3890
- if (val instanceof Date) {
3891
- return val;
3892
- }
3893
- if (typeof val === "string" || typeof val === "number") {
3894
- const date = new Date(val);
3895
- return isNaN(date.getTime()) ? null : date;
3896
- }
3897
- return null;
3898
- }
3899
- function castToBoolean4(val) {
3900
- if (val === null || val === void 0) {
3901
- return null;
3902
- }
3903
- if (typeof val === "boolean") {
3904
- return val;
3905
- }
3906
- if (typeof val === "number") {
3907
- return val !== 0;
3908
- }
3909
- if (typeof val === "string") {
3910
- const lower = val.toLowerCase();
3911
- if (lower === "true" || lower === "1") {
3912
- return true;
3913
- }
3914
- if (lower === "false" || lower === "0") {
3915
- return false;
3793
+ }
3794
+ }
3795
+ const resultObj = result;
3796
+ const rowCount = resultObj.affectedRows ?? 0;
3797
+ this.logger.debug(`Retry succeeded in ${duration}ms, affected: ${rowCount}`);
3798
+ return {
3799
+ rows: [],
3800
+ rowCount
3801
+ };
3802
+ } catch (retryError) {
3803
+ this.logger.error(`Retry also failed: ${sqlWithoutReturning}`, retryError);
3804
+ throw retryError;
3805
+ }
3806
+ }
3807
+ this.logger.error(`Query failed: ${sqlWithoutReturning}`, error);
3808
+ throw error;
3916
3809
  }
3917
3810
  }
3918
- if (Buffer.isBuffer(val)) {
3919
- return val[0] !== 0;
3920
- }
3921
- return null;
3922
- }
3923
- function castToIntegerArray4(val) {
3924
- if (val === null || val === void 0) {
3925
- return [];
3926
- }
3927
- if (Array.isArray(val)) {
3928
- return val.map((v) => {
3929
- const n = parseInt(String(v), 10);
3930
- return isNaN(n) ? 0 : n;
3931
- });
3932
- }
3933
- if (typeof val === "string") {
3811
+ /**
3812
+ * Execute a write query (uses writer pool if available)
3813
+ */
3814
+ async executeWrite(sql2, params = []) {
3815
+ const conn = this.writerPool || this.pool;
3816
+ const convertedSql = convertOnConflictToMysql(sql2);
3817
+ const { sql: sqlWithoutReturning, hasReturning, returningCols } = removeReturning(convertedSql);
3818
+ const convertedParams = convertParams2(params);
3819
+ this.logger.debug(`SQL: ${sqlWithoutReturning}`, convertedParams);
3820
+ const startTime = Date.now();
3934
3821
  try {
3935
- const parsed = JSON.parse(val);
3936
- if (Array.isArray(parsed)) {
3937
- return parsed.map((v) => {
3938
- const n = parseInt(String(v), 10);
3939
- return isNaN(n) ? 0 : n;
3940
- });
3822
+ const [result] = await conn.query(sqlWithoutReturning, convertedParams);
3823
+ const duration = Date.now() - startTime;
3824
+ if (hasReturning) {
3825
+ const resultObj2 = result;
3826
+ const tableName = extractTableName(sql2);
3827
+ if (tableName && sql2.trim().toUpperCase().startsWith("INSERT")) {
3828
+ const insertId = resultObj2.insertId;
3829
+ const affectedRows = resultObj2.affectedRows ?? 1;
3830
+ if (affectedRows > 0 && insertId > 0) {
3831
+ const cols = returningCols === "*" ? "*" : returningCols;
3832
+ const selectSql = `SELECT ${cols} FROM ${tableName} WHERE id >= ? AND id < ?`;
3833
+ const [selectResult] = await conn.query(selectSql, [insertId, insertId + affectedRows]);
3834
+ const rows2 = selectResult;
3835
+ this.logger.debug(`Insert completed in ${duration}ms, rows: ${rows2.length}`);
3836
+ return {
3837
+ rows: rows2,
3838
+ rowCount: rows2.length
3839
+ };
3840
+ }
3841
+ }
3941
3842
  }
3942
- } catch {
3843
+ const resultObj = result;
3844
+ const rowCount = resultObj.affectedRows ?? 0;
3845
+ const rows = Array.isArray(result) ? result : [];
3846
+ this.logger.debug(`Write completed in ${duration}ms, affected: ${rowCount}`);
3847
+ return {
3848
+ rows,
3849
+ rowCount
3850
+ };
3851
+ } catch (error) {
3852
+ if (isConnectionError(error)) {
3853
+ this.logger.warn(`Connection error, retrying write: ${sqlWithoutReturning}`);
3854
+ try {
3855
+ const [result] = await conn.query(sqlWithoutReturning, convertedParams);
3856
+ const duration = Date.now() - startTime;
3857
+ if (hasReturning) {
3858
+ const resultObj2 = result;
3859
+ const tableName = extractTableName(sql2);
3860
+ if (tableName && sql2.trim().toUpperCase().startsWith("INSERT")) {
3861
+ const insertId = resultObj2.insertId;
3862
+ const affectedRows = resultObj2.affectedRows ?? 1;
3863
+ if (affectedRows > 0 && insertId > 0) {
3864
+ const cols = returningCols === "*" ? "*" : returningCols;
3865
+ const selectSql = `SELECT ${cols} FROM ${tableName} WHERE id >= ? AND id < ?`;
3866
+ const [selectResult] = await conn.query(selectSql, [insertId, insertId + affectedRows]);
3867
+ const rows2 = selectResult;
3868
+ this.logger.debug(`Retry succeeded in ${duration}ms, rows: ${rows2.length}`);
3869
+ return {
3870
+ rows: rows2,
3871
+ rowCount: rows2.length
3872
+ };
3873
+ }
3874
+ }
3875
+ }
3876
+ const resultObj = result;
3877
+ const rowCount = resultObj.affectedRows ?? 0;
3878
+ const rows = Array.isArray(result) ? result : [];
3879
+ this.logger.debug(`Retry succeeded in ${duration}ms, affected: ${rowCount}`);
3880
+ return {
3881
+ rows,
3882
+ rowCount
3883
+ };
3884
+ } catch (retryError) {
3885
+ this.logger.error(`Retry also failed: ${sqlWithoutReturning}`, retryError);
3886
+ throw retryError;
3887
+ }
3888
+ }
3889
+ this.logger.error(`Write failed: ${sqlWithoutReturning}`, error);
3890
+ throw error;
3943
3891
  }
3944
3892
  }
3945
- return [];
3946
- }
3947
- function castToStringArray4(val) {
3948
- if (val === null || val === void 0) {
3949
- return [];
3950
- }
3951
- if (Array.isArray(val)) {
3952
- return val.map((v) => String(v));
3893
+ /**
3894
+ * Get a connection for transaction (uses writer pool if available)
3895
+ */
3896
+ async getConnection() {
3897
+ const pool = this.writerPool || this.pool;
3898
+ const connection = await pool.getConnection();
3899
+ return new MysqlConnection(connection, this.logger);
3953
3900
  }
3954
- if (typeof val === "string") {
3955
- try {
3956
- const parsed = JSON.parse(val);
3957
- if (Array.isArray(parsed)) {
3958
- return parsed.map((v) => String(v));
3959
- }
3960
- } catch {
3901
+ /**
3902
+ * Close all connections
3903
+ */
3904
+ async close() {
3905
+ await closePool2(this.config);
3906
+ if (this.writerConfig) {
3907
+ await closePool2(this.writerConfig);
3961
3908
  }
3962
3909
  }
3963
- return [];
3964
- }
3965
- function castToJson4(val) {
3966
- if (val === null || val === void 0) {
3967
- return null;
3910
+ /**
3911
+ * Set logger
3912
+ */
3913
+ setLogger(logger) {
3914
+ this.logger = logger;
3968
3915
  }
3969
- if (typeof val === "object") {
3970
- return val;
3916
+ /**
3917
+ * Get the underlying pool (for advanced use)
3918
+ */
3919
+ getPool() {
3920
+ return this.pool;
3971
3921
  }
3972
- if (typeof val === "string") {
3973
- try {
3974
- return JSON.parse(val);
3975
- } catch {
3976
- return null;
3977
- }
3922
+ /**
3923
+ * Get the underlying writer pool
3924
+ */
3925
+ getWriterPool() {
3926
+ return this.writerPool;
3978
3927
  }
3979
- return null;
3980
- }
3981
- function formatSqlCast3(placeholder, _sqlCast) {
3982
- return placeholder;
3983
- }
3928
+ };
3984
3929
 
3985
3930
  // src/drivers/index.ts
3986
3931
  function getSqlBuilder(driverType) {
@@ -4003,9 +3948,9 @@ function getSqlCastFormatter(driverType) {
4003
3948
  case "postgres":
4004
3949
  return (placeholder, sqlType) => formatSqlCast(placeholder, sqlType);
4005
3950
  case "sqlite":
4006
- return (placeholder, sqlType) => formatSqlCast2(placeholder, sqlType);
4007
- case "mysql":
4008
3951
  return (placeholder, sqlType) => formatSqlCast3(placeholder, sqlType);
3952
+ case "mysql":
3953
+ return (placeholder, sqlType) => formatSqlCast2(placeholder, sqlType);
4009
3954
  default:
4010
3955
  return (placeholder) => placeholder;
4011
3956
  }
@@ -5344,7 +5289,7 @@ function orderToString(order) {
5344
5289
  }
5345
5290
  return order.toString();
5346
5291
  }
5347
- function createColumn(columnName, tableName, modelName, propertyName, sqlCast) {
5292
+ function createColumn(columnName, tableName, modelName, propertyName, sqlCast, serialize) {
5348
5293
  const fn = function() {
5349
5294
  return columnName;
5350
5295
  };
@@ -5379,6 +5324,11 @@ function createColumn(columnName, tableName, modelName, propertyName, sqlCast) {
5379
5324
  writable: false,
5380
5325
  enumerable: true
5381
5326
  });
5327
+ Object.defineProperty(fn, "serialize", {
5328
+ value: serialize,
5329
+ writable: false,
5330
+ enumerable: false
5331
+ });
5382
5332
  if (sqlCast) {
5383
5333
  fn.eq = (value) => ({ [columnName]: new DBCast(value, sqlCast, "=") });
5384
5334
  fn.ne = (value) => ({ [columnName]: new DBCast(value, sqlCast, "!=") });
@@ -5525,7 +5475,12 @@ function createOrCond(condGroups) {
5525
5475
  function isOrCond(cond) {
5526
5476
  return typeof cond === "object" && cond !== null && "_type" in cond && cond._type === "or";
5527
5477
  }
5528
- function condToKeyValue(cond) {
5478
+ function serializeCondValue(col, value, typeCast) {
5479
+ const serialize = col.serialize;
5480
+ if (serialize === void 0) return value;
5481
+ return Array.isArray(value) ? value.map((v) => serialize(v, typeCast)) : serialize(value, typeCast);
5482
+ }
5483
+ function condToKeyValue(cond, typeCast) {
5529
5484
  if (cond.length === 1) {
5530
5485
  return [cond[0], true];
5531
5486
  }
@@ -5535,7 +5490,7 @@ function condToKeyValue(cond) {
5535
5490
  }
5536
5491
  if (Array.isArray(keyOrCol)) {
5537
5492
  const columns = keyOrCol;
5538
- const tuples = value;
5493
+ const tuples = value.map((t) => t.map((v, i) => serializeCondValue(columns[i], v, typeCast)));
5539
5494
  const columnNames = columns.map((col2) => col2.columnName);
5540
5495
  return ["__tuple__", dbTupleIn(columnNames, tuples)];
5541
5496
  }
@@ -5550,13 +5505,14 @@ function condToKeyValue(cond) {
5550
5505
  if (value instanceof DBToken) {
5551
5506
  return [col.columnName, value];
5552
5507
  }
5508
+ const bound = serializeCondValue(col, value, typeCast);
5553
5509
  if (sqlCast) {
5554
- if (Array.isArray(value)) {
5555
- return [col.columnName, new DBCastArray(value, sqlCast)];
5510
+ if (Array.isArray(bound)) {
5511
+ return [col.columnName, new DBCastArray(bound, sqlCast)];
5556
5512
  }
5557
- return [col.columnName, new DBCast(value, sqlCast, "=")];
5513
+ return [col.columnName, new DBCast(bound, sqlCast, "=")];
5558
5514
  }
5559
- return [col.columnName, value];
5515
+ return [col.columnName, bound];
5560
5516
  }
5561
5517
  function sqlFragmentToKeyValue(frag) {
5562
5518
  if (frag.params.length === 0) {
@@ -5567,14 +5523,14 @@ function sqlFragmentToKeyValue(frag) {
5567
5523
  }
5568
5524
  return [frag.sql, [...frag.params]];
5569
5525
  }
5570
- function condsToRecord(conditions) {
5526
+ function condsToRecord(conditions, typeCast) {
5571
5527
  const result = {};
5572
5528
  for (const cond of conditions) {
5573
5529
  if (cond === SKIP) {
5574
5530
  continue;
5575
5531
  }
5576
5532
  if (isOrCond(cond)) {
5577
- const orGroups = cond.conditions.map((group) => condsToRecord(group));
5533
+ const orGroups = cond.conditions.map((group) => condsToRecord(group, typeCast));
5578
5534
  result["__or__"] = orGroups;
5579
5535
  } else if (isAnySqlFragment(cond)) {
5580
5536
  const kv = sqlFragmentToKeyValue(cond);
@@ -5583,7 +5539,7 @@ function condsToRecord(conditions) {
5583
5539
  result[key] = value;
5584
5540
  }
5585
5541
  } else {
5586
- const kv = condToKeyValue(cond);
5542
+ const kv = condToKeyValue(cond, typeCast);
5587
5543
  if (kv === null) continue;
5588
5544
  const [key, value] = kv;
5589
5545
  result[key] = value;
@@ -6463,6 +6419,14 @@ function rejectNonText(family, val) {
6463
6419
  }
6464
6420
  return val;
6465
6421
  }
6422
+ function materializeString(family, v) {
6423
+ if (v === void 0 || v === null) return v;
6424
+ if (typeof v === "string") return v;
6425
+ if (typeof v === "number" || typeof v === "bigint" || typeof v === "boolean") return String(v);
6426
+ throw new Error(
6427
+ `materialize ${family}: driver returned ${typeof v} for a ${family} column. Use @column.passthrough() for a BYTEA/BLOB column, or @column.json<T>() for JSON.`
6428
+ );
6429
+ }
6466
6430
  function createColumnDecorator(typeCast, serialize, sqlCast, baseSqlType) {
6467
6431
  return function(columnNameOrOptions) {
6468
6432
  return function(targetOrValue, keyOrContext) {
@@ -6492,7 +6456,7 @@ function createColumnDecorator(typeCast, serialize, sqlCast, baseSqlType) {
6492
6456
  }
6493
6457
  function requireColumnFamily() {
6494
6458
  throw new Error(
6495
- "litedbmodel: `@column()` no longer declares a column \u2014 a column must state its type with a family: @column.text() / .number() / .boolean() / .bigint() / .datetime() / .date() / .uuid() / .json() / .stringArray() / .intArray() / .numericArray() / .booleanArray() / .datetimeArray() / .passthrough() / .custom(). Every family takes the same argument as `@column()` did (`@column.text('db_name')`, `@column.number({ primaryKey: true })`). The bare form inferred the type from `emitDecoratorMetadata`, which esbuild (tsx/vite/vitest) never emits and standard decorators do not have, so it silently produced untyped reads."
6459
+ "litedbmodel: `@column()` no longer declares a column \u2014 a column must state its type with a family: @column.text() / .decimal() / .number() / .boolean() / .bigint() / .datetime() / .date() / .uuid() / .json() / .stringArray() / .intArray() / .numericArray() / .booleanArray() / .datetimeArray() / .passthrough() / .custom(). Every family takes the same argument as `@column()` did (`@column.text('db_name')`, `@column.number({ primaryKey: true })`). The bare form inferred the type from `emitDecoratorMetadata`, which esbuild (tsx/vite/vitest) never emits and standard decorators do not have, so it silently produced untyped reads."
6496
6460
  );
6497
6461
  }
6498
6462
  function serializeArray(val, typeCast) {
@@ -6545,17 +6509,8 @@ var column = Object.assign(
6545
6509
  * @example @column.text('user_name') name?: string;
6546
6510
  */
6547
6511
  text: (columnNameOrOptions) => createColumnDecorator(
6548
- // The family DECLARES `string`, so it must hand back one. Most drivers already do, but SQLite
6549
- // is dynamically typed: it returns a JS number for a `NUMERIC`/`DECIMAL` column whatever the
6550
- // declaration says, and the declared type would be a lie on that dialect alone.
6551
- (v) => {
6552
- if (v === void 0 || v === null) return v;
6553
- if (typeof v === "string") return v;
6554
- if (typeof v === "number" || typeof v === "bigint" || typeof v === "boolean") return String(v);
6555
- throw new Error(
6556
- `materialize text: driver returned ${typeof v} for a text column. Use @column.passthrough() for a BYTEA/BLOB column, or @column.json<T>() for JSON.`
6557
- );
6558
- },
6512
+ (v) => materializeString("text", v),
6513
+ // the family DECLARES `string`, so it hands back one
6559
6514
  (val) => rejectNonText("text", val),
6560
6515
  // …and it cannot SERIALIZE a Date or an object
6561
6516
  void 0,
@@ -6563,6 +6518,18 @@ var column = Object.assign(
6563
6518
  "TEXT"
6564
6519
  // §4.1 token: types the SCP typed read
6565
6520
  )(columnNameOrOptions),
6521
+ /**
6522
+ * Exact decimal type (NUMERIC / DECIMAL) — read back as its exact decimal STRING (a JS number
6523
+ * rounds past 2^53). The family states the column is `numeric`, so a write binds the string as a
6524
+ * numeric — a batch write (`createMany` / `updateMany`) included.
6525
+ * @example @column.decimal() price?: string;
6526
+ */
6527
+ decimal: (columnNameOrOptions) => createColumnDecorator(
6528
+ (v) => materializeString("decimal", v),
6529
+ (val) => rejectNonText("decimal", val),
6530
+ "numeric"
6531
+ // sqlCast for WHERE / INSERT / batch-write type casting
6532
+ )(columnNameOrOptions),
6566
6533
  /**
6567
6534
  * Boolean type conversion
6568
6535
  * Converts 't'/'f', 'true'/'false', 1/0 to boolean
@@ -6690,7 +6657,7 @@ var column = Object.assign(
6690
6657
  (v) => {
6691
6658
  if (v === void 0) return void 0;
6692
6659
  if (v === null) return null;
6693
- return castToStringArray(v);
6660
+ return castToStringArray2(v);
6694
6661
  },
6695
6662
  serializeArray,
6696
6663
  "text[]"
@@ -6704,7 +6671,7 @@ var column = Object.assign(
6704
6671
  (v) => {
6705
6672
  if (v === void 0) return void 0;
6706
6673
  if (v === null) return null;
6707
- return castToIntegerArray(v);
6674
+ return castToIntegerArray2(v);
6708
6675
  },
6709
6676
  serializeArray,
6710
6677
  "int[]"
@@ -6718,7 +6685,7 @@ var column = Object.assign(
6718
6685
  (v) => {
6719
6686
  if (v === void 0) return void 0;
6720
6687
  if (v === null) return null;
6721
- return castToNumericArray(v);
6688
+ return castToNumericArray2(v);
6722
6689
  },
6723
6690
  serializeArray,
6724
6691
  "numeric[]"
@@ -6732,7 +6699,7 @@ var column = Object.assign(
6732
6699
  (v) => {
6733
6700
  if (v === void 0) return void 0;
6734
6701
  if (v === null) return null;
6735
- return castToBooleanArray(v);
6702
+ return castToBooleanArray2(v);
6736
6703
  },
6737
6704
  serializeBooleanArray,
6738
6705
  "boolean[]"
@@ -6750,7 +6717,7 @@ var column = Object.assign(
6750
6717
  (v) => {
6751
6718
  if (v === void 0) return void 0;
6752
6719
  if (v === null) return null;
6753
- return castToDatetimeArray(v).map((d) => d === null ? null : materializeCell(d, "date"));
6720
+ return castToDatetimeArray2(v).map((d) => d === null ? null : materializeCell(d, "date"));
6754
6721
  },
6755
6722
  // DateTime arrays serialize each Date to ISO string
6756
6723
  (val) => {
@@ -6773,7 +6740,7 @@ var column = Object.assign(
6773
6740
  (v) => {
6774
6741
  if (v === void 0) return void 0;
6775
6742
  if (v === null) return null;
6776
- return castToJson(v);
6743
+ return castToJson2(v);
6777
6744
  },
6778
6745
  serializeJson,
6779
6746
  "jsonb"
@@ -6984,7 +6951,7 @@ function applyModelDecorator(constructor, members, tableName, options) {
6984
6951
  const effectiveTableName = tableName ?? modelName.toLowerCase();
6985
6952
  for (const [propKey, meta] of columns) {
6986
6953
  Object.defineProperty(constructor, propKey, {
6987
- value: createColumn(meta.columnName, effectiveTableName, modelName, propKey, meta.sqlCast),
6954
+ value: createColumn(meta.columnName, effectiveTableName, modelName, propKey, meta.sqlCast, meta.serialize),
6988
6955
  writable: false,
6989
6956
  enumerable: true,
6990
6957
  configurable: false
@@ -7028,12 +6995,11 @@ function applyModelDecorator(constructor, members, tableName, options) {
7028
6995
  const keys = keysFactory();
7029
6996
  const { sourceKeys, targetKeys, targetModelName } = parseKeys(keys);
7030
6997
  const order = options2?.order ? orderToString(options2.order()) : null;
7031
- const conditions = options2?.where ? condsToRecord(options2.where()) : void 0;
7032
6998
  return this._loadRelation(type, targetModelName, {
7033
6999
  sourceKeys,
7034
7000
  targetKeys,
7035
7001
  order,
7036
- conditions,
7002
+ where: options2?.where?.(),
7037
7003
  limit: options2?.limit,
7038
7004
  hardLimit: options2?.hardLimit,
7039
7005
  relationName: propertyKey
@@ -7164,18 +7130,23 @@ function serializeRecord(modelClass, record, typeCast) {
7164
7130
  if (serializeMap.size === 0) {
7165
7131
  return record;
7166
7132
  }
7133
+ let result = record;
7167
7134
  for (const key of Object.keys(record)) {
7168
7135
  const serialize = serializeMap.get(key);
7169
7136
  if (serialize) {
7170
- record[key] = serialize(record[key], typeCast);
7137
+ if (result === record) {
7138
+ result = { ...record };
7139
+ }
7140
+ result[key] = serialize(record[key], typeCast);
7171
7141
  }
7172
7142
  }
7173
- return record;
7143
+ return result;
7174
7144
  }
7175
7145
 
7176
7146
  // src/scp/decorator-adapter.ts
7177
7147
  var COLUMN_FAMILY_SQL_TYPE = {
7178
7148
  boolean: "BOOLEAN",
7149
+ numeric: "NUMERIC",
7179
7150
  bigint: "BIGINT",
7180
7151
  timestamp: "TIMESTAMP",
7181
7152
  date: "DATE",
@@ -7328,23 +7299,6 @@ function createDriver(config, options) {
7328
7299
  }
7329
7300
  function getTypeCastForDriver(driverType) {
7330
7301
  if (driverType === "sqlite") {
7331
- return {
7332
- castToDatetime: castToDatetime3,
7333
- castToBoolean: castToBoolean3,
7334
- castToIntegerArray: castToIntegerArray3,
7335
- castToNumericArray: (val) => castToIntegerArray3(val).map((v) => v),
7336
- castToStringArray: castToStringArray3,
7337
- castToBooleanArray: (val) => {
7338
- const arr = castToStringArray3(val);
7339
- return arr.map((v) => castToBoolean3(v));
7340
- },
7341
- castToDatetimeArray: (val) => {
7342
- const arr = castToStringArray3(val);
7343
- return arr.map((v) => castToDatetime3(v));
7344
- },
7345
- castToJson: castToJson3
7346
- };
7347
- } else if (driverType === "mysql") {
7348
7302
  return {
7349
7303
  castToDatetime: castToDatetime4,
7350
7304
  castToBoolean: castToBoolean4,
@@ -7361,16 +7315,33 @@ function getTypeCastForDriver(driverType) {
7361
7315
  },
7362
7316
  castToJson: castToJson4
7363
7317
  };
7318
+ } else if (driverType === "mysql") {
7319
+ return {
7320
+ castToDatetime: castToDatetime3,
7321
+ castToBoolean: castToBoolean3,
7322
+ castToIntegerArray: castToIntegerArray3,
7323
+ castToNumericArray: (val) => castToIntegerArray3(val).map((v) => v),
7324
+ castToStringArray: castToStringArray3,
7325
+ castToBooleanArray: (val) => {
7326
+ const arr = castToStringArray3(val);
7327
+ return arr.map((v) => castToBoolean3(v));
7328
+ },
7329
+ castToDatetimeArray: (val) => {
7330
+ const arr = castToStringArray3(val);
7331
+ return arr.map((v) => castToDatetime3(v));
7332
+ },
7333
+ castToJson: castToJson3
7334
+ };
7364
7335
  } else {
7365
7336
  return {
7366
- castToDatetime: castToDatetime2,
7367
- castToBoolean: castToBoolean2,
7368
- castToIntegerArray: castToIntegerArray2,
7369
- castToNumericArray: castToNumericArray2,
7370
- castToStringArray: castToStringArray2,
7371
- castToBooleanArray: castToBooleanArray2,
7372
- castToDatetimeArray: castToDatetimeArray2,
7373
- castToJson: castToJson2
7337
+ castToDatetime,
7338
+ castToBoolean,
7339
+ castToIntegerArray,
7340
+ castToNumericArray,
7341
+ castToStringArray,
7342
+ castToBooleanArray,
7343
+ castToDatetimeArray,
7344
+ castToJson
7374
7345
  };
7375
7346
  }
7376
7347
  }
@@ -8382,6 +8353,30 @@ var DBModel = class _DBModel {
8382
8353
  return void 0;
8383
8354
  }
8384
8355
  }
8356
+ /**
8357
+ * A subquery's `[column, value]` conditions, each literal value bound the way the column's family
8358
+ * writes it (see {@link _getConditionTypeCast}); a correlation reference passes through.
8359
+ * @internal
8360
+ */
8361
+ static _subqueryConditions(conditions) {
8362
+ const typeCast = this._getConditionTypeCast();
8363
+ return conditions.map(([col, value]) => ({
8364
+ column: col,
8365
+ value: value instanceof DBToken ? value : serializeCondValue(col, value, typeCast)
8366
+ }));
8367
+ }
8368
+ /**
8369
+ * The driver's type cast a condition value binds with — the one a create / update serializes with.
8370
+ * Returns undefined if DBHandler is not initialized, like {@link _getSqlCastFormatter}.
8371
+ * @internal
8372
+ */
8373
+ static _getConditionTypeCast() {
8374
+ try {
8375
+ return getTypeCast2(this.getDriverType());
8376
+ } catch {
8377
+ return void 0;
8378
+ }
8379
+ }
8385
8380
  /**
8386
8381
  * Get a DBHandler instance for this model.
8387
8382
  * Connection priority:
@@ -8616,7 +8611,7 @@ var DBModel = class _DBModel {
8616
8611
  }
8617
8612
  const normalizedCond = normalizeConditions(conditions);
8618
8613
  if (this.FIND_FILTER) {
8619
- const filterCondition = condsToRecord(this.FIND_FILTER);
8614
+ const filterCondition = condsToRecord(this.FIND_FILTER, this._getConditionTypeCast());
8620
8615
  normalizedCond.add(filterCondition);
8621
8616
  }
8622
8617
  const formatter = this._getSqlCastFormatter();
@@ -8735,7 +8730,7 @@ var DBModel = class _DBModel {
8735
8730
  /** Merge FIND_FILTER (the model's default filter) into a condition object (v1 `_buildSelectSQL` parity). */
8736
8731
  static _mergeFindFilter(conditions) {
8737
8732
  if (!this.FIND_FILTER) return conditions;
8738
- const filter = condsToRecord(this.FIND_FILTER);
8733
+ const filter = condsToRecord(this.FIND_FILTER, this._getConditionTypeCast());
8739
8734
  return { ...conditions, ...filter };
8740
8735
  }
8741
8736
  /** Build model instances from raw rows, wiring the deferred relation context (v1 `query` parity). @internal */
@@ -8804,7 +8799,7 @@ var DBModel = class _DBModel {
8804
8799
  }
8805
8800
  const normalizedCond = normalizeConditions(conditions);
8806
8801
  if (this.FIND_FILTER) {
8807
- const filterCondition = condsToRecord(this.FIND_FILTER);
8802
+ const filterCondition = condsToRecord(this.FIND_FILTER, this._getConditionTypeCast());
8808
8803
  normalizedCond.add(filterCondition);
8809
8804
  }
8810
8805
  const formatter = this._getSqlCastFormatter();
@@ -9137,10 +9132,7 @@ var DBModel = class _DBModel {
9137
9132
  const parentColumns = pairs.map((pair) => pair[0]);
9138
9133
  const selectColumns = pairs.map((pair) => pair[1]);
9139
9134
  const targetTableName = selectColumns[0]?.tableName ?? "";
9140
- const subqueryConditions = conditions.map(([col, value]) => ({
9141
- column: col,
9142
- value
9143
- }));
9135
+ const subqueryConditions = this._subqueryConditions(conditions);
9144
9136
  return ["__subquery__", new DBSubquery(parentColumns, targetTableName, selectColumns, subqueryConditions, "IN")];
9145
9137
  }
9146
9138
  /**
@@ -9176,10 +9168,7 @@ var DBModel = class _DBModel {
9176
9168
  const parentColumns = pairs.map((pair) => pair[0]);
9177
9169
  const selectColumns = pairs.map((pair) => pair[1]);
9178
9170
  const targetTableName = selectColumns[0]?.tableName ?? "";
9179
- const subqueryConditions = conditions.map(([col, value]) => ({
9180
- column: col,
9181
- value
9182
- }));
9171
+ const subqueryConditions = this._subqueryConditions(conditions);
9183
9172
  return ["__subquery__", new DBSubquery(parentColumns, targetTableName, selectColumns, subqueryConditions, "NOT IN")];
9184
9173
  }
9185
9174
  /**
@@ -9207,10 +9196,7 @@ var DBModel = class _DBModel {
9207
9196
  */
9208
9197
  static exists(conditions) {
9209
9198
  const targetTableName = conditions[0]?.[0]?.tableName ?? "";
9210
- const subqueryConditions = conditions.map(([col, value]) => ({
9211
- column: col,
9212
- value
9213
- }));
9199
+ const subqueryConditions = this._subqueryConditions(conditions);
9214
9200
  return ["__exists__", new DBExists(targetTableName, subqueryConditions, false)];
9215
9201
  }
9216
9202
  /**
@@ -9237,10 +9223,7 @@ var DBModel = class _DBModel {
9237
9223
  */
9238
9224
  static notExists(conditions) {
9239
9225
  const targetTableName = conditions[0]?.[0]?.tableName ?? "";
9240
- const subqueryConditions = conditions.map(([col, value]) => ({
9241
- column: col,
9242
- value
9243
- }));
9226
+ const subqueryConditions = this._subqueryConditions(conditions);
9244
9227
  return ["__exists__", new DBExists(targetTableName, subqueryConditions, true)];
9245
9228
  }
9246
9229
  // ============================================
@@ -9491,7 +9474,7 @@ var DBModel = class _DBModel {
9491
9474
  }
9492
9475
  const relationConfig = {
9493
9476
  targetClass: TargetClass,
9494
- conditions: config.conditions,
9477
+ conditions: config.where ? condsToRecord(config.where, TargetClass._getConditionTypeCast()) : void 0,
9495
9478
  order: config.order,
9496
9479
  limit: config.limit,
9497
9480
  hardLimit: config.hardLimit,
@@ -9788,7 +9771,7 @@ var DBModel = class _DBModel {
9788
9771
  */
9789
9772
  static find(conditions, options) {
9790
9773
  const core = async (conds, opts) => {
9791
- const conditionRecord = condsToRecord(conds);
9774
+ const conditionRecord = condsToRecord(conds, this._getConditionTypeCast());
9792
9775
  const hardLimit = _DBModel._limitConfig.findHardLimit;
9793
9776
  const shouldCheckLimit = hardLimit != null && !opts?.limit;
9794
9777
  const effectiveOpts = shouldCheckLimit ? { ...opts, limit: hardLimit + 1 } : opts;
@@ -9822,7 +9805,7 @@ var DBModel = class _DBModel {
9822
9805
  */
9823
9806
  static findOne(conditions, options) {
9824
9807
  const core = async (conds, opts) => {
9825
- const conditionRecord = condsToRecord(conds);
9808
+ const conditionRecord = condsToRecord(conds, this._getConditionTypeCast());
9826
9809
  const results = await this._select(conditionRecord, { ...opts, limit: 1 });
9827
9810
  return results.length > 0 ? results[0] : null;
9828
9811
  };
@@ -9900,7 +9883,7 @@ var DBModel = class _DBModel {
9900
9883
  */
9901
9884
  static count(conditions) {
9902
9885
  const core = async (conds) => {
9903
- const conditionRecord = condsToRecord(conds);
9886
+ const conditionRecord = condsToRecord(conds, this._getConditionTypeCast());
9904
9887
  return this._count(conditionRecord);
9905
9888
  };
9906
9889
  return this._applyMiddleware("count", core, [conditions]);
@@ -10034,7 +10017,7 @@ var DBModel = class _DBModel {
10034
10017
  */
10035
10018
  static update(conditions, values, options) {
10036
10019
  const core = async (conds, vals, opts) => {
10037
- const conditionRecord = condsToRecord(conds);
10020
+ const conditionRecord = condsToRecord(conds, this._getConditionTypeCast());
10038
10021
  const valueRecord = pairsToRecord(vals);
10039
10022
  if (!opts?.returning) {
10040
10023
  await this._update(conditionRecord, valueRecord, {});
@@ -10086,7 +10069,7 @@ var DBModel = class _DBModel {
10086
10069
  */
10087
10070
  static delete(conditions, options) {
10088
10071
  const core = async (conds, opts) => {
10089
- const conditionRecord = condsToRecord(conds);
10072
+ const conditionRecord = condsToRecord(conds, this._getConditionTypeCast());
10090
10073
  if (!opts?.returning) {
10091
10074
  await this._delete(conditionRecord, {});
10092
10075
  return null;