bun-query-builder 0.2.38 → 0.2.40
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 +25 -4
- package/dist/db.d.ts +7 -0
- package/dist/orm.d.ts +21 -1
- package/dist/src/index.js +24 -3
- 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 {
|
|
@@ -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.
|
|
32357
|
+
var version2 = "0.2.40";
|
|
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/orm.d.ts
CHANGED
|
@@ -199,6 +199,11 @@ declare interface StaticWhereOverloads<TDef extends ModelDefinition> {
|
|
|
199
199
|
column: K,
|
|
200
200
|
value: K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown
|
|
201
201
|
): ModelQueryBuilder<TDef>
|
|
202
|
+
where<K extends ColumnName<TDef>>(
|
|
203
|
+
column: K,
|
|
204
|
+
operator: 'in' | 'not in',
|
|
205
|
+
value: ReadonlyArray<K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown>
|
|
206
|
+
): ModelQueryBuilder<TDef>
|
|
202
207
|
where<K extends ColumnName<TDef>>(
|
|
203
208
|
column: K,
|
|
204
209
|
operator: WhereOperator,
|
|
@@ -357,8 +362,21 @@ declare type FillableKeys<TDef extends ModelDefinition> = {
|
|
|
357
362
|
* from `attributes`, so without this every such create was a type error
|
|
358
363
|
* against the one column the relation exists to set.
|
|
359
364
|
*/
|
|
365
|
+
/**
|
|
366
|
+
* What `create` / `update` accept.
|
|
367
|
+
*
|
|
368
|
+
* `null` is allowed alongside each column's own type because a write is how a
|
|
369
|
+
* nullable column gets CLEARED, and that is a different instruction from
|
|
370
|
+
* leaving the field out. Without it, a caller assembling an update payload -
|
|
371
|
+
* `{ subject: form.subject ?? null }` is the ordinary shape - had to choose
|
|
372
|
+
* between a type error and `undefined`, and `undefined` silently means "do not
|
|
373
|
+
* touch this column", so the field the user cleared stayed as it was.
|
|
374
|
+
*
|
|
375
|
+
* The database's own nullability is still the authority: writing null to a NOT
|
|
376
|
+
* NULL column fails there, as it should.
|
|
377
|
+
*/
|
|
360
378
|
declare type FillableAttributes<TDef extends ModelDefinition> = Partial<Pick<
|
|
361
|
-
ModelAttributes<TDef
|
|
379
|
+
{ [K in keyof ModelAttributes<TDef>]: ModelAttributes<TDef>[K] | null },
|
|
362
380
|
FillableKeys<TDef> | SnakeCase<FillableKeys<TDef>> | BelongsToKeys<TDef>
|
|
363
381
|
>>;
|
|
364
382
|
// Numeric attribute columns - constrains aggregate methods (sum, avg, etc.)
|
|
@@ -583,9 +601,11 @@ declare class ModelQueryBuilder<TDef extends ModelDefinition, TSelected extends
|
|
|
583
601
|
withTrashed(): ModelQueryBuilder<TDef, TSelected>;
|
|
584
602
|
onlyTrashed(): ModelQueryBuilder<TDef, TSelected>;
|
|
585
603
|
where<K extends ColumnName<TDef>>(column: K, value: K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown): ModelQueryBuilder<TDef, TSelected>;
|
|
604
|
+
where<K extends ColumnName<TDef>>(column: K, operator: 'in' | 'not in', value: ReadonlyArray<K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown>): ModelQueryBuilder<TDef, TSelected>;
|
|
586
605
|
where<K extends ColumnName<TDef>>(column: K, operator: WhereOperator, value: K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown): ModelQueryBuilder<TDef, TSelected>;
|
|
587
606
|
where<K extends ColumnName<TDef>>(column: K, operatorOrValue: WhereOperator | unknown, value?: unknown): ModelQueryBuilder<TDef, TSelected>;
|
|
588
607
|
orWhere<K extends ColumnName<TDef>>(column: K, value: K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown): ModelQueryBuilder<TDef, TSelected>;
|
|
608
|
+
orWhere<K extends ColumnName<TDef>>(column: K, operator: 'in' | 'not in', value: ReadonlyArray<K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown>): ModelQueryBuilder<TDef, TSelected>;
|
|
589
609
|
orWhere<K extends ColumnName<TDef>>(column: K, operator: WhereOperator, value: K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown): ModelQueryBuilder<TDef, TSelected>;
|
|
590
610
|
orWhere<K extends ColumnName<TDef>>(column: K, operatorOrValue: WhereOperator | unknown, value?: unknown): ModelQueryBuilder<TDef, TSelected>;
|
|
591
611
|
whereIn<K extends ColumnName<TDef>>(column: K, values: (K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown)[]): ModelQueryBuilder<TDef, TSelected>;
|
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 {
|
|
@@ -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