@spinajs/orm-sql 2.0.38 → 2.0.39

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 (67) hide show
  1. package/lib/compilers.d.ts +25 -6
  2. package/lib/compilers.js +223 -16
  3. package/lib/compilers.js.map +1 -1
  4. package/lib/converters.js +4 -7
  5. package/lib/converters.js.map +1 -1
  6. package/lib/index.js +3 -0
  7. package/lib/index.js.map +1 -1
  8. package/lib/orm/src/builders.d.ts +636 -0
  9. package/lib/orm/src/builders.js +1509 -0
  10. package/lib/orm/src/builders.js.map +1 -0
  11. package/lib/orm/src/converters.d.ts +14 -0
  12. package/lib/orm/src/converters.js +57 -0
  13. package/lib/orm/src/converters.js.map +1 -0
  14. package/lib/orm/src/decorators.d.ts +152 -0
  15. package/lib/orm/src/decorators.js +454 -0
  16. package/lib/orm/src/decorators.js.map +1 -0
  17. package/lib/orm/src/dehydrators.d.ts +7 -0
  18. package/lib/orm/src/dehydrators.js +41 -0
  19. package/lib/orm/src/dehydrators.js.map +1 -0
  20. package/lib/orm/src/driver.d.ts +80 -0
  21. package/lib/orm/src/driver.js +104 -0
  22. package/lib/orm/src/driver.js.map +1 -0
  23. package/lib/orm/src/enums.d.ts +115 -0
  24. package/lib/orm/src/enums.js +125 -0
  25. package/lib/orm/src/enums.js.map +1 -0
  26. package/lib/orm/src/exceptions.d.ts +6 -0
  27. package/lib/orm/src/exceptions.js +11 -0
  28. package/lib/orm/src/exceptions.js.map +1 -0
  29. package/lib/orm/src/hydrators.d.ts +19 -0
  30. package/lib/orm/src/hydrators.js +110 -0
  31. package/lib/orm/src/hydrators.js.map +1 -0
  32. package/lib/orm/src/interfaces.d.ts +794 -0
  33. package/lib/orm/src/interfaces.js +293 -0
  34. package/lib/orm/src/interfaces.js.map +1 -0
  35. package/lib/orm/src/model.d.ts +310 -0
  36. package/lib/orm/src/model.js +779 -0
  37. package/lib/orm/src/model.js.map +1 -0
  38. package/lib/orm/src/orm.d.ts +61 -0
  39. package/lib/orm/src/orm.js +341 -0
  40. package/lib/orm/src/orm.js.map +1 -0
  41. package/lib/orm/src/relations.d.ts +150 -0
  42. package/lib/orm/src/relations.js +681 -0
  43. package/lib/orm/src/relations.js.map +1 -0
  44. package/lib/orm/src/statements.d.ts +140 -0
  45. package/lib/orm/src/statements.js +314 -0
  46. package/lib/orm/src/statements.js.map +1 -0
  47. package/lib/orm/src/types.d.ts +11 -0
  48. package/lib/orm/src/types.js +3 -0
  49. package/lib/orm/src/types.js.map +1 -0
  50. package/lib/orm-sql/src/builders.d.ts +11 -0
  51. package/lib/orm-sql/src/builders.js +42 -0
  52. package/lib/orm-sql/src/builders.js.map +1 -0
  53. package/lib/orm-sql/src/compilers.d.ts +226 -0
  54. package/lib/orm-sql/src/compilers.js +1016 -0
  55. package/lib/orm-sql/src/compilers.js.map +1 -0
  56. package/lib/orm-sql/src/converters.d.ts +10 -0
  57. package/lib/orm-sql/src/converters.js +39 -0
  58. package/lib/orm-sql/src/converters.js.map +1 -0
  59. package/lib/orm-sql/src/index.d.ts +6 -0
  60. package/lib/orm-sql/src/index.js +70 -0
  61. package/lib/orm-sql/src/index.js.map +1 -0
  62. package/lib/orm-sql/src/statements.d.ts +46 -0
  63. package/lib/orm-sql/src/statements.js +268 -0
  64. package/lib/orm-sql/src/statements.js.map +1 -0
  65. package/lib/statements.js +22 -4
  66. package/lib/statements.js.map +1 -1
  67. package/package.json +5 -5
@@ -0,0 +1,794 @@
1
+ import { Op } from './enums';
2
+ import { QueryBuilder, RawQuery } from './builders';
3
+ import { SordOrder, WhereBoolean } from './enums';
4
+ import { IQueryStatement, Wrap } from './statements';
5
+ import { PartialModel, Unbox, WhereFunction } from './types';
6
+ import { Relation } from './relations';
7
+ import { OrmDriver } from './driver';
8
+ import { Constructor, IContainer } from '@spinajs/di';
9
+ import { ModelBase } from './model';
10
+ import { DateTime } from 'luxon';
11
+ export declare enum QueryContext {
12
+ Insert = 0,
13
+ Select = 1,
14
+ Update = 2,
15
+ Delete = 3,
16
+ Schema = 4,
17
+ Transaction = 5
18
+ }
19
+ export declare enum ColumnAlterationType {
20
+ Add = 0,
21
+ Modify = 1,
22
+ Rename = 2
23
+ }
24
+ export declare abstract class DefaultValueBuilder<T> {
25
+ Query: RawQuery;
26
+ Value: string | number;
27
+ /**
28
+ * fills by default with current date
29
+ */
30
+ abstract date(): T;
31
+ /**
32
+ * fills by default with current datetime
33
+ */
34
+ abstract dateTime(): T;
35
+ /**
36
+ * Fills column with default value
37
+ *
38
+ * @param val - value to fill
39
+ */
40
+ abstract value(val: string | number): T;
41
+ /**
42
+ * Fills column with result of query provided
43
+ *
44
+ * @param query - raw query instance
45
+ */
46
+ abstract raw(query: RawQuery): T;
47
+ }
48
+ export declare enum InsertBehaviour {
49
+ /**
50
+ * Ignores if primary key exists in db
51
+ */
52
+ InsertOrIgnore = 0,
53
+ /**
54
+ * Updates entry if pk exists
55
+ */
56
+ InsertOrUpdate = 1,
57
+ /**
58
+ * Replaces entry if pk exists
59
+ */
60
+ InsertOrReplace = 2,
61
+ None = 3
62
+ }
63
+ /**
64
+ * Foreign key referential actions
65
+ */
66
+ export declare enum ReferentialAction {
67
+ Cascade = "CASCADE",
68
+ SetNull = "SET NULL",
69
+ Restrict = "RESTRICT",
70
+ NoAction = "NO ACTION",
71
+ SetDefault = "SET DEFAULT"
72
+ }
73
+ /**
74
+ * Transaction mode when migration DB
75
+ */
76
+ export declare enum MigrationTransactionMode {
77
+ /**
78
+ * Migration is run whithout transaction
79
+ */
80
+ None = 0,
81
+ /**
82
+ * On transaction for one migration - every migration has its own
83
+ */
84
+ PerMigration = 1
85
+ }
86
+ /**
87
+ * Configuration options to set in configuration file and used in OrmDriver
88
+ */
89
+ export interface IDriverOptions {
90
+ /**
91
+ * Max connections limit
92
+ */
93
+ PoolLimit?: number;
94
+ /**
95
+ * Database name associated with this connection
96
+ */
97
+ Database?: string;
98
+ /**
99
+ * User associatet with this connection
100
+ */
101
+ User?: string;
102
+ /**
103
+ * Password to database
104
+ */
105
+ Password?: string;
106
+ /**
107
+ * DB Host
108
+ */
109
+ Host?: string;
110
+ /**
111
+ * Connection port
112
+ */
113
+ Port?: number;
114
+ /**
115
+ * Connection encoding eg. utf-8
116
+ */
117
+ Encoding?: string;
118
+ /**
119
+ * Database filename eg. for Sqlite driver
120
+ */
121
+ Filename?: string;
122
+ /**
123
+ * Driver name eg. mysql, sqlite, mssql etc.
124
+ */
125
+ Driver: string;
126
+ /**
127
+ * Connection name for identification
128
+ */
129
+ Name: string;
130
+ /**
131
+ * Additional driver-specific options
132
+ */
133
+ Options?: any;
134
+ Migration?: {
135
+ /**
136
+ * Should run migration on startup
137
+ */
138
+ OnStartup?: boolean;
139
+ /**
140
+ * Migration table name, if not set default is spinajs_orm_migrations
141
+ */
142
+ Table?: string;
143
+ /**
144
+ * Migration transaction options
145
+ */
146
+ Transaction?: {
147
+ /**
148
+ * How to run migration - with or without transaction
149
+ */
150
+ Mode?: MigrationTransactionMode;
151
+ };
152
+ };
153
+ /**
154
+ * When building queries with auto generated tables & fields
155
+ * we wrap them in special caharacter eg. $
156
+ * Different sql engines allows different characters,
157
+ * SQLITE & MYSQL allow to use $ in queries, but MSSQL its special characted used to create pseudocolumn
158
+ *
159
+ * Example: SELECT $users$.Name FROM users as $users$
160
+ */
161
+ AliasSeparator?: string;
162
+ /**
163
+ * Is this connection default. Later can be referenced under 'default' name
164
+ * eg. @Connection('default')
165
+ */
166
+ DefaultConnection?: boolean;
167
+ }
168
+ export interface IMigrationDescriptor {
169
+ /**
170
+ * Whitch connection migration will be executed
171
+ */
172
+ Connection: string;
173
+ }
174
+ export interface IValueConverterDescriptor {
175
+ Class: Constructor<ValueConverter>;
176
+ Options?: any;
177
+ }
178
+ /**
179
+ * Describes model, used internally
180
+ */
181
+ export interface IModelDescriptor {
182
+ /**
183
+ * Primary key name
184
+ */
185
+ PrimaryKey: string;
186
+ /**
187
+ * Connection name, must be avaible in db config
188
+ */
189
+ Connection: string;
190
+ /**
191
+ * Table name in database for this model
192
+ */
193
+ TableName: string;
194
+ /**
195
+ * Optional, describes timestamps in model
196
+ */
197
+ Timestamps: IModelTimestampDescriptor;
198
+ /**
199
+ * Optional, describes soft delete
200
+ */
201
+ SoftDelete: IModelSoftDeleteDescriptor;
202
+ /**
203
+ * Optional, is archive mode enabled
204
+ */
205
+ Archived: IModelArchivedDescriptor;
206
+ /**
207
+ * Column / fields list in model
208
+ */
209
+ Columns: IColumnDescriptor[];
210
+ /**
211
+ * Converters attached to fields
212
+ */
213
+ Converters: Map<string, IValueConverterDescriptor>;
214
+ /**
215
+ * List of unique columns ( UNIQUE constraint )
216
+ */
217
+ JunctionModelProperties: IJunctionProperty[];
218
+ /**
219
+ * List of relations in model
220
+ */
221
+ Relations: Map<string, IRelationDescriptor>;
222
+ /** Name of model */
223
+ Name: string;
224
+ /**
225
+ * Model discrimination map that allows to create different models based on db field value
226
+ */
227
+ DiscriminationMap: IDiscriminationMap;
228
+ /**
229
+ * Orm driver that this model
230
+ */
231
+ Driver: OrmDriver;
232
+ /**
233
+ * Json schema for validation
234
+ */
235
+ Schema: any;
236
+ }
237
+ export interface IDiscriminationMap {
238
+ /**
239
+ * DB field that holds inheritance value
240
+ */
241
+ Field: string;
242
+ /**
243
+ * Field values mapped for proper models
244
+ */
245
+ Models: Map<string, Constructor<ModelBase>>;
246
+ }
247
+ export interface IDiscriminationEntry {
248
+ Key: string;
249
+ Value: Constructor<ModelBase>;
250
+ }
251
+ export declare enum RelationType {
252
+ One = 0,
253
+ Many = 1,
254
+ ManyToMany = 2
255
+ }
256
+ export declare type ForwardRefFunction = () => Constructor<ModelBase>;
257
+ /**
258
+ * Returns result of last insert or affected rows ( eg. rows affected would be 0 if insert is ignored )
259
+ */
260
+ export interface IUpdateResult {
261
+ RowsAffected: number;
262
+ LastInsertId: number;
263
+ }
264
+ export interface IRelationDescriptor {
265
+ /**
266
+ * Name of relations, defaults for property name in model that owns relation
267
+ */
268
+ Name: string;
269
+ /**
270
+ * Is it one-to-one, one-to-many or many-to-many
271
+ */
272
+ Type: RelationType;
273
+ TargetModelType: Constructor<ModelBase> | ForwardRefFunction | string;
274
+ /**
275
+ * Relation model ( foreign )
276
+ */
277
+ TargetModel: Constructor<ModelBase>;
278
+ /**
279
+ * Relation owner
280
+ */
281
+ SourceModel: Constructor<ModelBase>;
282
+ /**
283
+ * Relation foreign key (one to one, one to many)
284
+ */
285
+ ForeignKey: string;
286
+ /**
287
+ * Relation primary key (one to one, one to many)
288
+ */
289
+ PrimaryKey: string;
290
+ /**
291
+ * Used in many to many relations, model for join table
292
+ */
293
+ JunctionModel?: Constructor<ModelBase>;
294
+ /**
295
+ * Join table foreign keys, defaults to auto generated field names. Can be override.
296
+ */
297
+ JunctionModelTargetModelFKey_Name?: string;
298
+ JunctionModelSourceModelFKey_Name?: string;
299
+ /**
300
+ * Is this relation recursive ? Used for hierarchical / paren one-to-one relations
301
+ */
302
+ Recursive: boolean;
303
+ /**
304
+ * Relation factory, sometimes we dont want to create standard relation object
305
+ */
306
+ Factory?: (model: ModelBase<unknown>, relation: IRelationDescriptor, container: IContainer) => Relation<ModelBase<unknown>, ModelBase<unknown>>;
307
+ /**
308
+ * sometimes we dont want to create standard relation object, so we create type
309
+ * that is passed in this property
310
+ */
311
+ RelationClass?: Constructor<Relation<ModelBase<unknown>, ModelBase<unknown>>>;
312
+ }
313
+ export interface IJunctionProperty {
314
+ Name: string;
315
+ Model: Constructor<ModelBase>;
316
+ }
317
+ /**
318
+ * Table column description, used in models to build schema, validate & other stuff
319
+ */
320
+ export interface IColumnDescriptor {
321
+ /**
322
+ * Columnt type eg int, varchar, text
323
+ */
324
+ Type: string;
325
+ /**
326
+ * Max character lenght handled in column
327
+ */
328
+ MaxLength: number;
329
+ /**
330
+ * Column comment, use it for documentation purposes.
331
+ */
332
+ Comment: string;
333
+ /**
334
+ * Default column value
335
+ */
336
+ DefaultValue: any;
337
+ /**
338
+ * Full database type with size/length info & sign eg. int(10) unsigned if avaible
339
+ */
340
+ NativeType: string;
341
+ /**
342
+ * Numeric types sign
343
+ */
344
+ Unsigned: boolean;
345
+ /**
346
+ * Is column nullable (can be null)
347
+ */
348
+ Nullable: boolean;
349
+ /**
350
+ * Is column primary key
351
+ */
352
+ PrimaryKey: boolean;
353
+ /**
354
+ * Is column auto increment
355
+ */
356
+ AutoIncrement: boolean;
357
+ /**
358
+ * Column name
359
+ */
360
+ Name: string;
361
+ /**
362
+ * Value converter between database & model
363
+ */
364
+ Converter: IValueConverter;
365
+ /**
366
+ * JSON schema definition build for this column. Used to automate data validation
367
+ */
368
+ Schema: any;
369
+ /**
370
+ * Does have unique constraint
371
+ */
372
+ Unique: boolean;
373
+ /**
374
+ * Is uuid generated column
375
+ */
376
+ Uuid: boolean;
377
+ Ignore: boolean;
378
+ }
379
+ /**
380
+ * Value converter between model & database data types
381
+ */
382
+ export interface IValueConverter {
383
+ /**
384
+ * Converts value to database type
385
+ *
386
+ * @param value - value to convert
387
+ */
388
+ toDB(value: any, model: ModelBase, options: any): any;
389
+ /**
390
+ * Converts value from database type eg. mysql timestamp to DateTime
391
+ *
392
+ * @param value - value to convert
393
+ */
394
+ fromDB(value: any, rawData: any, options: any): any;
395
+ }
396
+ /**
397
+ * Model timestamps description
398
+ */
399
+ export interface IModelTimestampDescriptor {
400
+ /**
401
+ * Created at column name
402
+ */
403
+ CreatedAt: string;
404
+ /**
405
+ * Updated at column name
406
+ */
407
+ UpdatedAt: string;
408
+ }
409
+ /**
410
+ * Model soft delete description
411
+ */
412
+ export interface IModelSoftDeleteDescriptor {
413
+ /**
414
+ * Deleted at column name
415
+ */
416
+ DeletedAt: string;
417
+ }
418
+ export declare abstract class OrmMigration {
419
+ /**
420
+ *
421
+ * Migrate up - create tables, indices etc.
422
+ * Be aware that model function are not avaible yet. To fill tables with
423
+ * data use fill function
424
+ */
425
+ abstract up(connection: OrmDriver): Promise<void>;
426
+ /**
427
+ * Migrate down - undo changes made in up
428
+ */
429
+ abstract down(connection: OrmDriver): Promise<void>;
430
+ }
431
+ /**
432
+ * Model archived description
433
+ */
434
+ export interface IModelArchivedDescriptor {
435
+ /**
436
+ * Archived at column name
437
+ */
438
+ ArchivedAt: string;
439
+ }
440
+ export interface IQueryLimit {
441
+ limit?: number;
442
+ offset?: number;
443
+ }
444
+ export interface ISort {
445
+ column: string;
446
+ order: SordOrder;
447
+ }
448
+ export interface IQueryBuilder {
449
+ Table: string;
450
+ TableAlias: string;
451
+ Database: string;
452
+ database(database: string): IQueryBuilder;
453
+ from(table: string, alias?: string): this;
454
+ setAlias(alias: string): this;
455
+ Driver: OrmDriver;
456
+ Container: IContainer;
457
+ }
458
+ export interface ILimitBuilder<T> {
459
+ take(count: number): this;
460
+ skip(count: number): this;
461
+ first(): Promise<Unbox<T>>;
462
+ firstOrFail(): Promise<Unbox<T>>;
463
+ firstOrThrow(error: Error): Promise<Unbox<T>>;
464
+ orThrow(error: Error): Promise<Unbox<T>>;
465
+ getLimits(): IQueryLimit;
466
+ }
467
+ export interface IOrderByBuilder {
468
+ orderBy(column: string): this;
469
+ orderByDescending(column: string): this;
470
+ order(column: string, direction: 'ASC' | 'DESC'): this;
471
+ getSort(): ISort;
472
+ }
473
+ export interface IColumnsBuilder {
474
+ /**
475
+ * clears selected columns
476
+ */
477
+ clearColumns(): this;
478
+ /**
479
+ *
480
+ * Select columns from db result ( multiple at once )
481
+ *
482
+ * @param names - column names to select
483
+ */
484
+ columns(names: string[]): this;
485
+ /**
486
+ * Return selected columns in this query
487
+ */
488
+ getColumns(): IQueryStatement[];
489
+ /**
490
+ * Selects single column from DB result with optional alias
491
+ * Can be used multiple times
492
+ *
493
+ * @param column - column to select
494
+ * @param alias - column alias ( optional )
495
+ */
496
+ select(column: string, alias?: string): this;
497
+ /**
498
+ * Selects custom values from DB. eg. Count(*)
499
+ *
500
+ * @param rawQuery - raw query to be executed
501
+ */
502
+ select(rawQuery: RawQuery): this;
503
+ /**
504
+ * Selects multiple columns at once with aliases. Map key property is column name, value is its alias
505
+ *
506
+ * @param columns - column list with aliases
507
+ */
508
+ select(columns: Map<string, string>): this;
509
+ }
510
+ export interface IWhereBuilder<T> {
511
+ Statements: IQueryStatement[];
512
+ Op: WhereBoolean;
513
+ where(val: boolean): this;
514
+ where(val: PartialModel<T>): this;
515
+ where(func: WhereFunction<T>): this;
516
+ where(column: string, operator: Op, value: any): this;
517
+ where(column: string, value: any): this;
518
+ where(statement: Wrap): this;
519
+ where(column: string | boolean | WhereFunction<T> | RawQuery | PartialModel<T> | Wrap, operator?: Op | any, value?: any): this;
520
+ orWhere(val: boolean): this;
521
+ orWhere(val: PartialModel<T>): this;
522
+ orWhere(func: WhereFunction<T>): this;
523
+ orWhere(column: string, operator: Op, value: any): this;
524
+ orWhere(column: string, value: any): this;
525
+ orWhere(statement: Wrap): this;
526
+ orWhere(column: string | boolean | WhereFunction<T> | RawQuery | Wrap | PartialModel<T>, operator?: Op | any, value?: any): this;
527
+ andWhere(val: boolean): this;
528
+ andWhere(val: PartialModel<T>): this;
529
+ andWhere(func: WhereFunction<T>): this;
530
+ andWhere(column: string, operator: Op, value: any): this;
531
+ andWhere(column: string, value: any): this;
532
+ andWhere(statement: Wrap): this;
533
+ andWhere(column: string | boolean | WhereFunction<T> | RawQuery | Wrap | PartialModel<T>, operator?: Op | any, value?: any): this;
534
+ whereObject(obj: any): this;
535
+ whereNotNull(column: string): this;
536
+ whereNull(column: string): this;
537
+ whereNot(column: string, val: any): this;
538
+ whereIn(column: string, val: any[]): this;
539
+ whereNotIn(column: string, val: any[]): this;
540
+ whereExist(query: ISelectQueryBuilder<T>): this;
541
+ whereNotExists(query: ISelectQueryBuilder<T>): this;
542
+ whereBetween(column: string, val: any[]): this;
543
+ whereNotBetween(column: string, val: any[]): this;
544
+ whereInSet(column: string, val: any[]): this;
545
+ whereNotInSet(column: string, val: any[]): this;
546
+ clearWhere(): this;
547
+ }
548
+ export interface IWithRecursiveBuilder {
549
+ CteRecursive: IQueryStatement;
550
+ withRecursive(recKeyName: string, pkKeyName: string): this;
551
+ }
552
+ export interface IGroupByBuilder {
553
+ GroupStatements: IQueryStatement[];
554
+ clearGroupBy(): this;
555
+ groupBy(expression: RawQuery | string): this;
556
+ }
557
+ /**
558
+ * Dummy interface for allowing to add extensions for builder via declaration merging & mixins
559
+ */
560
+ export interface ISelectBuilderExtensions {
561
+ }
562
+ export interface IJoinBuilder {
563
+ JoinStatements: IQueryStatement[];
564
+ clearJoins(): this;
565
+ innerJoin<M extends ModelBase>(model: Constructor<M>, where?: (this: ISelectQueryBuilder<M>) => void): this;
566
+ innerJoin(query: RawQuery): this;
567
+ innerJoin(table: string, foreignKey: string, primaryKey: string): this;
568
+ innerJoin(table: string, tableAlias: string, foreignKey: string, primaryKey: string): this;
569
+ leftJoin<M extends ModelBase>(model: Constructor<M>, where?: (this: ISelectQueryBuilder<M>) => void): this;
570
+ leftJoin(query: RawQuery): this;
571
+ leftJoin(table: string, foreignKey: string, primaryKey: string): this;
572
+ leftJoin(table: string, tableAlias: string, foreignKey: string, primaryKey: string): this;
573
+ leftOuterJoin<M extends ModelBase>(model: Constructor<M>, where?: (this: ISelectQueryBuilder<M>) => void): this;
574
+ leftOuterJoin(query: RawQuery): this;
575
+ leftOuterJoin(table: string, foreignKey: string, primaryKey: string): this;
576
+ leftOuterJoin(table: string, tableAlias: string, foreignKey: string, primaryKey: string): this;
577
+ rightJoin<M extends ModelBase>(model: Constructor<M>, where?: (this: ISelectQueryBuilder<M>) => void): this;
578
+ rightJoin(query: RawQuery): this;
579
+ rightJoin(table: string, foreignKey: string, primaryKey: string): this;
580
+ rightJoin(table: string, tableAlias: string, foreignKey: string, primaryKey: string): this;
581
+ rightOuterJoin<M extends ModelBase>(model: Constructor<M>, where?: (this: ISelectQueryBuilder<M>) => void): this;
582
+ rightOuterJoin(query: RawQuery): this;
583
+ rightOuterJoin(table: string, foreignKey: string, primaryKey: string): this;
584
+ rightOuterJoin(table: string, tableAlias: string, foreignKey: string, primaryKey: string): this;
585
+ fullOuterJoin<M extends ModelBase>(model: Constructor<M>, where?: (this: ISelectQueryBuilder<M>) => void): this;
586
+ fullOuterJoin(query: RawQuery): this;
587
+ fullOuterJoin(table: string, foreignKey: string, primaryKey: string): this;
588
+ fullOuterJoin(table: string, tableAlias: string, foreignKey: string, primaryKey: string): this;
589
+ crossJoin<M extends ModelBase>(model: Constructor<M>, where?: (this: ISelectQueryBuilder<M>) => void): this;
590
+ crossJoin(query: RawQuery): this;
591
+ crossJoin(table: string, foreignKey: string, primaryKey: string): this;
592
+ crossJoin(table: string, tableAlias: string, foreignKey: string, primaryKey: string): this;
593
+ }
594
+ export interface ISelectQueryBuilder<T> extends IColumnsBuilder, IOrderByBuilder, ILimitBuilder<T>, IWhereBuilder<T>, IJoinBuilder, IWithRecursiveBuilder, IGroupByBuilder {
595
+ min(column: string, as?: string): this;
596
+ max(column: string, as?: string): this;
597
+ count(column: string, as?: string): this;
598
+ sum(column: string, as?: string): this;
599
+ avg(column: string, as?: string): this;
600
+ distinct(): this;
601
+ clone(): this;
602
+ }
603
+ export interface ICompilerOutput {
604
+ expression: string;
605
+ bindings: any[];
606
+ }
607
+ export interface IQueryCompiler {
608
+ compile(): ICompilerOutput | ICompilerOutput[];
609
+ }
610
+ export interface ILimitCompiler {
611
+ limit(builder: ILimitBuilder<any>): ICompilerOutput;
612
+ }
613
+ export interface IGroupByCompiler {
614
+ group(builder: IGroupByBuilder): ICompilerOutput;
615
+ }
616
+ export interface IRecursiveCompiler {
617
+ recursive(builder: IWithRecursiveBuilder): ICompilerOutput;
618
+ }
619
+ export interface IColumnsCompiler {
620
+ columns(builder: IColumnsBuilder): ICompilerOutput;
621
+ }
622
+ export interface IWhereCompiler {
623
+ where(builder: IWhereBuilder<any>): ICompilerOutput;
624
+ }
625
+ export interface IJoinCompiler {
626
+ join(builder: IJoinBuilder): ICompilerOutput;
627
+ }
628
+ /**
629
+ * Definitions of query compiler are needed for DI resolving
630
+ * ==========================================================
631
+ */
632
+ export declare abstract class RecursiveQueryCompiler implements IQueryCompiler {
633
+ abstract compile(): ICompilerOutput;
634
+ }
635
+ export declare abstract class SelectQueryCompiler implements IQueryCompiler {
636
+ abstract compile(): ICompilerOutput;
637
+ }
638
+ export declare abstract class JoinQueryCompiler implements IQueryCompiler {
639
+ abstract compile(): ICompilerOutput;
640
+ }
641
+ export declare abstract class IndexQueryCompiler implements IQueryCompiler {
642
+ abstract compile(): ICompilerOutput;
643
+ }
644
+ export declare abstract class LimitQueryCompiler implements IQueryCompiler {
645
+ abstract compile(): ICompilerOutput;
646
+ }
647
+ export declare abstract class ForeignKeyQueryCompiler implements IQueryCompiler {
648
+ abstract compile(): ICompilerOutput;
649
+ }
650
+ export declare abstract class DeleteQueryCompiler implements IQueryCompiler {
651
+ abstract compile(): ICompilerOutput;
652
+ }
653
+ export declare abstract class UpdateQueryCompiler implements IQueryCompiler {
654
+ abstract compile(): ICompilerOutput;
655
+ }
656
+ export declare abstract class InsertQueryCompiler implements IQueryCompiler {
657
+ abstract compile(): ICompilerOutput;
658
+ }
659
+ export declare abstract class OnDuplicateQueryCompiler implements IQueryCompiler {
660
+ abstract compile(): ICompilerOutput;
661
+ }
662
+ export declare abstract class TableQueryCompiler implements IQueryCompiler {
663
+ abstract compile(): ICompilerOutput[] | ICompilerOutput;
664
+ }
665
+ export declare abstract class TableHistoryQueryCompiler implements IQueryCompiler {
666
+ abstract compile(): ICompilerOutput[];
667
+ }
668
+ export declare abstract class TruncateTableQueryCompiler implements IQueryCompiler {
669
+ abstract compile(): ICompilerOutput;
670
+ }
671
+ export declare abstract class TableCloneQueryCompiler implements IQueryCompiler {
672
+ abstract compile(): ICompilerOutput[];
673
+ }
674
+ export declare abstract class EventQueryCompiler implements IQueryCompiler {
675
+ abstract compile(): ICompilerOutput[];
676
+ }
677
+ export declare abstract class DropEventQueryCompiler implements IQueryCompiler {
678
+ abstract compile(): ICompilerOutput[];
679
+ }
680
+ export declare abstract class AlterTableQueryCompiler implements IQueryCompiler {
681
+ abstract compile(): ICompilerOutput[];
682
+ }
683
+ export declare abstract class TableExistsCompiler implements IQueryCompiler {
684
+ abstract compile(): ICompilerOutput;
685
+ }
686
+ export declare abstract class DropTableCompiler implements IQueryCompiler {
687
+ abstract compile(): ICompilerOutput;
688
+ }
689
+ export declare abstract class ColumnQueryCompiler implements IQueryCompiler {
690
+ abstract compile(): ICompilerOutput;
691
+ }
692
+ export declare abstract class AlterColumnQueryCompiler implements IQueryCompiler {
693
+ abstract compile(): ICompilerOutput;
694
+ }
695
+ export declare abstract class OrderByQueryCompiler implements IQueryCompiler {
696
+ abstract compile(): ICompilerOutput;
697
+ }
698
+ export declare abstract class GroupByQueryCompiler implements IQueryCompiler {
699
+ abstract compile(): ICompilerOutput;
700
+ }
701
+ /**
702
+ * ==========================================================
703
+ */
704
+ /**
705
+ * Middlewares for query builders
706
+ */
707
+ export interface IBuilderMiddleware<T = any[]> {
708
+ /**
709
+ *
710
+ * Executed AFTER query is executed in DB and raw data is fetched
711
+ * Use it to transform DB data before everything else
712
+ *
713
+ * @param data - raw data fetched from DB
714
+ */
715
+ afterQuery(data: T): T;
716
+ /**
717
+ * Executed when model is about to create. Use it to
718
+ * override model creation logic. If null is returned, default model
719
+ * is executed
720
+ *
721
+ * @param data - raw data to create
722
+ */
723
+ modelCreation(data: any): ModelBase;
724
+ /**
725
+ * executed after model was created ( all returned data by query is executed)
726
+ *
727
+ * @param data - hydrated data. Models are created and hydrated with data
728
+ */
729
+ afterHydration(data: ModelBase[]): Promise<any[] | void>;
730
+ }
731
+ export declare abstract class QueryMiddleware {
732
+ abstract afterQueryCreation(query: QueryBuilder): void;
733
+ }
734
+ export declare abstract class ModelMiddleware {
735
+ abstract onDelete(model: ModelBase): Promise<void>;
736
+ abstract onUpdate(model: ModelBase): Promise<void>;
737
+ abstract onInsert(model: ModelBase): Promise<void>;
738
+ abstract onSelect(model: ModelBase): Promise<void>;
739
+ }
740
+ export declare class ValueConverter implements IValueConverter {
741
+ /**
742
+ * Converts value to database type
743
+ *
744
+ * @param value - value to convert
745
+ */
746
+ toDB(_value: any, _model: ModelBase<any>, _options: any): any;
747
+ /**
748
+ * Converts value from database type eg. mysql timestamp to DateTime
749
+ *
750
+ * @param value - value to convert
751
+ */
752
+ fromDB(_value: any, _rawData: any, _options: any): any;
753
+ }
754
+ /**
755
+ * Converter for DATETIME field (eg. mysql datetime)
756
+ */
757
+ export declare class DatetimeValueConverter extends ValueConverter {
758
+ }
759
+ export declare class JsonValueConverter extends ValueConverter {
760
+ /**
761
+ * Converts value to database type
762
+ *
763
+ * @param value - value to convert
764
+ */
765
+ toDB(value: any): any;
766
+ /**
767
+ * Converts value from database type eg. mysql timestamp to DateTime
768
+ *
769
+ * @param value - value to convert
770
+ */
771
+ fromDB(value: any): any;
772
+ }
773
+ /**
774
+ * Converter for set field (eg. mysql SET)
775
+ */
776
+ export declare class SetValueConverter extends ValueConverter {
777
+ }
778
+ export declare abstract class TableAliasCompiler {
779
+ abstract compile(builder: QueryBuilder, tbl?: string): string;
780
+ }
781
+ export interface IUniversalConverterOptions {
782
+ TypeColumn: string;
783
+ }
784
+ /**
785
+ * base class for select & where builder for defining scopes
786
+ */
787
+ export declare abstract class QueryScope {
788
+ }
789
+ export interface IHistoricalModel {
790
+ readonly __action__: 'insert' | 'update' | 'delete';
791
+ readonly __revision__: number;
792
+ readonly __start__: DateTime;
793
+ readonly __end__: DateTime;
794
+ }