@spinajs/orm 1.2.44 → 1.2.50

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 (58) hide show
  1. package/lib/orm.d.ts +1 -0
  2. package/lib/orm.js +22 -20
  3. package/lib/orm.js.map +1 -1
  4. package/package.json +5 -5
  5. package/lib/helpers.d.ts +0 -1
  6. package/lib/helpers.js +0 -14
  7. package/lib/helpers.js.map +0 -1
  8. package/lib/log-common/src/index.d.ts +0 -180
  9. package/lib/log-common/src/index.js +0 -49
  10. package/lib/log-common/src/index.js.map +0 -1
  11. package/lib/orm/src/builders.d.ts +0 -429
  12. package/lib/orm/src/builders.js +0 -1082
  13. package/lib/orm/src/builders.js.map +0 -1
  14. package/lib/orm/src/cli.d.ts +0 -1
  15. package/lib/orm/src/cli.js +0 -2
  16. package/lib/orm/src/cli.js.map +0 -1
  17. package/lib/orm/src/converters.d.ts +0 -9
  18. package/lib/orm/src/converters.js +0 -22
  19. package/lib/orm/src/converters.js.map +0 -1
  20. package/lib/orm/src/decorators.d.ts +0 -122
  21. package/lib/orm/src/decorators.js +0 -380
  22. package/lib/orm/src/decorators.js.map +0 -1
  23. package/lib/orm/src/driver.d.ts +0 -77
  24. package/lib/orm/src/driver.js +0 -84
  25. package/lib/orm/src/driver.js.map +0 -1
  26. package/lib/orm/src/enums.d.ts +0 -111
  27. package/lib/orm/src/enums.js +0 -122
  28. package/lib/orm/src/enums.js.map +0 -1
  29. package/lib/orm/src/exceptions.d.ts +0 -6
  30. package/lib/orm/src/exceptions.js +0 -11
  31. package/lib/orm/src/exceptions.js.map +0 -1
  32. package/lib/orm/src/hydrators.d.ts +0 -16
  33. package/lib/orm/src/hydrators.js +0 -70
  34. package/lib/orm/src/hydrators.js.map +0 -1
  35. package/lib/orm/src/index.d.ts +0 -12
  36. package/lib/orm/src/index.js +0 -25
  37. package/lib/orm/src/index.js.map +0 -1
  38. package/lib/orm/src/interfaces.d.ts +0 -615
  39. package/lib/orm/src/interfaces.js +0 -186
  40. package/lib/orm/src/interfaces.js.map +0 -1
  41. package/lib/orm/src/model.d.ts +0 -135
  42. package/lib/orm/src/model.js +0 -449
  43. package/lib/orm/src/model.js.map +0 -1
  44. package/lib/orm/src/orm.d.ts +0 -59
  45. package/lib/orm/src/orm.js +0 -278
  46. package/lib/orm/src/orm.js.map +0 -1
  47. package/lib/orm/src/relations.d.ts +0 -96
  48. package/lib/orm/src/relations.js +0 -503
  49. package/lib/orm/src/relations.js.map +0 -1
  50. package/lib/orm/src/statements.d.ts +0 -132
  51. package/lib/orm/src/statements.js +0 -257
  52. package/lib/orm/src/statements.js.map +0 -1
  53. package/lib/orm/src/types.d.ts +0 -2
  54. package/lib/orm/src/types.js +0 -3
  55. package/lib/orm/src/types.js.map +0 -1
  56. package/lib/orm/src/wrappers.d.ts +0 -5
  57. package/lib/orm/src/wrappers.js +0 -13
  58. package/lib/orm/src/wrappers.js.map +0 -1
@@ -1,429 +0,0 @@
1
- import { Container, Constructor } from '@spinajs/di';
2
- import { QueryMethod, SORT_ORDER, WhereBoolean, WhereOperators } from './enums';
3
- import { IColumnsBuilder, ICompilerOutput, ILimitBuilder, IOrderByBuilder, IQueryBuilder, IQueryLimit, ISort, IWhereBuilder, QueryContext, IJoinBuilder, IBuilderMiddleware, IWithRecursiveBuilder, ReferentialAction, IGroupByBuilder } from './interfaces';
4
- import { ColumnStatement, IQueryStatement, WrapStatement } from './statements';
5
- import { WhereFunction } from './types';
6
- import { OrmDriver } from './driver';
7
- import { ModelBase } from './model';
8
- import { OrmRelation, IOrmRelation } from './relations';
9
- /**
10
- * Trick typescript by using the inbuilt interface inheritance and declaration merging
11
- * for builder classes.
12
- *
13
- * We use mixins to extend functionality of builder eg. insert query builder uses function from columns builder
14
- * and so on...
15
- */
16
- export interface InsertQueryBuilder extends IColumnsBuilder {
17
- }
18
- export interface DeleteQueryBuilder extends IWhereBuilder, ILimitBuilder {
19
- }
20
- export interface UpdateQueryBuilder extends IColumnsBuilder, IWhereBuilder {
21
- }
22
- export interface SelectQueryBuilder extends IColumnsBuilder, IOrderByBuilder, ILimitBuilder, IWhereBuilder, IJoinBuilder, IWithRecursiveBuilder, IGroupByBuilder {
23
- }
24
- export declare class Builder<T = any> {
25
- protected _driver: OrmDriver;
26
- protected _container: Container;
27
- protected _model?: Constructor<ModelBase>;
28
- protected _nonSelect: boolean;
29
- protected _queryContext: QueryContext;
30
- protected _middlewares: IBuilderMiddleware[];
31
- protected _asRaw: boolean;
32
- constructor(container: Container, driver: OrmDriver, model?: Constructor<ModelBase>);
33
- middleware(middleware: IBuilderMiddleware): this;
34
- /**
35
- * Builds query that is ready to use in DB
36
- */
37
- toDB(): ICompilerOutput;
38
- then(resolve: (rows: any[]) => void, reject: (err: Error) => void): Promise<T>;
39
- }
40
- /**
41
- * Base class for queires. Implements basic query functionality
42
- *
43
- */
44
- export declare class QueryBuilder<T = any> extends Builder<T> implements IQueryBuilder {
45
- protected _method: QueryMethod;
46
- protected _table: string;
47
- protected _tableAlias: string;
48
- protected _schema: string;
49
- constructor(container: Container, driver: OrmDriver, model?: Constructor<ModelBase>);
50
- /**
51
- * SQL table name that query is executed on
52
- *
53
- * @example
54
- * SELECT * FROM `users`
55
- */
56
- get Table(): string;
57
- /**
58
- * DB table alias
59
- */
60
- get TableAlias(): string;
61
- /**
62
- * SQL schema/database name that query is executed on.
63
- *
64
- * @example
65
- * SELECT * FROM `spinejs`.`users` as u
66
- */
67
- get Schema(): string;
68
- /**
69
- * Sets schema to this query.
70
- *
71
- * @param schema - schema or database name in database
72
- */
73
- schema(schema: string): this;
74
- /**
75
- * Sets table that query is executed on
76
- *
77
- * @param table - sql table name
78
- * @param alias - sql table alias
79
- *
80
- * @example
81
- *
82
- * this.setTable("user","u")
83
- *
84
- */
85
- setTable(table: string, alias?: string): this;
86
- /**
87
- * Sets table alias for query
88
- *
89
- * @param alias - sql table alias
90
- */
91
- setAlias(alias: string): this;
92
- from(table: string, alias?: string): this;
93
- }
94
- export declare class LimitBuilder implements ILimitBuilder {
95
- protected _fail: boolean;
96
- protected _first: boolean;
97
- protected _limit: IQueryLimit;
98
- constructor();
99
- take(count: number): this;
100
- skip(count: number): this;
101
- first(): Promise<any>;
102
- firstOrFail(): Promise<any>;
103
- getLimits(): IQueryLimit;
104
- }
105
- export declare class OrderByBuilder implements IOrderByBuilder {
106
- protected _sort: ISort;
107
- constructor();
108
- order(column: string, direction: SORT_ORDER): this;
109
- orderBy(column: string): this;
110
- orderByDescending(column: string): this;
111
- getSort(): ISort;
112
- }
113
- export declare class ColumnsBuilder implements IColumnsBuilder {
114
- protected _container: Container;
115
- protected _columns: IQueryStatement[];
116
- protected _tableAlias: string;
117
- protected _model?: Constructor<ModelBase>;
118
- constructor();
119
- /**
120
- * Clears all select clauses from the query.
121
- *
122
- * @example
123
- *
124
- * query.columns()
125
- *
126
- */
127
- clearColumns(): this;
128
- columns(names: string[]): this;
129
- select(column: string | RawQuery | Map<string, string>, alias?: string): this;
130
- getColumns(): IQueryStatement[];
131
- }
132
- export declare class RawQuery {
133
- get Query(): string;
134
- get Bindings(): any[];
135
- static create(query: string, bindings?: any[]): RawQuery;
136
- private _query;
137
- private _bindings;
138
- constructor(query: string, bindings?: any[]);
139
- }
140
- export declare class GroupByBuilder implements IGroupByBuilder {
141
- protected _container: Container;
142
- protected _groupStatements: IQueryStatement[];
143
- get GroupStatements(): IQueryStatement[];
144
- clearGroupBy(): this;
145
- groupBy(expression: string | RawQuery): this;
146
- }
147
- export declare class JoinBuilder implements IJoinBuilder {
148
- get JoinStatements(): IQueryStatement[];
149
- protected _joinStatements: IQueryStatement[];
150
- protected _container: Container;
151
- protected _tableAlias: string;
152
- constructor(container: Container);
153
- clearJoins(): this;
154
- innerJoin(query: RawQuery): this;
155
- innerJoin(table: string, foreignKey: string, primaryKey: string): this;
156
- leftJoin(query: RawQuery): this;
157
- leftJoin(table: string, foreignKey: string, primaryKey: string): this;
158
- leftOuterJoin(query: RawQuery): this;
159
- leftOuterJoin(table: string, foreignKey: string, primaryKey: string): this;
160
- rightJoin(query: RawQuery): this;
161
- rightJoin(table: string, foreignKey: string, primaryKey: string): this;
162
- rightOuterJoin(query: RawQuery): this;
163
- rightOuterJoin(table: string, foreignKey: string, primaryKey: string): this;
164
- fullOuterJoin(query: RawQuery): this;
165
- fullOuterJoin(table: string, foreignKey: string, primaryKey: string): this;
166
- crossJoin(query: RawQuery): this;
167
- crossJoin(table: string, foreignKey: string, primaryKey: string): this;
168
- private addJoinStatement;
169
- }
170
- export declare class WithRecursiveBuilder implements IWithRecursiveBuilder {
171
- protected _container: Container;
172
- protected _cteStatement: IQueryStatement;
173
- get CteRecursive(): IQueryStatement;
174
- withRecursive(rcKeyName: string, pkName: string): this;
175
- }
176
- export declare class WhereBuilder implements IWhereBuilder {
177
- protected _statements: IQueryStatement[];
178
- protected _boolean: WhereBoolean;
179
- protected _container: Container;
180
- protected _tableAlias: string;
181
- get Statements(): IQueryStatement[];
182
- get Op(): WhereBoolean;
183
- constructor(container: Container, tableAlias?: string);
184
- where(column: string | boolean | WhereFunction | RawQuery | WrapStatement | {}, operator?: WhereOperators | any, value?: any): this;
185
- orWhere(column: string | boolean | WhereFunction | {}, ..._args: any[]): this;
186
- andWhere(column: string | boolean | WhereFunction | {}, ..._args: any[]): this;
187
- whereObject(obj: any): this;
188
- whereNotNull(column: string): this;
189
- whereNull(column: string): this;
190
- whereNot(column: string, val: any): this;
191
- whereIn(column: string, val: any[]): this;
192
- whereNotIn(column: string, val: any[]): this;
193
- whereExist(query: SelectQueryBuilder): this;
194
- whereNotExists(query: SelectQueryBuilder): this;
195
- whereBetween(column: string, val: any[]): this;
196
- whereNotBetween(column: string, val: any[]): this;
197
- whereInSet(column: string, val: any[]): this;
198
- whereNotInSet(column: string, val: any[]): this;
199
- clearWhere(): this;
200
- }
201
- export declare class SelectQueryBuilder<T = any> extends QueryBuilder<T> {
202
- /**
203
- * column query props
204
- */
205
- protected _distinct: boolean;
206
- protected _columns: IQueryStatement[];
207
- /**
208
- * limit query props
209
- */
210
- protected _fail: boolean;
211
- protected _first: boolean;
212
- protected _limit: IQueryLimit;
213
- /**
214
- * order by query props
215
- */
216
- protected _sort: ISort;
217
- /**
218
- * where query props
219
- */
220
- protected _statements: IQueryStatement[];
221
- protected _boolean: WhereBoolean;
222
- protected _joinStatements: IQueryStatement[];
223
- protected _groupStatements: IQueryStatement[];
224
- protected _cteStatement: IQueryStatement;
225
- protected _owner: IOrmRelation;
226
- protected _relations: IOrmRelation[];
227
- this: this;
228
- get IsDistinct(): boolean;
229
- get Owner(): IOrmRelation;
230
- get Relations(): IOrmRelation[];
231
- constructor(container: Container, driver: OrmDriver, model: Constructor<any>, owner?: IOrmRelation);
232
- asRaw<T>(): Promise<T>;
233
- setAlias(alias: string): this;
234
- clone(): this;
235
- populate<R = this>(relation: string, callback?: (this: SelectQueryBuilder<R>, relation: OrmRelation) => void): this;
236
- mergeStatements(builder: SelectQueryBuilder): void;
237
- min(column: string, as?: string): this;
238
- max(column: string, as?: string): this;
239
- count(column: string, as?: string): this;
240
- sum(column: string, as?: string): this;
241
- avg(column: string, as?: string): this;
242
- distinct(): this;
243
- toDB(): ICompilerOutput;
244
- then(resolve: (rows: any[]) => void, reject: (err: Error) => void): Promise<T>;
245
- execute(): Promise<T>;
246
- }
247
- export declare class DeleteQueryBuilder extends QueryBuilder {
248
- /**
249
- * where query props
250
- */
251
- protected _statements: IQueryStatement[];
252
- protected _boolean: WhereBoolean;
253
- protected _truncate: boolean;
254
- protected _limit: IQueryLimit;
255
- get Truncate(): boolean;
256
- private this;
257
- constructor(container: Container, driver: OrmDriver, model: Constructor<any>);
258
- toDB(): ICompilerOutput;
259
- truncate(): this;
260
- }
261
- export declare class OnDuplicateQueryBuilder {
262
- protected _column: string[];
263
- protected _parent: InsertQueryBuilder;
264
- protected _columnsToUpdate: Array<string | RawQuery>;
265
- protected _container: Container;
266
- constructor(container: Container, insertQueryBuilder: InsertQueryBuilder, column?: string | string[]);
267
- getColumn(): string[];
268
- getColumnsToUpdate(): (string | RawQuery)[];
269
- getParent(): InsertQueryBuilder;
270
- update(columns: string[] | RawQuery[]): this;
271
- then(resolve: (rows: any[]) => void, reject: (err: Error) => void): Promise<any>;
272
- toDB(): ICompilerOutput;
273
- }
274
- export declare class UpdateQueryBuilder extends QueryBuilder {
275
- /**
276
- * where query props
277
- */
278
- protected _statements: IQueryStatement[];
279
- protected _boolean: WhereBoolean;
280
- protected _value: {};
281
- get Value(): {};
282
- this: this;
283
- constructor(container: Container, driver: OrmDriver, model: Constructor<any>);
284
- in(name: string): this;
285
- update(value: {}): this;
286
- toDB(): ICompilerOutput;
287
- }
288
- export declare class InsertQueryBuilder extends QueryBuilder {
289
- DuplicateQueryBuilder: OnDuplicateQueryBuilder;
290
- protected _values: any[][];
291
- protected _columns: ColumnStatement[];
292
- protected _ignore: boolean;
293
- this: this;
294
- get Values(): any[][];
295
- get Ignore(): boolean;
296
- constructor(container: Container, driver: OrmDriver, model: Constructor<any>);
297
- /**
298
- * Sets insert to ignore on duplicate
299
- */
300
- ignore(): this;
301
- values(data: {} | Array<{}>): this;
302
- into(table: string, schema?: string): this;
303
- onDuplicate(column?: string | string[]): OnDuplicateQueryBuilder;
304
- toDB(): ICompilerOutput;
305
- }
306
- export declare class IndexQueryBuilder extends Builder {
307
- Name: string;
308
- Unique: boolean;
309
- Table: string;
310
- Columns: string[];
311
- constructor(container: Container, driver: OrmDriver);
312
- name(name: string): this;
313
- unique(): this;
314
- table(name: string): this;
315
- columns(colNames: string[]): this;
316
- toDB(): ICompilerOutput;
317
- }
318
- export declare class ForeignKeyBuilder {
319
- ForeignKeyField: string;
320
- Table: string;
321
- PrimaryKey: string;
322
- OnDeleteAction: ReferentialAction;
323
- OnUpdateAction: ReferentialAction;
324
- constructor();
325
- /**
326
- *
327
- * Referenced field in child table
328
- *
329
- * @param fkName - name of foreign field in child table
330
- */
331
- foreignKey(fkName: string): this;
332
- /**
333
- *
334
- * Referenced parent table & key
335
- *
336
- * @param table - parent table
337
- * @param pKey - parant table key field
338
- */
339
- references(table: string, pKey: string): this;
340
- /**
341
- *
342
- * On delete action
343
- *
344
- * @param action - action to take on delete
345
- */
346
- onDelete(action: ReferentialAction): this;
347
- /**
348
- *
349
- * On update action
350
- *
351
- * @param action - action to take on update
352
- */
353
- onUpdate(action: ReferentialAction): this;
354
- /**
355
- * Shorhand for on update and on delete cascade settings
356
- */
357
- cascade(): this;
358
- }
359
- export declare class ColumnQueryBuilder {
360
- Name: string;
361
- Unique: boolean;
362
- Unsigned: boolean;
363
- AutoIncrement: boolean;
364
- Default: string | RawQuery | number;
365
- PrimaryKey: boolean;
366
- Comment: string;
367
- Charset: string;
368
- Collation: string;
369
- NotNull: boolean;
370
- Type: string;
371
- Args: any[];
372
- constructor(name: string, type: string, ...args: any[]);
373
- notNull(): this;
374
- unique(): this;
375
- unsigned(): this;
376
- autoIncrement(): this;
377
- default(val: string | RawQuery | number): this;
378
- primaryKey(): this;
379
- comment(comment: string): this;
380
- charset(charset: string): this;
381
- collation(collation: string): this;
382
- }
383
- export declare class TableQueryBuilder extends QueryBuilder {
384
- int: (name: string) => ColumnQueryBuilder;
385
- bigint: (name: string) => ColumnQueryBuilder;
386
- tinyint: (name: string) => ColumnQueryBuilder;
387
- smallint: (name: string) => ColumnQueryBuilder;
388
- mediumint: (name: string) => ColumnQueryBuilder;
389
- text: (name: string) => ColumnQueryBuilder;
390
- tinytext: (name: string) => ColumnQueryBuilder;
391
- mediumtext: (name: string) => ColumnQueryBuilder;
392
- smalltext: (name: string) => ColumnQueryBuilder;
393
- longtext: (name: string) => ColumnQueryBuilder;
394
- string: (name: string, length?: number) => ColumnQueryBuilder;
395
- float: (name: string, precision?: number, scale?: number) => ColumnQueryBuilder;
396
- double: (name: string, precision?: number, scale?: number) => ColumnQueryBuilder;
397
- decimal: (name: string, precision?: number, scale?: number) => ColumnQueryBuilder;
398
- boolean: (name: string) => ColumnQueryBuilder;
399
- bit: (name: string) => ColumnQueryBuilder;
400
- date: (name: string) => ColumnQueryBuilder;
401
- dateTime: (name: string) => ColumnQueryBuilder;
402
- time: (name: string) => ColumnQueryBuilder;
403
- timestamp: (name: string) => ColumnQueryBuilder;
404
- enum: (name: string, values: any[]) => ColumnQueryBuilder;
405
- json: (name: string) => ColumnQueryBuilder;
406
- binary: (name: string, size: number) => ColumnQueryBuilder;
407
- tinyblob: (name: string) => ColumnQueryBuilder;
408
- mediumblob: (name: string) => ColumnQueryBuilder;
409
- longblob: (name: string) => ColumnQueryBuilder;
410
- set: (name: string, allowed: string[]) => ColumnQueryBuilder;
411
- get Columns(): ColumnQueryBuilder[];
412
- get ForeignKeys(): ForeignKeyBuilder[];
413
- protected _columns: ColumnQueryBuilder[];
414
- protected _foreignKeys: ForeignKeyBuilder[];
415
- protected _comment: string;
416
- protected _charset: string;
417
- constructor(container: Container, driver: OrmDriver, name: string);
418
- increments(name: string): ColumnQueryBuilder;
419
- comment(comment: string): void;
420
- charset(charset: string): void;
421
- foreignKey(foreignKey: string): ForeignKeyBuilder;
422
- toDB(): ICompilerOutput;
423
- }
424
- export declare class SchemaQueryBuilder {
425
- protected container: Container;
426
- protected driver: OrmDriver;
427
- constructor(container: Container, driver: OrmDriver);
428
- createTable(name: string, callback: (table: TableQueryBuilder) => void): TableQueryBuilder;
429
- }