@bunnykit/orm 0.1.0

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +904 -0
  3. package/dist/bin/bunny.d.ts +2 -0
  4. package/dist/bin/bunny.js +108 -0
  5. package/dist/src/connection/Connection.d.ts +13 -0
  6. package/dist/src/connection/Connection.js +49 -0
  7. package/dist/src/index.d.ts +20 -0
  8. package/dist/src/index.js +18 -0
  9. package/dist/src/migration/Migration.d.ts +4 -0
  10. package/dist/src/migration/Migration.js +2 -0
  11. package/dist/src/migration/MigrationCreator.d.ts +5 -0
  12. package/dist/src/migration/MigrationCreator.js +39 -0
  13. package/dist/src/migration/Migrator.d.ts +21 -0
  14. package/dist/src/migration/Migrator.js +137 -0
  15. package/dist/src/model/BelongsToMany.d.ts +27 -0
  16. package/dist/src/model/BelongsToMany.js +118 -0
  17. package/dist/src/model/Model.d.ts +166 -0
  18. package/dist/src/model/Model.js +763 -0
  19. package/dist/src/model/MorphMap.d.ts +7 -0
  20. package/dist/src/model/MorphMap.js +12 -0
  21. package/dist/src/model/MorphRelations.d.ts +81 -0
  22. package/dist/src/model/MorphRelations.js +296 -0
  23. package/dist/src/model/Observer.d.ts +19 -0
  24. package/dist/src/model/Observer.js +21 -0
  25. package/dist/src/query/Builder.d.ts +106 -0
  26. package/dist/src/query/Builder.js +466 -0
  27. package/dist/src/schema/Blueprint.d.ts +66 -0
  28. package/dist/src/schema/Blueprint.js +200 -0
  29. package/dist/src/schema/Schema.d.ts +16 -0
  30. package/dist/src/schema/Schema.js +135 -0
  31. package/dist/src/schema/grammars/Grammar.d.ts +26 -0
  32. package/dist/src/schema/grammars/Grammar.js +95 -0
  33. package/dist/src/schema/grammars/MySqlGrammar.d.ts +18 -0
  34. package/dist/src/schema/grammars/MySqlGrammar.js +96 -0
  35. package/dist/src/schema/grammars/PostgresGrammar.d.ts +16 -0
  36. package/dist/src/schema/grammars/PostgresGrammar.js +88 -0
  37. package/dist/src/schema/grammars/SQLiteGrammar.d.ts +16 -0
  38. package/dist/src/schema/grammars/SQLiteGrammar.js +108 -0
  39. package/dist/src/typegen/TypeGenerator.d.ts +29 -0
  40. package/dist/src/typegen/TypeGenerator.js +171 -0
  41. package/dist/src/typegen/TypeMapper.d.ts +4 -0
  42. package/dist/src/typegen/TypeMapper.js +27 -0
  43. package/dist/src/types/index.d.ts +53 -0
  44. package/dist/src/types/index.js +1 -0
  45. package/dist/src/utils.d.ts +1 -0
  46. package/dist/src/utils.js +6 -0
  47. package/package.json +62 -0
@@ -0,0 +1,7 @@
1
+ import type { Model } from "./Model.js";
2
+ export declare class MorphMap {
3
+ private static map;
4
+ static register(name: string, model: typeof Model): void;
5
+ static get(name: string): typeof Model | undefined;
6
+ static keys(): string[];
7
+ }
@@ -0,0 +1,12 @@
1
+ export class MorphMap {
2
+ static map = new Map();
3
+ static register(name, model) {
4
+ this.map.set(name, model);
5
+ }
6
+ static get(name) {
7
+ return this.map.get(name);
8
+ }
9
+ static keys() {
10
+ return Array.from(this.map.keys());
11
+ }
12
+ }
@@ -0,0 +1,81 @@
1
+ import { Builder } from "../query/Builder.js";
2
+ import type { Model, ModelConstructor } from "./Model.js";
3
+ export declare class MorphTo<T extends Model = Model> {
4
+ protected parent: Model;
5
+ protected name: string;
6
+ protected typeColumn: string;
7
+ protected idColumn: string;
8
+ protected typeMap?: Record<string, ModelConstructor>;
9
+ constructor(parent: Model, name: string, typeMap?: Record<string, ModelConstructor>);
10
+ getResults(): Promise<T | null>;
11
+ private resolveAndFind;
12
+ addEagerConstraints(models: Model[]): void;
13
+ getEager(): Promise<any[]>;
14
+ match(models: Model[], _results: any[], relationName: string): void;
15
+ }
16
+ export declare class MorphOne<T extends Model = Model> {
17
+ protected builder: Builder<T>;
18
+ protected parent: Model;
19
+ protected related: typeof Model;
20
+ protected name: string;
21
+ protected typeColumn: string;
22
+ protected idColumn: string;
23
+ protected localKey: string;
24
+ constructor(parent: Model, related: typeof Model, name: string, typeColumn?: string, idColumn?: string, localKey?: string);
25
+ protected getMorphType(): string;
26
+ getQuery(): Builder<T>;
27
+ addEagerConstraints(models: Model[]): void;
28
+ getEager(): Promise<any[]>;
29
+ match(models: Model[], results: any[], relationName: string): void;
30
+ getResults(): Promise<T | null>;
31
+ qualifyRelatedColumn(column: string): string;
32
+ protected newExistenceQuery(parentTable: string, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): Builder<any>;
33
+ getRelationExistenceSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
34
+ getRelationCountSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
35
+ getRelationAggregateSql(parentQuery: Builder<any>, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): string;
36
+ }
37
+ export declare class MorphMany<T extends Model = Model> {
38
+ protected builder: Builder<T>;
39
+ protected parent: Model;
40
+ protected related: typeof Model;
41
+ protected name: string;
42
+ protected typeColumn: string;
43
+ protected idColumn: string;
44
+ protected localKey: string;
45
+ constructor(parent: Model, related: typeof Model, name: string, typeColumn?: string, idColumn?: string, localKey?: string);
46
+ protected getMorphType(): string;
47
+ getQuery(): Builder<T>;
48
+ addEagerConstraints(models: Model[]): void;
49
+ getEager(): Promise<any[]>;
50
+ match(models: Model[], results: any[], relationName: string): void;
51
+ getResults(): Promise<T[]>;
52
+ qualifyRelatedColumn(column: string): string;
53
+ protected newExistenceQuery(parentTable: string, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): Builder<any>;
54
+ getRelationExistenceSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
55
+ getRelationCountSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
56
+ getRelationAggregateSql(parentQuery: Builder<any>, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): string;
57
+ }
58
+ export declare class MorphToMany<T extends Model = Model> {
59
+ protected builder: Builder<T>;
60
+ protected parent: Model;
61
+ protected related: typeof Model;
62
+ protected name: string;
63
+ protected table: string;
64
+ protected foreignPivotKey: string;
65
+ protected relatedPivotKey: string;
66
+ protected parentKey: string;
67
+ protected relatedKey: string;
68
+ protected morphType: string;
69
+ constructor(parent: Model, related: typeof Model, name: string, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string, morphType?: string);
70
+ protected addConstraints(): void;
71
+ getQuery(): Builder<T>;
72
+ addEagerConstraints(models: Model[]): void;
73
+ getEager(): Promise<any[]>;
74
+ match(models: Model[], results: any[], relationName: string): void;
75
+ getResults(): Promise<T[]>;
76
+ qualifyRelatedColumn(column: string): string;
77
+ protected newExistenceQuery(parentTable: string, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): Builder<any>;
78
+ getRelationExistenceSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
79
+ getRelationCountSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
80
+ getRelationAggregateSql(parentQuery: Builder<any>, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): string;
81
+ }
@@ -0,0 +1,296 @@
1
+ import { snakeCase } from "../utils.js";
2
+ import { MorphMap } from "./MorphMap.js";
3
+ export class MorphTo {
4
+ parent;
5
+ name;
6
+ typeColumn;
7
+ idColumn;
8
+ typeMap;
9
+ constructor(parent, name, typeMap) {
10
+ this.parent = parent;
11
+ this.name = name;
12
+ this.typeColumn = `${name}_type`;
13
+ this.idColumn = `${name}_id`;
14
+ this.typeMap = typeMap;
15
+ }
16
+ async getResults() {
17
+ const type = this.parent.getAttribute(this.typeColumn);
18
+ const id = this.parent.getAttribute(this.idColumn);
19
+ if (!type || !id)
20
+ return null;
21
+ return this.resolveAndFind(type, id);
22
+ }
23
+ async resolveAndFind(type, id) {
24
+ let Related;
25
+ if (this.typeMap) {
26
+ Related = this.typeMap[type];
27
+ }
28
+ if (!Related) {
29
+ Related = MorphMap.get(type);
30
+ }
31
+ if (!Related) {
32
+ throw new Error(`No morph mapping found for type: ${type}. Register it with MorphMap.register() or pass a typeMap.`);
33
+ }
34
+ return Related.find(id);
35
+ }
36
+ addEagerConstraints(models) {
37
+ // MorphTo eager loading is handled separately in getEager
38
+ }
39
+ async getEager() {
40
+ return []; // Results are assembled in match
41
+ }
42
+ match(models, _results, relationName) {
43
+ // Group models by type
44
+ const typeGroups = {};
45
+ for (const model of models) {
46
+ const type = model.getAttribute(this.typeColumn);
47
+ if (!type)
48
+ continue;
49
+ if (!typeGroups[type])
50
+ typeGroups[type] = [];
51
+ typeGroups[type].push(model);
52
+ }
53
+ // For each type, find the related models
54
+ for (const [type, groupModels] of Object.entries(typeGroups)) {
55
+ const ids = groupModels.map((m) => m.getAttribute(this.idColumn)).filter((id) => id !== null && id !== undefined);
56
+ if (ids.length === 0)
57
+ continue;
58
+ let Related;
59
+ if (this.typeMap)
60
+ Related = this.typeMap[type];
61
+ if (!Related)
62
+ Related = MorphMap.get(type);
63
+ if (!Related)
64
+ continue;
65
+ const relatedModels = Related.whereIn(Related.primaryKey, ids).get();
66
+ // We need to execute this synchronously-ish... but it's async
67
+ // Actually, we can't do async in for...of without awaiting
68
+ }
69
+ }
70
+ }
71
+ export class MorphOne {
72
+ builder;
73
+ parent;
74
+ related;
75
+ name;
76
+ typeColumn;
77
+ idColumn;
78
+ localKey;
79
+ constructor(parent, related, name, typeColumn, idColumn, localKey) {
80
+ this.parent = parent;
81
+ this.related = related;
82
+ this.name = name;
83
+ this.typeColumn = typeColumn || `${name}_type`;
84
+ this.idColumn = idColumn || `${name}_id`;
85
+ this.localKey = localKey || parent.constructor.primaryKey;
86
+ this.builder = related.query();
87
+ this.builder.where(this.typeColumn, this.getMorphType());
88
+ this.builder.where(this.idColumn, this.parent.getAttribute(this.localKey));
89
+ }
90
+ getMorphType() {
91
+ return this.parent.constructor.morphName || this.parent.constructor.name;
92
+ }
93
+ getQuery() {
94
+ return this.builder;
95
+ }
96
+ addEagerConstraints(models) {
97
+ this.builder = this.related.query();
98
+ const keys = models.map((m) => m.getAttribute(this.localKey));
99
+ this.builder.whereIn(this.idColumn, keys);
100
+ this.builder.where(this.typeColumn, this.getMorphType());
101
+ }
102
+ async getEager() {
103
+ return this.builder.get();
104
+ }
105
+ match(models, results, relationName) {
106
+ const dictionary = {};
107
+ for (const result of results) {
108
+ const key = result.$attributes[this.idColumn];
109
+ dictionary[String(key)] = result;
110
+ }
111
+ for (const model of models) {
112
+ const key = model.getAttribute(this.localKey);
113
+ model.setRelation(relationName, dictionary[String(key)] || null);
114
+ }
115
+ }
116
+ async getResults() {
117
+ return this.builder.first();
118
+ }
119
+ qualifyRelatedColumn(column) {
120
+ return column.includes(".") ? column : `${this.related.getTable()}.${column}`;
121
+ }
122
+ newExistenceQuery(parentTable, aggregate, callback) {
123
+ const query = this.related.query().select(aggregate);
124
+ query.whereColumn(`${this.related.getTable()}.${this.idColumn}`, "=", `${parentTable}.${this.localKey}`);
125
+ query.where(`${this.related.getTable()}.${this.typeColumn}`, this.getMorphType());
126
+ if (callback)
127
+ callback(query);
128
+ return query;
129
+ }
130
+ getRelationExistenceSql(parentQuery, callback) {
131
+ return this.newExistenceQuery(parentQuery.tableName, "1", callback).toSql();
132
+ }
133
+ getRelationCountSql(parentQuery, callback) {
134
+ return this.getRelationAggregateSql(parentQuery, "COUNT(*)", callback);
135
+ }
136
+ getRelationAggregateSql(parentQuery, aggregate, callback) {
137
+ return this.newExistenceQuery(parentQuery.tableName, aggregate, callback).toSql();
138
+ }
139
+ }
140
+ export class MorphMany {
141
+ builder;
142
+ parent;
143
+ related;
144
+ name;
145
+ typeColumn;
146
+ idColumn;
147
+ localKey;
148
+ constructor(parent, related, name, typeColumn, idColumn, localKey) {
149
+ this.parent = parent;
150
+ this.related = related;
151
+ this.name = name;
152
+ this.typeColumn = typeColumn || `${name}_type`;
153
+ this.idColumn = idColumn || `${name}_id`;
154
+ this.localKey = localKey || parent.constructor.primaryKey;
155
+ this.builder = related.query();
156
+ this.builder.where(this.typeColumn, this.getMorphType());
157
+ this.builder.where(this.idColumn, this.parent.getAttribute(this.localKey));
158
+ }
159
+ getMorphType() {
160
+ return this.parent.constructor.morphName || this.parent.constructor.name;
161
+ }
162
+ getQuery() {
163
+ return this.builder;
164
+ }
165
+ addEagerConstraints(models) {
166
+ this.builder = this.related.query();
167
+ const keys = models.map((m) => m.getAttribute(this.localKey));
168
+ this.builder.whereIn(this.idColumn, keys);
169
+ this.builder.where(this.typeColumn, this.getMorphType());
170
+ }
171
+ async getEager() {
172
+ return this.builder.get();
173
+ }
174
+ match(models, results, relationName) {
175
+ const dictionary = {};
176
+ for (const result of results) {
177
+ const key = result.$attributes[this.idColumn];
178
+ if (!dictionary[key])
179
+ dictionary[key] = [];
180
+ dictionary[key].push(result);
181
+ }
182
+ for (const model of models) {
183
+ const key = model.getAttribute(this.localKey);
184
+ model.setRelation(relationName, dictionary[String(key)] || []);
185
+ }
186
+ }
187
+ async getResults() {
188
+ return this.builder.get();
189
+ }
190
+ qualifyRelatedColumn(column) {
191
+ return column.includes(".") ? column : `${this.related.getTable()}.${column}`;
192
+ }
193
+ newExistenceQuery(parentTable, aggregate, callback) {
194
+ const query = this.related.query().select(aggregate);
195
+ query.whereColumn(`${this.related.getTable()}.${this.idColumn}`, "=", `${parentTable}.${this.localKey}`);
196
+ query.where(`${this.related.getTable()}.${this.typeColumn}`, this.getMorphType());
197
+ if (callback)
198
+ callback(query);
199
+ return query;
200
+ }
201
+ getRelationExistenceSql(parentQuery, callback) {
202
+ return this.newExistenceQuery(parentQuery.tableName, "1", callback).toSql();
203
+ }
204
+ getRelationCountSql(parentQuery, callback) {
205
+ return this.getRelationAggregateSql(parentQuery, "COUNT(*)", callback);
206
+ }
207
+ getRelationAggregateSql(parentQuery, aggregate, callback) {
208
+ return this.newExistenceQuery(parentQuery.tableName, aggregate, callback).toSql();
209
+ }
210
+ }
211
+ export class MorphToMany {
212
+ builder;
213
+ parent;
214
+ related;
215
+ name;
216
+ table;
217
+ foreignPivotKey;
218
+ relatedPivotKey;
219
+ parentKey;
220
+ relatedKey;
221
+ morphType;
222
+ constructor(parent, related, name, table, foreignPivotKey, relatedPivotKey, parentKey, relatedKey, morphType) {
223
+ this.parent = parent;
224
+ this.related = related;
225
+ this.name = name;
226
+ this.table = table || `${name}s`;
227
+ this.parentKey = parentKey || parent.constructor.primaryKey;
228
+ this.relatedKey = relatedKey || related.primaryKey;
229
+ this.morphType = morphType || parent.constructor.morphName || parent.constructor.name;
230
+ this.foreignPivotKey = foreignPivotKey || `${snakeCase(name)}_id`;
231
+ this.relatedPivotKey = relatedPivotKey || `${snakeCase(related.name)}_id`;
232
+ this.builder = related.query();
233
+ this.addConstraints();
234
+ }
235
+ addConstraints() {
236
+ const relatedTable = this.related.getTable();
237
+ this.builder.select(`${relatedTable}.*`);
238
+ this.builder.join(this.table, `${this.table}.${this.relatedPivotKey}`, "=", `${relatedTable}.${this.relatedKey}`);
239
+ this.builder.where(`${this.table}.${this.foreignPivotKey}`, this.parent.getAttribute(this.parentKey));
240
+ this.builder.where(`${this.table}.${this.name}_type`, this.morphType);
241
+ }
242
+ getQuery() {
243
+ return this.builder;
244
+ }
245
+ addEagerConstraints(models) {
246
+ const keys = models.map((m) => m.getAttribute(this.parentKey));
247
+ const relatedTable = this.related.getTable();
248
+ this.builder = this.related.query();
249
+ this.builder.select(`${relatedTable}.*`, `${this.table}.${this.foreignPivotKey}`);
250
+ this.builder.join(this.table, `${this.table}.${this.relatedPivotKey}`, "=", `${relatedTable}.${this.relatedKey}`);
251
+ this.builder.whereIn(`${this.table}.${this.foreignPivotKey}`, keys);
252
+ this.builder.where(`${this.table}.${this.name}_type`, this.morphType);
253
+ }
254
+ async getEager() {
255
+ return this.builder.get();
256
+ }
257
+ match(models, results, relationName) {
258
+ const dictionary = {};
259
+ for (const result of results) {
260
+ const key = result.$attributes[this.foreignPivotKey];
261
+ if (!dictionary[key])
262
+ dictionary[key] = [];
263
+ delete result.$attributes[this.foreignPivotKey];
264
+ dictionary[key].push(result);
265
+ }
266
+ for (const model of models) {
267
+ const key = model.getAttribute(this.parentKey);
268
+ model.setRelation(relationName, dictionary[String(key)] || []);
269
+ }
270
+ }
271
+ async getResults() {
272
+ return this.builder.get();
273
+ }
274
+ qualifyRelatedColumn(column) {
275
+ return column.includes(".") ? column : `${this.related.getTable()}.${column}`;
276
+ }
277
+ newExistenceQuery(parentTable, aggregate, callback) {
278
+ const relatedTable = this.related.getTable();
279
+ const query = this.related.query().select(aggregate);
280
+ query.join(this.table, `${this.table}.${this.relatedPivotKey}`, "=", `${relatedTable}.${this.relatedKey}`);
281
+ query.whereColumn(`${this.table}.${this.foreignPivotKey}`, "=", `${parentTable}.${this.parentKey}`);
282
+ query.where(`${this.table}.${this.name}_type`, this.morphType);
283
+ if (callback)
284
+ callback(query);
285
+ return query;
286
+ }
287
+ getRelationExistenceSql(parentQuery, callback) {
288
+ return this.newExistenceQuery(parentQuery.tableName, "1", callback).toSql();
289
+ }
290
+ getRelationCountSql(parentQuery, callback) {
291
+ return this.getRelationAggregateSql(parentQuery, "COUNT(*)", callback);
292
+ }
293
+ getRelationAggregateSql(parentQuery, aggregate, callback) {
294
+ return this.newExistenceQuery(parentQuery.tableName, aggregate, callback).toSql();
295
+ }
296
+ }
@@ -0,0 +1,19 @@
1
+ import type { Model } from "./Model.js";
2
+ export interface ObserverContract<T extends Model = Model> {
3
+ creating?(model: T): Promise<void> | void;
4
+ created?(model: T): Promise<void> | void;
5
+ updating?(model: T): Promise<void> | void;
6
+ updated?(model: T): Promise<void> | void;
7
+ saving?(model: T): Promise<void> | void;
8
+ saved?(model: T): Promise<void> | void;
9
+ deleting?(model: T): Promise<void> | void;
10
+ deleted?(model: T): Promise<void> | void;
11
+ restoring?(model: T): Promise<void> | void;
12
+ restored?(model: T): Promise<void> | void;
13
+ }
14
+ export declare class ObserverRegistry {
15
+ private static observers;
16
+ static register(modelClass: typeof Model, observer: ObserverContract): void;
17
+ static get(modelClass: typeof Model): ObserverContract[];
18
+ static dispatch<T extends Model>(event: keyof ObserverContract, model: T): Promise<void>;
19
+ }
@@ -0,0 +1,21 @@
1
+ export class ObserverRegistry {
2
+ static observers = new Map();
3
+ static register(modelClass, observer) {
4
+ if (!this.observers.has(modelClass)) {
5
+ this.observers.set(modelClass, []);
6
+ }
7
+ this.observers.get(modelClass).push(observer);
8
+ }
9
+ static get(modelClass) {
10
+ return this.observers.get(modelClass) || [];
11
+ }
12
+ static async dispatch(event, model) {
13
+ const observers = this.get(model.constructor);
14
+ for (const observer of observers) {
15
+ const handler = observer[event];
16
+ if (handler) {
17
+ await handler(model);
18
+ }
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,106 @@
1
+ import { Connection } from "../connection/Connection.js";
2
+ import type { WhereClause, OrderClause } from "../types/index.js";
3
+ import type { Model } from "../model/Model.js";
4
+ type RelationConstraint = (query: Builder<any>) => void | Builder<any>;
5
+ export interface Paginator<T> {
6
+ data: T[];
7
+ current_page: number;
8
+ per_page: number;
9
+ total: number;
10
+ last_page: number;
11
+ from: number;
12
+ to: number;
13
+ }
14
+ export declare class Builder<T = Record<string, any>> {
15
+ connection: Connection;
16
+ tableName: string;
17
+ columns: string[];
18
+ wheres: WhereClause[];
19
+ orders: OrderClause[];
20
+ groups: string[];
21
+ havings: string[];
22
+ limitValue?: number;
23
+ offsetValue?: number;
24
+ joins: string[];
25
+ distinctFlag: boolean;
26
+ model?: typeof Model;
27
+ eagerLoads: string[];
28
+ constructor(connection: Connection, table: string);
29
+ setModel(model: typeof Model): this;
30
+ table(table: string): this;
31
+ select(...columns: string[]): this;
32
+ distinct(): this;
33
+ where(column: string | Record<string, any>, operator?: string | any, value?: any, boolean?: "and" | "or", scope?: string): this;
34
+ orWhere(column: string | Record<string, any>, operator?: string | any, value?: any): this;
35
+ whereIn(column: string, values: any[], boolean?: "and" | "or", scope?: string): this;
36
+ whereNotIn(column: string, values: any[], boolean?: "and" | "or", scope?: string): this;
37
+ whereNull(column: string, boolean?: "and" | "or", scope?: string): this;
38
+ whereNotNull(column: string, boolean?: "and" | "or", scope?: string): this;
39
+ whereBetween(column: string, values: [any, any], boolean?: "and" | "or", scope?: string): this;
40
+ whereNotBetween(column: string, values: [any, any], boolean?: "and" | "or", scope?: string): this;
41
+ whereRaw(sql: string, boolean?: "and" | "or", scope?: string): this;
42
+ whereColumn(first: string, operator: string, second: string, boolean?: "and" | "or"): this;
43
+ whereExists(sql: string, boolean?: "and" | "or", not?: boolean): this;
44
+ orderBy(column: string, direction?: "asc" | "desc"): this;
45
+ groupBy(...columns: string[]): this;
46
+ having(column: string, operator: string, value: any): this;
47
+ limit(count: number): this;
48
+ offset(count: number): this;
49
+ forPage(page: number, perPage?: number): this;
50
+ join(table: string, first: string, operator: string, second: string, type?: string): this;
51
+ leftJoin(table: string, first: string, operator: string, second: string): this;
52
+ rightJoin(table: string, first: string, operator: string, second: string): this;
53
+ with(...relations: string[]): this;
54
+ withoutGlobalScope(scope: string): this;
55
+ withoutGlobalScopes(): this;
56
+ withTrashed(): this;
57
+ onlyTrashed(): this;
58
+ scope(name: string, ...args: any[]): this;
59
+ has(relationName: string, operator?: string | RelationConstraint, count?: number, callback?: RelationConstraint): this;
60
+ orHas(relationName: string, operator?: string | RelationConstraint, count?: number, callback?: RelationConstraint): this;
61
+ whereHas(relationName: string, callback?: RelationConstraint, operator?: string, count?: number): this;
62
+ orWhereHas(relationName: string, callback?: RelationConstraint, operator?: string, count?: number): this;
63
+ doesntHave(relationName: string, callback?: RelationConstraint): this;
64
+ whereDoesntHave(relationName: string, callback?: RelationConstraint): this;
65
+ withCount(relationName: string, alias?: string): this;
66
+ withSum(relationName: string, column: string, alias?: string): this;
67
+ withAvg(relationName: string, column: string, alias?: string): this;
68
+ withMin(relationName: string, column: string, alias?: string): this;
69
+ withMax(relationName: string, column: string, alias?: string): this;
70
+ addSelect(...columns: string[]): this;
71
+ clone(): Builder<T>;
72
+ wrapColumn(value: string): string;
73
+ escapeValue(value: any): string;
74
+ private wrap;
75
+ private wrapValue;
76
+ private escape;
77
+ private compileWheres;
78
+ private compileOrders;
79
+ private compileGroups;
80
+ private compileHavings;
81
+ private compileLimit;
82
+ private compileOffset;
83
+ private compileColumns;
84
+ private isRawColumn;
85
+ toSql(): string;
86
+ get(): Promise<T[]>;
87
+ first(): Promise<T | null>;
88
+ find(id: any, column?: string): Promise<T | null>;
89
+ pluck(column: string): Promise<any[]>;
90
+ private aggregate;
91
+ count(column?: string): Promise<number>;
92
+ sum(column: string): Promise<number>;
93
+ avg(column: string): Promise<number>;
94
+ min(column: string): Promise<any>;
95
+ max(column: string): Promise<any>;
96
+ paginate(perPage?: number, page?: number): Promise<Paginator<T>>;
97
+ insert(data: Partial<T> | Partial<T>[]): Promise<any>;
98
+ insertGetId(data: Partial<T>, idColumn?: string): Promise<any>;
99
+ update(data: Partial<T>): Promise<any>;
100
+ delete(): Promise<any>;
101
+ restore(): Promise<any>;
102
+ exists(): Promise<boolean>;
103
+ private getModelRelation;
104
+ private withAggregate;
105
+ }
106
+ export {};