bun-query-builder 0.2.59 → 0.2.61
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 +31 -40
- package/dist/browser.d.ts +2 -2
- package/dist/chunk-1nqz3kbp.js +40 -0
- package/dist/chunk-3s6cme8m.js +3 -0
- package/dist/chunk-79cr4zy3.js +7 -0
- package/dist/chunk-rvr97jpq.js +2 -0
- package/dist/{chunk-739qq8wk.js → chunk-w49dhqgq.js} +1 -1
- package/dist/chunk-x8e0e418.js +446 -0
- package/dist/client.d.ts +19 -1
- package/dist/orm.d.ts +23 -2
- package/dist/sql-fragments.d.ts +30 -0
- package/dist/src/browser.js +1 -1
- package/dist/src/dynamodb/index.js +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-4q37wh0k.js +0 -445
- package/dist/chunk-asdkg5va.js +0 -3
- package/dist/chunk-cggx9cr8.js +0 -2
- package/dist/chunk-d2b8tt64.js +0 -40
- package/dist/chunk-j9778t8e.js +0 -7
package/dist/client.d.ts
CHANGED
|
@@ -128,6 +128,24 @@ declare interface RawExpression {
|
|
|
128
128
|
export declare interface WhereRaw {
|
|
129
129
|
raw: SqlFragment
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* # `PaginateOptions`
|
|
133
|
+
*
|
|
134
|
+
* The unambiguous spelling of a paginate() call.
|
|
135
|
+
*
|
|
136
|
+
* `db.selectFrom(t).paginate(perPage, page)` and `Model.query().paginate(page,
|
|
137
|
+
* perPage)` take the same two numbers in opposite orders, and both parameters
|
|
138
|
+
* are `number` — so transposing them is not a type error, it just returns a
|
|
139
|
+
* different page. Passing this object instead says which is which.
|
|
140
|
+
*
|
|
141
|
+
* Both APIs accept it and both keep their positional forms, so this adds a
|
|
142
|
+
* safe spelling without moving anyone's existing call. See #1092.
|
|
143
|
+
*/
|
|
144
|
+
export declare interface PaginateOptions {
|
|
145
|
+
perPage?: number
|
|
146
|
+
page?: number
|
|
147
|
+
tx?: { unsafe: (sql: string, params?: unknown[]) => unknown }
|
|
148
|
+
}
|
|
131
149
|
export declare interface BaseSelectQueryBuilder<DB extends AnyDatabaseSchema, TTable extends keyof DB & string, TSelected, TJoined extends string = TTable,> {
|
|
132
150
|
distinct: () => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
|
|
133
151
|
distinctOn: (...columns: (keyof DB[TTable]['columns'] & string | string)[]) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
|
|
@@ -279,7 +297,7 @@ export declare interface BaseSelectQueryBuilder<DB extends AnyDatabaseSchema, TT
|
|
|
279
297
|
explain: () => Promise<Record<string, unknown>[]>
|
|
280
298
|
simple: () => unknown
|
|
281
299
|
toText?: () => string
|
|
282
|
-
paginate: (perPage: number, page?: number, opts?: { tx?: { unsafe: (sql: string, params?: unknown[]) => unknown } }) => Promise<{ data: SelectedRow<DB, TTable, TSelected>[], meta: { perPage: number, page: number, total: number, lastPage: number } }>
|
|
300
|
+
paginate: ((perPage: number, page?: number, opts?: { tx?: { unsafe: (sql: string, params?: unknown[]) => unknown } }) => Promise<{ data: SelectedRow<DB, TTable, TSelected>[], meta: { perPage: number, page: number, total: number, lastPage: number } }>) & ((options: PaginateOptions) => Promise<{ data: SelectedRow<DB, TTable, TSelected>[], meta: { perPage: number, page: number, total: number, lastPage: number } }>)
|
|
283
301
|
simplePaginate: (perPage: number, page?: number) => Promise<{ data: SelectedRow<DB, TTable, TSelected>[], meta: { perPage: number, page: number, hasMore: boolean } }>
|
|
284
302
|
toSQL: () => string
|
|
285
303
|
execute: () => Promise<SelectedRow<DB, TTable, TSelected>[]>
|
package/dist/orm.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Database, type SQLQueryBindings } from 'bun:sqlite';
|
|
2
2
|
import type { FactoryFaker } from './faker-compat';
|
|
3
|
+
import type { PaginateOptions } from './client';
|
|
3
4
|
import type { RelationCardinality } from './type-inference';
|
|
4
5
|
import type { SupportedDialect } from './types';
|
|
5
6
|
export type {
|
|
@@ -20,6 +21,25 @@ export declare function extractChanges(res: WriteResultLike | null | undefined):
|
|
|
20
21
|
/** Extract a generated primary key from a Bun SQL driver result. */
|
|
21
22
|
export declare function extractInsertId(res: WriteResultLike | null | undefined): number | bigint | null;
|
|
22
23
|
export declare function configureOrm(options: { database?: string | Database; verbose?: boolean }): void;
|
|
24
|
+
/**
|
|
25
|
+
* Hand back the `configureOrm({ database })` override.
|
|
26
|
+
*
|
|
27
|
+
* `globalDb` outranks `setConfig()` in {@link getExecutor} and, until now, for
|
|
28
|
+
* the rest of the process: `configureOrm` could repoint it but nothing could
|
|
29
|
+
* remove it. In a runner that shares one process across many files - `bun test`
|
|
30
|
+
* does - the last file to configure the ORM left every later one pinned to a
|
|
31
|
+
* database it owned, and typically deleted in its own teardown. Everything
|
|
32
|
+
* afterwards got `RangeError: Cannot use a closed database` from a connection
|
|
33
|
+
* it never asked for (stacksjs/stacks#2415).
|
|
34
|
+
*
|
|
35
|
+
* After this call, resolution falls back to the dialect and database from
|
|
36
|
+
* `setConfig()`, exactly as if `configureOrm` had never run.
|
|
37
|
+
*
|
|
38
|
+
* A handle opened from a path is closed, since this module opened it and
|
|
39
|
+
* nothing else can. One passed in as a `Database` is left alone: bring your own
|
|
40
|
+
* connection, keep your own lifetime.
|
|
41
|
+
*/
|
|
42
|
+
export declare function releaseOrm(): void;
|
|
23
43
|
/**
|
|
24
44
|
* Return the underlying `bun:sqlite` Database backing the model layer.
|
|
25
45
|
*
|
|
@@ -508,7 +528,7 @@ export type ModelStatic<TDef extends ModelDefinition> = StaticWhereOverloads<TDe
|
|
|
508
528
|
count: () => Promise<number>
|
|
509
529
|
exists: () => Promise<boolean>
|
|
510
530
|
doesntExist: () => Promise<boolean>
|
|
511
|
-
paginate: (page?: number, perPage?: number) => Promise<{
|
|
531
|
+
paginate: (page?: number | PaginateOptions, perPage?: number) => Promise<{
|
|
512
532
|
data: ModelRecord<TDef>[]
|
|
513
533
|
total: number
|
|
514
534
|
page: number
|
|
@@ -680,7 +700,7 @@ declare class ModelQueryBuilder<TDef extends ModelDefinition, TSelected extends
|
|
|
680
700
|
increment<K extends NumericColumns<TDef>>(column: K, amount?: number): Promise<number>;
|
|
681
701
|
decrement<K extends NumericColumns<TDef>>(column: K, amount?: number): Promise<number>;
|
|
682
702
|
chunk(size: number, callback: (items: ModelInstance<TDef, TSelected>[]) => void | false | Promise<void | false>): Promise<void>;
|
|
683
|
-
paginate(page?: number, perPage?: number): Promise<{
|
|
703
|
+
paginate(page?: number | PaginateOptions, perPage?: number): Promise<{
|
|
684
704
|
data: ModelInstance<TDef, TSelected>[]
|
|
685
705
|
total: number
|
|
686
706
|
page: number
|
|
@@ -690,6 +710,7 @@ declare class ModelQueryBuilder<TDef extends ModelDefinition, TSelected extends
|
|
|
690
710
|
isEmpty: boolean
|
|
691
711
|
from: number | null
|
|
692
712
|
to: number | null
|
|
713
|
+
meta: { perPage: number, page: number, total: number, lastPage: number }
|
|
693
714
|
}>;
|
|
694
715
|
pluck<K extends ColumnName<TDef>>(column: K): Promise<(K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : unknown)[]>;
|
|
695
716
|
max<K extends ColumnName<TDef>>(column: K): Promise<(K extends keyof ModelAttributes<TDef> ? ModelAttributes<TDef>[K] : number) | null>;
|
package/dist/sql-fragments.d.ts
CHANGED
|
@@ -52,6 +52,28 @@ export declare function renderInPredicate(column: string, values: readonly unkno
|
|
|
52
52
|
* to apply unconditionally.
|
|
53
53
|
*/
|
|
54
54
|
export declare function toDialectPlaceholders(sql: string, dialect: SupportedDialect): string;
|
|
55
|
+
/* … *\/` block comments, which nest
|
|
56
|
+
* - `$$…$$` / `$tag$…$tag$` dollar-quoted strings, without mistaking a `$1`
|
|
57
|
+
* placeholder for the start of one
|
|
58
|
+
*
|
|
59
|
+
* Backslash escapes inside a literal are deliberately NOT honoured. Whether
|
|
60
|
+
* `'a\'` ends the string depends on the dialect and, on Postgres, on a server
|
|
61
|
+
* setting — so this matches the standard (and what the previous literal-aware
|
|
62
|
+
* scanner did) rather than inventing a rule that would be wrong somewhere.
|
|
63
|
+
*
|
|
64
|
+
* A keyword must be preceded by a non-word character, and never matches at
|
|
65
|
+
* index 0: a statement that opens with a clause keyword has nothing before it
|
|
66
|
+
* for the clause to attach to.
|
|
67
|
+
*
|
|
68
|
+
* @param sql the statement to scan
|
|
69
|
+
* @param keywords patterns to look for. Each MUST carry the sticky (`y`) flag;
|
|
70
|
+
* they are matched at a position rather than against a slice, and are tried
|
|
71
|
+
* in the order given — so longer keywords must come before any single-word
|
|
72
|
+
* prefix of them (`ORDER BY` before a hypothetical `ORDER`).
|
|
73
|
+
* @param limit stop after this many hits. Callers that only want the first
|
|
74
|
+
* clause boundary pass 1 rather than scanning the rest of the statement.
|
|
75
|
+
*/
|
|
76
|
+
export declare function scanTopLevelKeywords(sql: string, keywords: ReadonlyArray<{ key: string, pattern: RegExp }>, limit?: unknown): TopLevelKeyword[];
|
|
55
77
|
/**
|
|
56
78
|
* Constant predicates, for the cases where a collection is empty.
|
|
57
79
|
*
|
|
@@ -87,3 +109,11 @@ export declare interface WhereTerm {
|
|
|
87
109
|
conn: 'AND' | 'OR'
|
|
88
110
|
sql: string
|
|
89
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* A top-level keyword found by {@link scanTopLevelKeywords}.
|
|
114
|
+
*/
|
|
115
|
+
export declare interface TopLevelKeyword {
|
|
116
|
+
key: string
|
|
117
|
+
start: number
|
|
118
|
+
length: number
|
|
119
|
+
}
|
package/dist/src/browser.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Nb as a,Ob as b,Pb as c,Qb as d,Rb as e,Sb as f,Tb as g,Ub as h,Vb as i,Wb as j,Xb as k}from"../chunk-3s6cme8m.js";import"../chunk-w49dhqgq.js";k();export{e as BrowserQueryBuilder,d as BrowserQueryError,i as browserAuth,f as browserQuery,a as configureBrowser,g as createBrowserDb,h as createBrowserModel,j as default,b as getBrowserConfig,c as isBrowser};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{$b as
|
|
2
|
+
import{$b as b,_b as a,ac as c,bc as d,cc as e,dc as f,ec as g,fc as h,gc as i,hc as j,ic as k,jc as l,kc as m,lc as n,mc as o,nc as p,oc as q,pc as r}from"../../chunk-79cr4zy3.js";import"../../chunk-w49dhqgq.js";export{a as DynamoDBClient,m as DynamoDBMigrationDriver,l as DynamoDBMigrationTracker,p as EntityQueryBuilder,k as MIGRATIONS_TABLE,d as Model,i as buildDynamoDBMigrationPlan,c as configureModels,h as convertSchemaToDefinition,b as createClient,r as createDynamo,n as createMigrationDriver,q as dynamo,g as extractModelSchema,f as extractTableDefinition,e as hashTableDefinition,j as isDefinitionEqual,o as migrateModels};
|
package/dist/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{$ as aa,$a as ib,A,Aa,Ab as $b,B,Ba as Ka,Bb as ac,C,Ca as La,Cb as bc,D,Da as Ma,Db as cc,E,Ea as Na,Eb as dc,F,Fa as Oa,Fb as ec,G,Ga as Pa,Gb as fc,H,Ha as Qa,Hb as gc,I,Ia as Ra,Ib as hc,J,Ja as Sa,Jb as ic,K,Ka as Ta,Kb as jc,L,La as Ua,Lb as kc,M,Ma as Va,Mb as lc,N,Na as Wa,O,Oa as Xa,P,Pa as Ya,Q,Qa as Za,R,Ra as _a,S,Sa as $a,T,Ta as ab,U,Ua as bb,V,Va as cb,W,Wa as db,X,Xa as eb,Y,Ya as fb,Z,Za as gb,_,_a as hb,a,aa as ba,ab as jb,b,ba as ca,bb as kb,c,ca as fa,cb as lb,d,da as ga,db as mb,e,ea as ha,eb as nb,f,fa as ia,fb as ob,g,ga as ja,gb as pb,h,hb as qb,i,ib as rb,j,jb as sb,k,ka,kb as tb,l,la,lb as ub,m,ma,mb as vb,n,na,nb as Ob,o,oa,ob as Pb,p,pa,pb as Qb,q,qa,qb as Rb,r,ra,rb as Sb,s,sa,sb as Tb,t,ta,tb as Ub,u,ua,ub as Vb,v,va,vb as Wb,w,wa,wb as Xb,x,xa,xb as Yb,y,ya,yb as Zb,z,za,zb as _b}from"../chunk-x8e0e418.js";import{Nb as Ba,Ob as Ca,Pb as Da,Qb as Ea,Rb as Fa,Sb as Ga,Tb as Ha,Ub as Ia,Vb as Ja}from"../chunk-3s6cme8m.js";import{$b as xb,Yb as da,Zb as ea,_b as wb,ac as yb,bc as zb,cc as Ab,dc as Bb,ec as Cb,fc as Db,gc as Eb,hc as Fb,ic as Gb,jc as Hb,kc as Ib,lc as Jb,mc as Kb,nc as Lb,oc as Mb,pc as Nb}from"../chunk-79cr4zy3.js";import"../chunk-w49dhqgq.js";export{Ra as BelongsToManyRelationBuilder,Fa as BrowserQueryBuilder,Ea as BrowserQueryError,j as DEFAULT_SQLITE_PRAGMAS,wb as DynamoDBClient,da as DynamoDBDriverImpl,cb as DynamoDBItemBuilder,Ib as DynamoDBMigrationDriver,Hb as DynamoDBMigrationTracker,bb as DynamoDBQueryBuilder,sb as DynamoDBToolingAdapter,Lb as EntityQueryBuilder,Sb as GENERATED_MARKER,Gb as MIGRATIONS_TABLE,zb as Model,Z as MySQLDriver,_ as PostgresDriver,ca as SQLiteDriver,fc as Seeder,aa as SingleStoreDriver,gb as SingleTableManager,lb as SingleTablePatterns,ib as SingleTableQueryBuilder,hb as SingleTableRepository,ac as UTC_CLOCK_DEFAULT,ba as VitessDriver,l as applySqliteBootstrapPragmas,kc as auditSchemaDrift,Ja as browserAuth,Ga as browserQuery,Ob as buildDatabaseSchema,Eb as buildDynamoDBMigrationPlan,Wb as buildMigrationPlan,Qb as buildSchemaMeta,D as cacheClear,F as cacheConfig,E as cacheStats,$b as canonicalStorageType,bc as canonicalizeDefault,za as checkSchema,La as clearLocalModels,Za as clearModelRegistry,B as clearQueryCache,c as config,Ba as configureBrowser,yb as configureModels,Oa as configureOrm,Db as convertSchemaToDefinition,Ha as createBrowserDb,Ia as createBrowserModel,xb as createClient,Nb as createDynamo,fb as createDynamoDBClient,ea as createDynamoDBDriver,eb as createDynamoDBItemBuilder,db as createDynamoDBQueryBuilder,tb as createDynamoDBToolingAdapter,Ka as createFakerCompatLayer,Jb as createMigrationDriver,Sa as createModel,A as createQueryBuilder,kb as createRepository,jb as createSingleTableManager,Ta as createTableFromModel,L as dbInfo,N as dbOptimize,M as dbStats,O as dbWipe,b as defaultConfig,i as defineConfig,$a as defineModel,ec as defineModels,gc as defineSeeder,K as dumpDatabase,Mb as dynamo,z as escapeStringLiteral,ia as executeMigration,P as explain,qa as explainAllQueries,I as exportData,Ma as extractChanges,Na as extractInsertId,Cb as extractModelSchema,Bb as extractTableDefinition,hc as familyOfDeclared,ic as familyOfSqlType,Q as file,lc as formatSchemaDrift,va as freshDatabase,ub as generateAccessPatterns,ra as generateDiagram,cc as generateDiffOperations,dc as generateDiffSql,Zb as generateDiffSqlString,ha as generateMigration,W as generateModelSource,Xb as generateSql,Yb as generateSqlString,Wa as getAllModels,Ca as getBrowserConfig,g as getConfig,Qa as getDatabase,fa as getDialectDriver,Va as getModel,Xa as getModelRegistry,e as getPlaceholder,f as getPlaceholders,Ya as hasModel,_b as hashMigrationPlan,Ab as hashTableDefinition,J as importData,r as inflectSingular,R as inspectTable,T as introspect,X as introspectDatabase,Da as isBrowser,Fb as isDefinitionEqual,Tb as isGeneratedMigrationSql,Vb as isLosslessTypeChange,a as isMysqlLike,u as iterateAllPivots,Rb as lastCreatedMigrationFiles,Pb as loadModels,Y as makeModel,ua as makeSeeder,qb as marshallObject,ka as migrateGenerate,na as migrateList,Kb as migrateModels,la as migrateRollback,ma as migrateStatus,Ub as migrationBody,V as modelNameForTable,oa as modelShow,N as optimizeDatabase,nb as parseStacksModels,pa as ping,qa as queryExplainAll,x as quoteColumnForDialect,w as raw,ab as registerBrowserModels,_a as registerModel,ra as relationDiagram,Pa as releaseOrm,m as resetConnection,ja as resetDatabase,d as resolveDialect,mb as resolveKeyPattern,t as resolvePivot,k as resolveSqlitePragmas,n as runBenchmark,ta as runSeeder,sa as runSeeders,jc as satisfies,ga as saveMigrationSnapshot,Ua as seedModel,h as setConfig,C as setQueryCacheMaxSize,oa as showModel,s as singularizerFor,wa as sql,U as sqlTypeToAttr,vb as stacksModelToEntity,G as startConsole,q as stripTrailingS,S as tableInfo,p as tableNameFor,y as temporalLiteral,H as tinker,v as toDialectPlaceholders,ob as toDynamoDBItem,pb as toModelInstance,o as toTableName,rb as unmarshallItem,xa as unsafe,ya as validateSchema,Aa as waitReady,O as wipeDatabase};
|
package/package.json
CHANGED