bun-query-builder 0.2.38 → 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.
@@ -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 resetConnection() {
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 {
@@ -30154,9 +30169,15 @@ function familyOfSqlType(sqlType) {
30154
30169
  return "integer";
30155
30170
  return "other";
30156
30171
  }
30157
- function satisfies(declared, actual) {
30172
+ function satisfies(declared, actual, dialect) {
30158
30173
  if (declared === actual)
30159
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
+ }
30160
30181
  if (declared === "varchar" && actual === "text")
30161
30182
  return true;
30162
30183
  if (declared === "integer" && actual === "fractional")
@@ -30188,7 +30209,7 @@ async function auditSchemaDrift(plan, options = {}) {
30188
30209
  continue;
30189
30210
  }
30190
30211
  const actual = familyOfSqlType(liveColumn.sqlType);
30191
- if (!satisfies(declared, actual)) {
30212
+ if (!satisfies(declared, actual, dialect)) {
30192
30213
  typeMismatches.push({
30193
30214
  table: table.table,
30194
30215
  column: column.name,
@@ -32333,7 +32354,7 @@ function getPrefix() {
32333
32354
  }
32334
32355
  var prefix = getPrefix();
32335
32356
  // package.json
32336
- var version2 = "0.2.38";
32357
+ var version2 = "0.2.39";
32337
32358
 
32338
32359
  // bin/cli.ts
32339
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 resetConnection() {
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 {
@@ -30153,9 +30168,15 @@ function familyOfSqlType(sqlType) {
30153
30168
  return "integer";
30154
30169
  return "other";
30155
30170
  }
30156
- function satisfies(declared, actual) {
30171
+ function satisfies(declared, actual, dialect) {
30157
30172
  if (declared === actual)
30158
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
+ }
30159
30180
  if (declared === "varchar" && actual === "text")
30160
30181
  return true;
30161
30182
  if (declared === "integer" && actual === "fractional")
@@ -30187,7 +30208,7 @@ async function auditSchemaDrift(plan, options = {}) {
30187
30208
  continue;
30188
30209
  }
30189
30210
  const actual = familyOfSqlType(liveColumn.sqlType);
30190
- if (!satisfies(declared, actual)) {
30211
+ if (!satisfies(declared, actual, dialect)) {
30191
30212
  typeMismatches.push({
30192
30213
  table: table.table,
30193
30214
  column: column.name,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.38",
4
+ "version": "0.2.39",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",