tempest-db-js 0.7.0 → 0.8.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 +1 -0
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +2 -2
- package/dist/{chunk-SI4CLSF7.js → chunk-MF6O56RO.js} +3 -3
- package/dist/{chunk-SI4CLSF7.js.map → chunk-MF6O56RO.js.map} +1 -1
- package/dist/{chunk-4AWUP7BM.js → chunk-NH6K5LTX.js} +106 -10
- package/dist/chunk-NH6K5LTX.js.map +1 -0
- package/dist/index.cjs +104 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -2
- package/dist/index.d.ts +50 -2
- package/dist/index.js +1 -1
- package/dist/migrations/index.cjs.map +1 -1
- package/dist/migrations/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-4AWUP7BM.js.map +0 -1
|
@@ -2044,6 +2044,68 @@ var NodeSqliteDriver = class _NodeSqliteDriver {
|
|
|
2044
2044
|
this.db.close();
|
|
2045
2045
|
}
|
|
2046
2046
|
};
|
|
2047
|
+
var BetterSqliteDriver = class _BetterSqliteDriver {
|
|
2048
|
+
// biome-ignore lint/suspicious/noExplicitAny: the peer dep's types are optional here.
|
|
2049
|
+
db;
|
|
2050
|
+
/** Prepared-statement cache keyed by SQL text — see {@link NodeSqliteDriver}. */
|
|
2051
|
+
// biome-ignore lint/suspicious/noExplicitAny: see above.
|
|
2052
|
+
statements = /* @__PURE__ */ new Map();
|
|
2053
|
+
// biome-ignore lint/suspicious/noExplicitAny: accept an already-open Database handle.
|
|
2054
|
+
constructor(database) {
|
|
2055
|
+
this.db = database;
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Open a `better-sqlite3` database at the given path (or `":memory:"`).
|
|
2059
|
+
*
|
|
2060
|
+
* @param path The database file, or `":memory:"`.
|
|
2061
|
+
* @param options Passed straight to `new Database()` (`readonly`, `timeout`, …).
|
|
2062
|
+
* @returns A driver over the open handle.
|
|
2063
|
+
* @throws If `better-sqlite3` is not installed — it is an optional peer
|
|
2064
|
+
* dependency, so the error names the package to install.
|
|
2065
|
+
*/
|
|
2066
|
+
static open(path, options) {
|
|
2067
|
+
let Database;
|
|
2068
|
+
try {
|
|
2069
|
+
const mod = nodeRequire("better-sqlite3");
|
|
2070
|
+
Database = mod.default ?? mod;
|
|
2071
|
+
} catch (cause) {
|
|
2072
|
+
throw new Error(
|
|
2073
|
+
'The "better-sqlite3" driver requires the better-sqlite3 package: npm install better-sqlite3',
|
|
2074
|
+
{ cause }
|
|
2075
|
+
);
|
|
2076
|
+
}
|
|
2077
|
+
return new _BetterSqliteDriver(
|
|
2078
|
+
options ? new Database(path, { ...options }) : new Database(path)
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
/** Return the cached prepared statement for `sql`, preparing it on first use. */
|
|
2082
|
+
// biome-ignore lint/suspicious/noExplicitAny: statement type is optional here.
|
|
2083
|
+
prepare(sql2) {
|
|
2084
|
+
const cached = this.statements.get(sql2);
|
|
2085
|
+
if (cached) return cached;
|
|
2086
|
+
const stmt = this.db.prepare(sql2);
|
|
2087
|
+
this.statements.set(sql2, stmt);
|
|
2088
|
+
return stmt;
|
|
2089
|
+
}
|
|
2090
|
+
execute(sql2, params) {
|
|
2091
|
+
const stmt = this.prepare(sql2);
|
|
2092
|
+
const bound = params.map(encodeSqliteParam);
|
|
2093
|
+
if (stmt.reader) {
|
|
2094
|
+
return { rows: stmt.all(...bound), changes: 0 };
|
|
2095
|
+
}
|
|
2096
|
+
const info = stmt.run(...bound);
|
|
2097
|
+
return { rows: [], changes: Number(info.changes ?? 0) };
|
|
2098
|
+
}
|
|
2099
|
+
*iterate(sql2, params) {
|
|
2100
|
+
const stmt = this.prepare(sql2);
|
|
2101
|
+
const bound = params.map(encodeSqliteParam);
|
|
2102
|
+
yield* stmt.iterate(...bound);
|
|
2103
|
+
}
|
|
2104
|
+
close() {
|
|
2105
|
+
this.statements.clear();
|
|
2106
|
+
this.db.close();
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2047
2109
|
function returnsRows(sql2) {
|
|
2048
2110
|
return /^\s*(select|pragma)/i.test(sql2) || /\breturning\b/i.test(sql2);
|
|
2049
2111
|
}
|
|
@@ -2567,8 +2629,43 @@ function asAsync(driver) {
|
|
|
2567
2629
|
} : {}
|
|
2568
2630
|
};
|
|
2569
2631
|
}
|
|
2570
|
-
|
|
2571
|
-
|
|
2632
|
+
var SQLITE_DRIVER_ALIASES = {
|
|
2633
|
+
"node:sqlite": "node:sqlite",
|
|
2634
|
+
"node-sqlite": "node:sqlite",
|
|
2635
|
+
node: "node:sqlite",
|
|
2636
|
+
"better-sqlite3": "better-sqlite3",
|
|
2637
|
+
better_sqlite3: "better-sqlite3",
|
|
2638
|
+
bettersqlite3: "better-sqlite3"
|
|
2639
|
+
};
|
|
2640
|
+
var SERVER_DRIVER_ALIASES = {
|
|
2641
|
+
postgresql: ["postgres", "postgres.js", "postgresjs", "pg"],
|
|
2642
|
+
mysql: ["mysql", "mysql2"]
|
|
2643
|
+
};
|
|
2644
|
+
function checkServerDriver(dialect, driver) {
|
|
2645
|
+
if (!driver) return;
|
|
2646
|
+
const accepted = SERVER_DRIVER_ALIASES[dialect] ?? [];
|
|
2647
|
+
if (accepted.includes(driver.toLowerCase())) return;
|
|
2648
|
+
throw new Error(
|
|
2649
|
+
`Unknown ${dialect} driver ${JSON.stringify(driver)}; tempest-db-js runs ${dialect} on ${JSON.stringify(accepted[0])}.`
|
|
2650
|
+
);
|
|
2651
|
+
}
|
|
2652
|
+
function resolveSqliteDriver(parsed, options) {
|
|
2653
|
+
const explicit = options?.driver;
|
|
2654
|
+
if (explicit) {
|
|
2655
|
+
const resolved = SQLITE_DRIVER_ALIASES[explicit.toLowerCase()];
|
|
2656
|
+
if (!resolved) {
|
|
2657
|
+
throw new Error(
|
|
2658
|
+
`Unknown SQLite driver ${JSON.stringify(explicit)}; supported: "node:sqlite" (built-in, default) and "better-sqlite3".`
|
|
2659
|
+
);
|
|
2660
|
+
}
|
|
2661
|
+
return resolved;
|
|
2662
|
+
}
|
|
2663
|
+
const fromUrl = parsed.driver ? SQLITE_DRIVER_ALIASES[parsed.driver.toLowerCase()] : void 0;
|
|
2664
|
+
return fromUrl ?? "node:sqlite";
|
|
2665
|
+
}
|
|
2666
|
+
function openSqliteDriver(parsed, options) {
|
|
2667
|
+
const path = parsed.database ?? ":memory:";
|
|
2668
|
+
return resolveSqliteDriver(parsed, options) === "better-sqlite3" ? BetterSqliteDriver.open(path, options?.driverOptions) : NodeSqliteDriver.open(path, options?.driverOptions);
|
|
2572
2669
|
}
|
|
2573
2670
|
function createSyncEngine(url, options) {
|
|
2574
2671
|
const parsed = parseDatabaseUrl(url);
|
|
@@ -2577,27 +2674,26 @@ function createSyncEngine(url, options) {
|
|
|
2577
2674
|
`createSyncEngine supports only SQLite; ${parsed.dialect} is async-only \u2014 use createEngine.`
|
|
2578
2675
|
);
|
|
2579
2676
|
}
|
|
2580
|
-
return new SyncEngine(
|
|
2581
|
-
openSqliteDriver(parsed.database ?? ":memory:", options),
|
|
2582
|
-
options?.onQuery
|
|
2583
|
-
);
|
|
2677
|
+
return new SyncEngine(openSqliteDriver(parsed, options), options?.onQuery);
|
|
2584
2678
|
}
|
|
2585
2679
|
function createEngine(url, options) {
|
|
2586
2680
|
const parsed = parseDatabaseUrl(url);
|
|
2587
2681
|
if (parsed.dialect === "sqlite") {
|
|
2588
2682
|
return new AsyncEngine(
|
|
2589
|
-
asAsync(openSqliteDriver(parsed
|
|
2683
|
+
asAsync(openSqliteDriver(parsed, options)),
|
|
2590
2684
|
"sqlite",
|
|
2591
2685
|
options?.onQuery
|
|
2592
2686
|
);
|
|
2593
2687
|
}
|
|
2594
2688
|
if (parsed.dialect === "mysql") {
|
|
2689
|
+
checkServerDriver("mysql", options?.driver);
|
|
2595
2690
|
return new AsyncEngine(
|
|
2596
2691
|
createMysqlDriver(parsed.raw, options),
|
|
2597
2692
|
"mysql",
|
|
2598
2693
|
options?.onQuery
|
|
2599
2694
|
);
|
|
2600
2695
|
}
|
|
2696
|
+
checkServerDriver("postgresql", options?.driver);
|
|
2601
2697
|
return new AsyncEngine(
|
|
2602
2698
|
createPostgresDriver(parsed.raw, options),
|
|
2603
2699
|
"postgresql",
|
|
@@ -3071,6 +3167,6 @@ function dbColumn(names, prop) {
|
|
|
3071
3167
|
return names?.[prop] ?? prop;
|
|
3072
3168
|
}
|
|
3073
3169
|
|
|
3074
|
-
export { ActiveRecord, Agg, AsyncEngine, AsyncResult, AsyncSession, BaseDialect, BaseRepository, Column, DeleteBuilder, Expression, InsertBuilder, InvalidDatabaseUrl, JoinBuilder, Model, MysqlDialect, NoResultError, NodeSqliteDriver, OPERATORS, Params, PostgresDialect, QueryExecutionError, RecordNotFound, SelectBuilder, SqliteDialect, SyncEngine, SyncResult, SyncSession, UpdateBuilder, ValidationError, activeRecord, and, avg, belongsTo, col, column, columnNamesOf, columnPropsOf, columnsOf, count, createEngine, createSyncEngine, dbColumn, del, detectDialect, fn, foreignKey, fromDict, getDialect, hasMany, insert, isCondition, isExpression, isSqlExpression, isSubquery, join, loadRelations, max, min, not, or, parse, parseDatabaseUrl, renderPortableToken, select, sql, stringify, sum, toAsyncDriver, toCondNode, toDict, toJSON, toSnakeCase, unique, update, val };
|
|
3075
|
-
//# sourceMappingURL=chunk-
|
|
3076
|
-
//# sourceMappingURL=chunk-
|
|
3170
|
+
export { ActiveRecord, Agg, AsyncEngine, AsyncResult, AsyncSession, BaseDialect, BaseRepository, BetterSqliteDriver, Column, DeleteBuilder, Expression, InsertBuilder, InvalidDatabaseUrl, JoinBuilder, Model, MysqlDialect, NoResultError, NodeSqliteDriver, OPERATORS, Params, PostgresDialect, QueryExecutionError, RecordNotFound, SelectBuilder, SqliteDialect, SyncEngine, SyncResult, SyncSession, UpdateBuilder, ValidationError, activeRecord, and, avg, belongsTo, col, column, columnNamesOf, columnPropsOf, columnsOf, count, createEngine, createSyncEngine, dbColumn, del, detectDialect, fn, foreignKey, fromDict, getDialect, hasMany, insert, isCondition, isExpression, isSqlExpression, isSubquery, join, loadRelations, max, min, not, or, parse, parseDatabaseUrl, renderPortableToken, select, sql, stringify, sum, toAsyncDriver, toCondNode, toDict, toJSON, toSnakeCase, unique, update, val };
|
|
3171
|
+
//# sourceMappingURL=chunk-NH6K5LTX.js.map
|
|
3172
|
+
//# sourceMappingURL=chunk-NH6K5LTX.js.map
|