@crvouga/sqlite-mem 1.3.1 → 1.4.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/compat/divergences.json +22 -1
- package/compat/scenarios.ts +7 -4
- package/compat/smoke-baseline.json +1 -13
- package/dist/index.js +39 -15
- package/dist/index.js.map +2 -2
- package/dist/unstable.js +35 -14
- package/dist/unstable.js.map +2 -2
- package/package.json +1 -1
package/dist/unstable.js
CHANGED
|
@@ -1710,11 +1710,16 @@ function parseDate(value, context) {
|
|
|
1710
1710
|
const date = new Date(source);
|
|
1711
1711
|
return Number.isNaN(date.getTime()) ? null : date;
|
|
1712
1712
|
}
|
|
1713
|
-
function applyModifier(date, modifier) {
|
|
1713
|
+
function applyModifier(date, modifier, flags) {
|
|
1714
1714
|
const result = new Date(date);
|
|
1715
1715
|
const normalized = modifier.trim().toLowerCase();
|
|
1716
1716
|
if (normalized === "unixepoch") return new Date((date.getTime() / 864e5 + JULIAN_UNIX_EPOCH) * 1e3);
|
|
1717
1717
|
if (normalized === "utc" || normalized === "localtime") return result;
|
|
1718
|
+
if (normalized === "subsec" || normalized === "subsecond") {
|
|
1719
|
+
flags.subsec = true;
|
|
1720
|
+
return result;
|
|
1721
|
+
}
|
|
1722
|
+
if (normalized === "floor" || normalized === "ceiling") return result;
|
|
1718
1723
|
const weekday = /^weekday\s+([0-6])$/.exec(normalized);
|
|
1719
1724
|
if (weekday) {
|
|
1720
1725
|
const target = Number(weekday[1]);
|
|
@@ -1762,15 +1767,21 @@ function resolveDate(args, context) {
|
|
|
1762
1767
|
if (seconds === null) return null;
|
|
1763
1768
|
source = seconds / 86400 + JULIAN_UNIX_EPOCH;
|
|
1764
1769
|
modifiers = modifiers.slice(1);
|
|
1770
|
+
} else if (typeof modifiers[0] === "string" && modifiers[0].trim().toLowerCase() === "auto") {
|
|
1771
|
+
const number = coerceToNumber(source);
|
|
1772
|
+
if (number === null) return null;
|
|
1773
|
+
source = number >= 0 && number < 53734845e-1 ? number : number / 86400 + JULIAN_UNIX_EPOCH;
|
|
1774
|
+
modifiers = modifiers.slice(1);
|
|
1765
1775
|
}
|
|
1766
1776
|
let date = parseDate(source, context);
|
|
1767
1777
|
if (!date) return null;
|
|
1778
|
+
const flags = { subsec: false };
|
|
1768
1779
|
for (const modifier of modifiers) {
|
|
1769
1780
|
if (typeof modifier !== "string") return null;
|
|
1770
|
-
date = applyModifier(date, modifier);
|
|
1781
|
+
date = applyModifier(date, modifier, flags);
|
|
1771
1782
|
if (!date) return null;
|
|
1772
1783
|
}
|
|
1773
|
-
return date;
|
|
1784
|
+
return { date, subsec: flags.subsec };
|
|
1774
1785
|
}
|
|
1775
1786
|
function pad(value, length = 2) {
|
|
1776
1787
|
return String(value).padStart(length, "0");
|
|
@@ -1778,8 +1789,9 @@ function pad(value, length = 2) {
|
|
|
1778
1789
|
function isoDate(date) {
|
|
1779
1790
|
return `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`;
|
|
1780
1791
|
}
|
|
1781
|
-
function isoTime(date) {
|
|
1782
|
-
|
|
1792
|
+
function isoTime(date, subsec = false) {
|
|
1793
|
+
const base = `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(date.getUTCSeconds())}`;
|
|
1794
|
+
return subsec ? `${base}.${pad(date.getUTCMilliseconds(), 3)}` : base;
|
|
1783
1795
|
}
|
|
1784
1796
|
function dayOfYear(date) {
|
|
1785
1797
|
return Math.floor(
|
|
@@ -1823,24 +1835,24 @@ function formatDate(date, format) {
|
|
|
1823
1835
|
var dateTimeFunctions = {
|
|
1824
1836
|
date(args, context) {
|
|
1825
1837
|
const value = resolveDate(args, context);
|
|
1826
|
-
return value ? isoDate(value) : null;
|
|
1838
|
+
return value ? isoDate(value.date) : null;
|
|
1827
1839
|
},
|
|
1828
1840
|
time(args, context) {
|
|
1829
1841
|
const value = resolveDate(args, context);
|
|
1830
|
-
return value ? isoTime(value) : null;
|
|
1842
|
+
return value ? isoTime(value.date, value.subsec) : null;
|
|
1831
1843
|
},
|
|
1832
1844
|
datetime(args, context) {
|
|
1833
1845
|
const value = resolveDate(args, context);
|
|
1834
|
-
return value ? `${isoDate(value)} ${isoTime(value)}` : null;
|
|
1846
|
+
return value ? `${isoDate(value.date)} ${isoTime(value.date, value.subsec)}` : null;
|
|
1835
1847
|
},
|
|
1836
1848
|
julianday(args, context) {
|
|
1837
1849
|
const value = resolveDate(args, context);
|
|
1838
|
-
return value ? value.getTime() / 864e5 + JULIAN_UNIX_EPOCH : null;
|
|
1850
|
+
return value ? value.date.getTime() / 864e5 + JULIAN_UNIX_EPOCH : null;
|
|
1839
1851
|
},
|
|
1840
1852
|
strftime(args, context) {
|
|
1841
1853
|
if (typeof args[0] !== "string") return null;
|
|
1842
1854
|
const value = resolveDate(args.slice(1), context);
|
|
1843
|
-
return value ? formatDate(value, args[0]) : null;
|
|
1855
|
+
return value ? formatDate(value.date, args[0]) : null;
|
|
1844
1856
|
},
|
|
1845
1857
|
current_date(args, context) {
|
|
1846
1858
|
return dateTimeFunctions.date(args.length === 0 ? ["now"] : args, context);
|
|
@@ -1853,7 +1865,7 @@ var dateTimeFunctions = {
|
|
|
1853
1865
|
},
|
|
1854
1866
|
unixepoch(args, context) {
|
|
1855
1867
|
const value = resolveDate(args.length === 0 ? ["now"] : args, context);
|
|
1856
|
-
return value ? Math.floor(value.getTime() / 1e3) : null;
|
|
1868
|
+
return value ? Math.floor(value.date.getTime() / 1e3) : null;
|
|
1857
1869
|
},
|
|
1858
1870
|
timediff(args) {
|
|
1859
1871
|
if (args.length !== 2) return null;
|
|
@@ -3247,9 +3259,9 @@ function evalExpr(expr, ctx) {
|
|
|
3247
3259
|
return result.rows[0]?.[0] ?? null;
|
|
3248
3260
|
}
|
|
3249
3261
|
case "aggregate":
|
|
3250
|
-
throw new SqliteError("aggregate expression requires aggregate evaluation", "misuse");
|
|
3251
|
-
case "window":
|
|
3252
3262
|
throw new SqliteError("window expression requires window evaluation", "misuse");
|
|
3263
|
+
case "window":
|
|
3264
|
+
throw new SqliteError("misuse of window function", "misuse");
|
|
3253
3265
|
case "row":
|
|
3254
3266
|
throw new SqliteError("row value cannot be used as a scalar value", "misuse");
|
|
3255
3267
|
}
|
|
@@ -7957,8 +7969,17 @@ var Table = class _Table {
|
|
|
7957
7969
|
}
|
|
7958
7970
|
return this.maximumRowid === null ? 1 : incrementRowid(this.maximumRowid);
|
|
7959
7971
|
}
|
|
7972
|
+
const maxSigned = 9223372036854775807n;
|
|
7960
7973
|
let candidate = canonicalRowid(this.nextRowid);
|
|
7961
|
-
while (this.rows.has(candidate))
|
|
7974
|
+
while (this.rows.has(candidate)) {
|
|
7975
|
+
if (BigInt(candidate) >= maxSigned) {
|
|
7976
|
+
throw new SqliteError("database or disk is full", "other", "SQLITE_FULL");
|
|
7977
|
+
}
|
|
7978
|
+
candidate = incrementRowid(candidate);
|
|
7979
|
+
}
|
|
7980
|
+
if (BigInt(candidate) > maxSigned) {
|
|
7981
|
+
throw new SqliteError("database or disk is full", "other", "SQLITE_FULL");
|
|
7982
|
+
}
|
|
7962
7983
|
return candidate;
|
|
7963
7984
|
}
|
|
7964
7985
|
advanceNextRowid(rowid) {
|