bun-query-builder 0.2.37 → 0.2.39
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/dist/actions/schema-drift.d.ts +1 -1
- package/dist/bin/cli.js +36 -11
- package/dist/db.d.ts +7 -0
- package/dist/src/index.js +35 -10
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ export declare function familyOfSqlType(sqlType: string): TypeFamily;
|
|
|
11
11
|
* model asking for `varchar` is content in a `text` column, because nothing is
|
|
12
12
|
* lost. The reverse is exactly the bug this exists to find.
|
|
13
13
|
*/
|
|
14
|
-
export declare function satisfies(declared: TypeFamily, actual: TypeFamily): boolean;
|
|
14
|
+
export declare function satisfies(declared: TypeFamily, actual: TypeFamily, dialect?: SupportedDialect): boolean;
|
|
15
15
|
/**
|
|
16
16
|
* Audit the live database against a migration plan.
|
|
17
17
|
*
|
package/dist/bin/cli.js
CHANGED
|
@@ -12290,14 +12290,29 @@ function getOrCreateBunSql(forceNew = false) {
|
|
|
12290
12290
|
const signature = connectionSignature();
|
|
12291
12291
|
const configChanged = _bunSqlInstance !== null && _currentSignature !== signature;
|
|
12292
12292
|
if (forceNew || configChanged || !_bunSqlInstance) {
|
|
12293
|
+
if (_bunSqlInstance)
|
|
12294
|
+
resetConnection();
|
|
12293
12295
|
_bunSqlInstance = getBunSql();
|
|
12294
12296
|
_currentSignature = signature;
|
|
12295
12297
|
}
|
|
12296
12298
|
return _bunSqlInstance;
|
|
12297
12299
|
}
|
|
12298
|
-
function
|
|
12300
|
+
function detachCachedConnection() {
|
|
12301
|
+
const connection = _bunSqlInstance;
|
|
12299
12302
|
_bunSqlInstance = null;
|
|
12300
12303
|
_currentSignature = null;
|
|
12304
|
+
return connection;
|
|
12305
|
+
}
|
|
12306
|
+
async function closeSqlConnection(connection) {
|
|
12307
|
+
if (!connection || typeof connection.close !== "function")
|
|
12308
|
+
return;
|
|
12309
|
+
await connection.close();
|
|
12310
|
+
}
|
|
12311
|
+
function resetConnection() {
|
|
12312
|
+
const closing = closeSqlConnection(detachCachedConnection());
|
|
12313
|
+
closing.catch((error) => {
|
|
12314
|
+
console.error(`[query-builder] Failed to close database connection: ${error.message}`);
|
|
12315
|
+
});
|
|
12301
12316
|
}
|
|
12302
12317
|
async function withFreshConnection(fn) {
|
|
12303
12318
|
try {
|
|
@@ -19567,21 +19582,25 @@ async function resetDatabase(dir, opts = {}) {
|
|
|
19567
19582
|
} else {
|
|
19568
19583
|
info("-- No enum types found to drop");
|
|
19569
19584
|
}
|
|
19570
|
-
if (tableNames.length > 0) {
|
|
19585
|
+
if (tableNames.length > 0 && !opts.preserveMigrationState) {
|
|
19571
19586
|
try {
|
|
19572
19587
|
await deleteMigrationFiles(dir, workspaceRoot, opts);
|
|
19573
19588
|
} catch (err) {
|
|
19574
19589
|
console.error(err);
|
|
19575
19590
|
info("-- Could not clean up migration files");
|
|
19576
19591
|
}
|
|
19577
|
-
} else {
|
|
19592
|
+
} else if (tableNames.length === 0) {
|
|
19578
19593
|
info("-- No models directory found; keeping committed migration files in place");
|
|
19594
|
+
} else {
|
|
19595
|
+
info("-- Preserving migration files and model snapshot for fresh replay");
|
|
19579
19596
|
}
|
|
19580
|
-
|
|
19581
|
-
|
|
19582
|
-
|
|
19583
|
-
|
|
19584
|
-
|
|
19597
|
+
if (!opts.preserveMigrationState) {
|
|
19598
|
+
try {
|
|
19599
|
+
await clearGeneratedDirectory(workspaceRoot);
|
|
19600
|
+
} catch (err) {
|
|
19601
|
+
console.error(err);
|
|
19602
|
+
info("-- Could not clear generated directory");
|
|
19603
|
+
}
|
|
19585
19604
|
}
|
|
19586
19605
|
info("-- Database reset completed successfully");
|
|
19587
19606
|
return true;
|
|
@@ -30150,9 +30169,15 @@ function familyOfSqlType(sqlType) {
|
|
|
30150
30169
|
return "integer";
|
|
30151
30170
|
return "other";
|
|
30152
30171
|
}
|
|
30153
|
-
function satisfies(declared, actual) {
|
|
30172
|
+
function satisfies(declared, actual, dialect) {
|
|
30154
30173
|
if (declared === actual)
|
|
30155
30174
|
return true;
|
|
30175
|
+
if (dialect === "sqlite") {
|
|
30176
|
+
if (declared === "boolean" && actual === "integer")
|
|
30177
|
+
return true;
|
|
30178
|
+
if ((declared === "date" || declared === "json") && actual === "text")
|
|
30179
|
+
return true;
|
|
30180
|
+
}
|
|
30156
30181
|
if (declared === "varchar" && actual === "text")
|
|
30157
30182
|
return true;
|
|
30158
30183
|
if (declared === "integer" && actual === "fractional")
|
|
@@ -30184,7 +30209,7 @@ async function auditSchemaDrift(plan, options = {}) {
|
|
|
30184
30209
|
continue;
|
|
30185
30210
|
}
|
|
30186
30211
|
const actual = familyOfSqlType(liveColumn.sqlType);
|
|
30187
|
-
if (!satisfies(declared, actual)) {
|
|
30212
|
+
if (!satisfies(declared, actual, dialect)) {
|
|
30188
30213
|
typeMismatches.push({
|
|
30189
30214
|
table: table.table,
|
|
30190
30215
|
column: column.name,
|
|
@@ -32329,7 +32354,7 @@ function getPrefix() {
|
|
|
32329
32354
|
}
|
|
32330
32355
|
var prefix = getPrefix();
|
|
32331
32356
|
// package.json
|
|
32332
|
-
var version2 = "0.2.
|
|
32357
|
+
var version2 = "0.2.39";
|
|
32333
32358
|
|
|
32334
32359
|
// bin/cli.ts
|
|
32335
32360
|
init_actions();
|
package/dist/db.d.ts
CHANGED
|
@@ -72,6 +72,13 @@ export declare function resolvePoolOptions(pool?: PoolConfig): {
|
|
|
72
72
|
*/
|
|
73
73
|
export declare function getBunSql(): SQL;
|
|
74
74
|
export declare function getOrCreateBunSql(forceNew?: boolean): SQL;
|
|
75
|
+
/**
|
|
76
|
+
* Close and discard the cached connection.
|
|
77
|
+
*
|
|
78
|
+
* Use this when the caller needs to know the pool has fully drained before
|
|
79
|
+
* opening another connection, such as test teardown or a graceful shutdown.
|
|
80
|
+
*/
|
|
81
|
+
export declare function closeConnection(): Promise<void>;
|
|
75
82
|
/**
|
|
76
83
|
* Resets the cached database connection.
|
|
77
84
|
* Call this after changing config via setConfig() to ensure the new config is used.
|
package/dist/src/index.js
CHANGED
|
@@ -12289,14 +12289,29 @@ function getOrCreateBunSql(forceNew = false) {
|
|
|
12289
12289
|
const signature = connectionSignature();
|
|
12290
12290
|
const configChanged = _bunSqlInstance !== null && _currentSignature !== signature;
|
|
12291
12291
|
if (forceNew || configChanged || !_bunSqlInstance) {
|
|
12292
|
+
if (_bunSqlInstance)
|
|
12293
|
+
resetConnection();
|
|
12292
12294
|
_bunSqlInstance = getBunSql();
|
|
12293
12295
|
_currentSignature = signature;
|
|
12294
12296
|
}
|
|
12295
12297
|
return _bunSqlInstance;
|
|
12296
12298
|
}
|
|
12297
|
-
function
|
|
12299
|
+
function detachCachedConnection() {
|
|
12300
|
+
const connection = _bunSqlInstance;
|
|
12298
12301
|
_bunSqlInstance = null;
|
|
12299
12302
|
_currentSignature = null;
|
|
12303
|
+
return connection;
|
|
12304
|
+
}
|
|
12305
|
+
async function closeSqlConnection(connection) {
|
|
12306
|
+
if (!connection || typeof connection.close !== "function")
|
|
12307
|
+
return;
|
|
12308
|
+
await connection.close();
|
|
12309
|
+
}
|
|
12310
|
+
function resetConnection() {
|
|
12311
|
+
const closing = closeSqlConnection(detachCachedConnection());
|
|
12312
|
+
closing.catch((error) => {
|
|
12313
|
+
console.error(`[query-builder] Failed to close database connection: ${error.message}`);
|
|
12314
|
+
});
|
|
12300
12315
|
}
|
|
12301
12316
|
async function withFreshConnection(fn) {
|
|
12302
12317
|
try {
|
|
@@ -19566,21 +19581,25 @@ async function resetDatabase(dir, opts = {}) {
|
|
|
19566
19581
|
} else {
|
|
19567
19582
|
info("-- No enum types found to drop");
|
|
19568
19583
|
}
|
|
19569
|
-
if (tableNames.length > 0) {
|
|
19584
|
+
if (tableNames.length > 0 && !opts.preserveMigrationState) {
|
|
19570
19585
|
try {
|
|
19571
19586
|
await deleteMigrationFiles(dir, workspaceRoot, opts);
|
|
19572
19587
|
} catch (err) {
|
|
19573
19588
|
console.error(err);
|
|
19574
19589
|
info("-- Could not clean up migration files");
|
|
19575
19590
|
}
|
|
19576
|
-
} else {
|
|
19591
|
+
} else if (tableNames.length === 0) {
|
|
19577
19592
|
info("-- No models directory found; keeping committed migration files in place");
|
|
19593
|
+
} else {
|
|
19594
|
+
info("-- Preserving migration files and model snapshot for fresh replay");
|
|
19578
19595
|
}
|
|
19579
|
-
|
|
19580
|
-
|
|
19581
|
-
|
|
19582
|
-
|
|
19583
|
-
|
|
19596
|
+
if (!opts.preserveMigrationState) {
|
|
19597
|
+
try {
|
|
19598
|
+
await clearGeneratedDirectory(workspaceRoot);
|
|
19599
|
+
} catch (err) {
|
|
19600
|
+
console.error(err);
|
|
19601
|
+
info("-- Could not clear generated directory");
|
|
19602
|
+
}
|
|
19584
19603
|
}
|
|
19585
19604
|
info("-- Database reset completed successfully");
|
|
19586
19605
|
return true;
|
|
@@ -30149,9 +30168,15 @@ function familyOfSqlType(sqlType) {
|
|
|
30149
30168
|
return "integer";
|
|
30150
30169
|
return "other";
|
|
30151
30170
|
}
|
|
30152
|
-
function satisfies(declared, actual) {
|
|
30171
|
+
function satisfies(declared, actual, dialect) {
|
|
30153
30172
|
if (declared === actual)
|
|
30154
30173
|
return true;
|
|
30174
|
+
if (dialect === "sqlite") {
|
|
30175
|
+
if (declared === "boolean" && actual === "integer")
|
|
30176
|
+
return true;
|
|
30177
|
+
if ((declared === "date" || declared === "json") && actual === "text")
|
|
30178
|
+
return true;
|
|
30179
|
+
}
|
|
30155
30180
|
if (declared === "varchar" && actual === "text")
|
|
30156
30181
|
return true;
|
|
30157
30182
|
if (declared === "integer" && actual === "fractional")
|
|
@@ -30183,7 +30208,7 @@ async function auditSchemaDrift(plan, options = {}) {
|
|
|
30183
30208
|
continue;
|
|
30184
30209
|
}
|
|
30185
30210
|
const actual = familyOfSqlType(liveColumn.sqlType);
|
|
30186
|
-
if (!satisfies(declared, actual)) {
|
|
30211
|
+
if (!satisfies(declared, actual, dialect)) {
|
|
30187
30212
|
typeMismatches.push({
|
|
30188
30213
|
table: table.table,
|
|
30189
30214
|
column: column.name,
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED