bun-query-builder 0.2.43 → 0.2.45
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/bin/cli.js +266 -102
- package/dist/browser.d.ts +11 -5
- package/dist/client.d.ts +30 -30
- package/dist/column-types.d.ts +26 -0
- package/dist/db.d.ts +36 -6
- package/dist/drivers/sqlite.d.ts +11 -6
- package/dist/dynamodb-client.d.ts +57 -18
- package/dist/dynamodb-single-table.d.ts +2 -2
- package/dist/dynamodb-tooling-adapter.d.ts +7 -6
- package/dist/meta.d.ts +1 -1
- package/dist/model.d.ts +4 -0
- package/dist/orm.d.ts +33 -13
- package/dist/schema.d.ts +35 -21
- package/dist/seeder.d.ts +11 -1
- package/dist/sql-fragments.d.ts +1 -1
- package/dist/src/browser.js +2 -2
- package/dist/src/index.js +266 -101
- package/dist/types.d.ts +34 -20
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -171,15 +171,46 @@ export declare interface ModelOptions extends Base {
|
|
|
171
171
|
morphToMany?: MorphToMany<ModelNames>
|
|
172
172
|
morphedByMany?: MorphedByMany<ModelNames>
|
|
173
173
|
scopes?: {
|
|
174
|
-
[key: string]: (value: any) =>
|
|
174
|
+
[key: string]: (value: any) => unknown
|
|
175
175
|
}
|
|
176
176
|
get?: {
|
|
177
|
-
[key: string]: (value: any) =>
|
|
177
|
+
[key: string]: (value: any) => unknown
|
|
178
178
|
}
|
|
179
179
|
set?: {
|
|
180
|
-
[key: string]: (value: any) =>
|
|
180
|
+
[key: string]: (value: any) => unknown
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* # `DatabaseSchema<Models>`
|
|
185
|
+
*
|
|
186
|
+
* Maps model definitions to a concrete database schema shape containing the
|
|
187
|
+
* table columns and primary key. This is the primary input for the query
|
|
188
|
+
* builder's type-safety.
|
|
189
|
+
*
|
|
190
|
+
* The `relations` field is type-level only (phantom): `buildDatabaseSchema`
|
|
191
|
+
* never materializes it at runtime. It maps relation names to related table
|
|
192
|
+
* names so builder methods like `.with()` can narrow their accepted relation
|
|
193
|
+
* names per table.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const models = defineModels({ User, Post })
|
|
198
|
+
* type Schema = DatabaseSchema<typeof models>
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Any database schema, described by its shape rather than by `any`.
|
|
203
|
+
*
|
|
204
|
+
* Generic constraints throughout the client read `DB extends DatabaseSchema<any>`,
|
|
205
|
+
* which says "a schema of anything" and drags `any` into every published
|
|
206
|
+
* signature that mentions one. This says the same thing accurately: a schema
|
|
207
|
+
* is tables, each with columns, a primary key, and optionally relations.
|
|
208
|
+
*/
|
|
209
|
+
export declare interface AnySchemaTable {
|
|
210
|
+
columns: Record<string, unknown>
|
|
211
|
+
primaryKey?: unknown
|
|
212
|
+
relations?: Record<string, string> | undefined
|
|
213
|
+
}
|
|
183
214
|
/**
|
|
184
215
|
* # `ValidatorMessage`
|
|
185
216
|
*
|
|
@@ -316,24 +347,7 @@ declare type RelatedTableName<MRecord extends ModelRecord, ModelName> = ModelNam
|
|
|
316
347
|
export type InferTableRelations<M, MRecord extends ModelRecord> = {
|
|
317
348
|
[K in keyof ModelRelationsRecord<UnwrapModelDefinition<M>> & string]: RelatedTableName<MRecord, ModelRelationsRecord<UnwrapModelDefinition<M>>[K]>
|
|
318
349
|
}
|
|
319
|
-
|
|
320
|
-
* # `DatabaseSchema<Models>`
|
|
321
|
-
*
|
|
322
|
-
* Maps model definitions to a concrete database schema shape containing the
|
|
323
|
-
* table columns and primary key. This is the primary input for the query
|
|
324
|
-
* builder's type-safety.
|
|
325
|
-
*
|
|
326
|
-
* The `relations` field is type-level only (phantom): `buildDatabaseSchema`
|
|
327
|
-
* never materializes it at runtime. It maps relation names to related table
|
|
328
|
-
* names so builder methods like `.with()` can narrow their accepted relation
|
|
329
|
-
* names per table.
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```ts
|
|
333
|
-
* const models = defineModels({ User, Post })
|
|
334
|
-
* type Schema = DatabaseSchema<typeof models>
|
|
335
|
-
* ```
|
|
336
|
-
*/
|
|
350
|
+
export type AnyDatabaseSchema = Record<string, AnySchemaTable>;
|
|
337
351
|
export type DatabaseSchema<MRecord extends ModelRecord> = {
|
|
338
352
|
[MName in keyof MRecord & string as InferTableName<UnwrapModelDefinition<MRecord[MName]>>]: {
|
|
339
353
|
columns: InferAttributes<UnwrapModelDefinition<MRecord[MName]>>
|
package/dist/seeder.d.ts
CHANGED
|
@@ -17,12 +17,22 @@ export declare interface RunSeederOptions {
|
|
|
17
17
|
class?: string
|
|
18
18
|
verbose?: boolean
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* The query builder handed to a seeder.
|
|
22
|
+
*
|
|
23
|
+
* A seeder is written against the app's own schema, which this base class
|
|
24
|
+
* cannot know, so the handle stays `any` deliberately - narrowing it here
|
|
25
|
+
* would reject every real seeder's typed table access. Named rather than
|
|
26
|
+
* inline so the reason travels with it.
|
|
27
|
+
*/
|
|
28
|
+
// eslint-disable-next-line ts/no-explicit-any
|
|
29
|
+
export type SeederQueryBuilder = any;
|
|
20
30
|
/**
|
|
21
31
|
* Base seeder class that all seeders should extend.
|
|
22
32
|
* Provides access to query builder and faker for generating test data.
|
|
23
33
|
*/
|
|
24
34
|
export declare abstract class Seeder {
|
|
25
|
-
abstract run(qb:
|
|
35
|
+
abstract run(qb: SeederQueryBuilder): Promise<void>;
|
|
26
36
|
get order(): number;
|
|
27
37
|
get description(): string | undefined;
|
|
28
38
|
}
|
package/dist/sql-fragments.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare function renderWhereTerms(terms: readonly WhereTerm[]): string;
|
|
|
32
32
|
* happened to come back empty — the same shape of silent, widening-or-narrowing
|
|
33
33
|
* failure as the `IN ()` bug itself.
|
|
34
34
|
*/
|
|
35
|
-
export declare function renderInPredicate(column: string, values:
|
|
35
|
+
export declare function renderInPredicate(column: string, values: readonly unknown[], negated: boolean, placeholders: string): string;
|
|
36
36
|
/**
|
|
37
37
|
* Rewrite `?` placeholders into the numbered form Postgres requires.
|
|
38
38
|
*
|
package/dist/src/browser.js
CHANGED
|
@@ -139,7 +139,7 @@ class BrowserQueryBuilder {
|
|
|
139
139
|
return this;
|
|
140
140
|
}
|
|
141
141
|
andWhere(column, operatorOrValue, value) {
|
|
142
|
-
return this.where(column, operatorOrValue, value);
|
|
142
|
+
return value === undefined ? this.where(column, operatorOrValue) : this.where(column, operatorOrValue, value);
|
|
143
143
|
}
|
|
144
144
|
whereNull(column) {
|
|
145
145
|
return this.where(column, "is", null);
|
|
@@ -475,7 +475,7 @@ class BrowserModelQueryBuilder {
|
|
|
475
475
|
for (const where of this._wheres) {
|
|
476
476
|
if (where.operator === "=") {
|
|
477
477
|
params.append(where.column, String(where.value));
|
|
478
|
-
} else if (
|
|
478
|
+
} else if (where.operator === "in" && Array.isArray(where.value)) {
|
|
479
479
|
params.append(`${where.column}[]`, where.value.join(","));
|
|
480
480
|
} else if (where.operator === "is" && where.value === null) {
|
|
481
481
|
params.append(`filter[${where.column}][is]`, "null");
|