forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequelize.d.ts
2787 lines (2376 loc) · 113 KB
/
sequelize.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Sequelize 2.0.0 dev13
// Project: http://sequelizejs.com
// Definitions by: samuelneff <https://github.com/samuelneff>, Peter Harris <https://github.com/codeanimal>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// Based on original work by: samuelneff <https://github.com/samuelneff/sequelize-auto-ts/blob/master/lib/sequelize.d.ts>
/// <reference path="../node/node.d.ts" />
/// <reference path="../lodash/lodash.d.ts" />
declare module "sequelize"
{
module sequelize {
interface SequelizeStaticAndInstance {
/**
* A reference to sequelize utilities. Most users will not need to use these utils directly. However, you might want
* to use Sequelize.Utils._, which is a reference to the lodash library, if you don't already have it imported in
* your project.
*/
Utils: Utils;
/**
* A modified version of bluebird promises, that allows listening for sql events.
*
* @see Promise
*/
Promise: Promise;
/**
* Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed
* both on the instance, and on the constructor.
*
* @see Validator
*/
Validator: Validator;
QueryTypes: QueryTypes;
/**
* A general error class.
*/
Error: Error;
/**
* Emitted when a validation fails.
*
* @see ValidationError
*/
ValidationError: ValidationError;
/**
* Creates a object representing a database function. This can be used in search queries, both in where and order
* parts, and as default values in column definitions. If you want to refer to columns in your function, you should
* use sequelize.col, so that the columns are properly interpreted as columns and not a strings.
*
* @param fn The function you want to call.
* @param args All further arguments will be passed as arguments to the function.
*/
fn(fn: string, ...args: Array<any>): any;
/**
* Creates a object representing a column in the DB. This is often useful in conjunction with sequelize.fn, since
* raw string arguments to fn will be escaped.
*
* @param col The name of the column
*/
col(col: string): Col;
/**
* Creates a object representing a call to the cast function.
*
* @param val The value to cast.
* @param type The type to cast it to.
*/
cast(val: any, type: string): Cast;
/**
* Creates a object representing a literal, i.e. something that will not be escaped.
*
* @param val Value to convert to a literal.
*/
literal(val: any): Literal;
/**
* An AND query.
*
* @param args Each argument (string or object) will be joined by AND.
*/
and(...args: Array<any>): And;
/**
* An OR query.
*
* @param args Each argument (string or object) will be joined by OR.
*/
or(...args: Array<any>): Or;
/**
* A way of specifying attr = condition. Mostly used internally.
*
* @param attr The attribute
* @param condition The condition. Can be both a simply type, or a further condition (.or, .and, .literal etc.)
*/
where(attr: string, condition: any): Where;
}
interface SequelizeStatic extends SequelizeStaticAndInstance, DataTypes {
/**
* Instantiate sequelize with name of database and username
* @param database database name
* @param username user name
*/
new (database: string, username: string): Sequelize;
/**
* Instantiate sequelize with name of database, username and password
* @param database database name
* @param username user name
* @param password password
*/
new (database: string, username: string, password: string): Sequelize;
/**
* Instantiate sequelize with name of database, username, password, and options.
* @param database database name
* @param username user name
* @param password password
* @param options options. @see Options
*/
new (database: string, username: string, password: string, options: Options): Sequelize;
/**
* Instantiate sequelize with name of database, username, and options.
*
* @param database database name
* @param username user name
* @param options options. @see Options
*/
new (database: string, username: string, options: Options): Sequelize;
/**
* Instantiate sequlize with an URI
* @param connectionString A full database URI
* @param options Options for sequelize. @see Options
*/
new (connectionString: string, options?: Options): Sequelize;
}
interface Sequelize extends SequelizeStaticAndInstance {
/**
* Sequelize configuration (undocumented).
*/
config: Config;
/**
* Sequelize options (undocumented).
*/
options: Options;
/**
* Models are stored here under the name given to sequelize.define
*/
models: any;
modelManager: ModelManager;
daoFactoryManager: ModelManager;
transactionManager: TransactionManager;
importCache: any;
/**
* A reference to the sequelize transaction class. Use this to access isolationLevels when creating a transaction.
*
* @see Transaction
*/
Transaction: TransactionStatic;
/**
* Returns the specified dialect.
*/
getDialect(): string;
/**
* Returns the singleton instance of QueryInterface.
*/
getQueryInterface(): QueryInterface;
/**
* Returns the singleton instance of Migrator.
* @param options Migration options
* @param force A flag that defines if the migrator should get instantiated or not.
*/
getMigrator(options?: MigratorOptions, force?: boolean): Migrator;
/**
* Define a new model, representing a table in the DB.
*
* @param daoName The name of the entity (table). Typically specified in singular form.
* @param attributes A hash of attributes to define. Each attribute can be either a string name for the attribute
* or can be an object defining the attribute and its options. Note attributes is not fully
* typed since TypeScript does not support union types--it can be either a string or an
* options object. @see AttributeOptions.
* @param options Table options. @see DefineOptions.
*/
define<TInstance, TPojo>(daoName: string, attributes: any, options?: DefineOptions): Model<TInstance, TPojo>;
/**
* Fetch a DAO factory which is already defined.
*
* @param daoName The name of a model defined with Sequelize.define.
*/
model<TInstance, TPojo>(daoName: string): Model<TInstance, TPojo>;
/**
* Checks whether a model with the given name is defined.
*
* @param daoName The name of a model defined with Sequelize.define.
*/
isDefined(daoName: string): boolean;
/**
* Imports a model defined in another file.
*
* @param path The path to the file that holds the model you want to import. If the part is relative, it will be
* resolved relatively to the calling file
*/
import<TInstance, TPojo>(path: string): Model<TInstance, TPojo>;
/**
* Execute a query on the DB, with the possibility to bypass all the sequelize goodness.
*
* @param sql SQL statement to execute.
*
* @param callee If callee is provided, the selected data will be used to build an instance of the DAO represented
* by the factory. Equivalent to calling Model.build with the values provided by the query.
*
* @param options Query options.
*
* @param replacements Either an object of named parameter replacements in the format :param or an array of
* unnamed replacements to replace ? in your SQL.
*/
query(sql: string, callee?: Model<any, any>, options?: QueryOptions, replacements?: any): EventEmitter;
query<TInstance, TPojo>(sql: string, callee?: Model<TInstance, TPojo>, options?: QueryOptions): EventEmitterT<Model<TInstance, TPojo>>;
/**
* Create a new database schema.
*
* @param schema Name of the schema.
*/
createSchema(schema: string): EventEmitter;
/**
* Show all defined schemas.
*/
showAllSchemas(): EventEmitter;
/**
* Drop a single schema.
*
* @param schema Name of the schema.
*/
dropSchema(schema: string): EventEmitter;
/**
* Drop all schemas.
*/
dropAllSchemas(): EventEmitter;
/**
* Sync all defined DAOs to the DB.
*
* @param options Options.
*/
sync(options?: SyncOptions): EventEmitter;
/**
* Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model.
*
* @param options The options passed to each call to Model.drop.
*/
drop(options: DropOptions): EventEmitter;
/**
* Test the connection by trying to authenticate. Alias for 'validate'.
*/
authenticate(): EventEmitter;
/**
* Alias for authenticate(). Test the connection by trying to authenticate. Alias for 'validate'.
*/
validate(): EventEmitter;
/**
* !! DEPRECATED : When passing a callback to a transaction a promise chain is expected in return,
* the transaction will be committed or rejected based on the promise chain returned to the callback.
*
* Start a transaction. When using transactions, you should pass the transaction in the options argument in order
* for the query to happen under that transaction.
*
* @param callback Called when the transaction has been set up and is ready for use. Callback takes transaction
* argument (overload available for error and transaction arguments too).
*/
transaction(callback: (transaction: Transaction) => boolean): Promise;
/**
* Start a transaction. When using transactions, you should pass the transaction in the options argument in order
* for the query to happen under that transaction.
*
* @param options Transaction options.
* @param callback Called when the transaction has been set up and is ready for use. Callback takes transaction
* argument (overload available for error and transaction arguments too).
*/
transaction(options?: TransactionOptions, callback?: (transaction: Transaction) => void): PromiseT<Transaction>;
close(): void;
}
interface Config {
database?: string;
username?: string;
password?: string;
host?: string;
port?: number;
pool?: PoolOptions;
protocol?: string;
queue?: boolean;
native?: boolean;
ssl?: boolean;
replication?: ReplicationOptions;
dialectModulePath?: string;
maxConcurrentQueries?: number;
dialectOptions?: any;
}
interface Model<TInstance, TPojo> extends Hooks, Associations {
/**
* A reference to the sequelize instance.
*/
sequelize: Sequelize;
/**
* The name of the model, typically singular.
*/
name: string;
/**
* The name of the underlying database table, typically plural.
*/
tableName: string;
options: DefineOptions;
attributes: any;
rawAttributes: any;
modelManager: ModelManager;
daoFactoryManager: ModelManager;
associations: any;
scopeObj: any;
/**
* Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model
* instance (this).
*/
sync(options?: SyncOptions): PromiseT<Model<TInstance, TPojo>>;
/**
* Drop the table represented by this Model.
*
* @param options
*/
drop(options?: DropOptions): Promise;
/**
* Apply a schema to this model. For postgres, this will actually place the schema in front of the table name -
* "schema"."tableName", while the schema will be prepended to the table name for mysql and sqlite -
* 'schema.tablename'.
*
* @param schema The name of the schema.
* @param options Schema options.
*/
schema(schema: string, options?: SchemaOptions): Model<TInstance, TPojo>;
/**
* Get the tablename of the model, taking schema into account. The method will return The name as a string if the
* model has no schema, or an object with tableName, schema and delimiter properties.
*/
getTableName(): any;
/**
* Apply a scope created in define to the model.
*
* @param options The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of
* arguments. To apply simple scopes, pass them as strings. For scope function, pass an object,
* with a method property. The value can either be a string, if the method does not take any
* arguments, or an array, where the first element is the name of the method, and consecutive
* elements are arguments to that method. Pass null to remove all scopes, including the default.
*/
scope(options: any): Model<TInstance, TPojo>;
/**
* Search for multiple instances..
*
* @param options A hash of options to describe the scope of the search.
* @param queryOptions Set the query options, e.g. raw, specifying that you want raw data instead of built
* Instances. See sequelize.query for options.
*/
findAll(options?: FindOptions, queryOptions?: QueryOptions): PromiseT<Array<TInstance>>;
/**
* Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single instance.
*
* @param options A hash of options to describe the scope of the search.
* @param queryOptions Set the query options, e.g. raw, specifying that you want raw data instead of built
* Instances. See sequelize.query for options
*/
find(options?: FindOptions, queryOptions?: QueryOptions): PromiseT<TInstance>;
/**
* Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single instance.
*
* @param options A number to search by id.
* @param queryOptions Set the query options, e.g. raw, specifying that you want raw data instead of built
* Instances. See sequelize.query for options
*/
find(id?: number, queryOptions?: QueryOptions): PromiseT<TInstance>;
/**
* Run an aggregation method on the specified field.
*
* @param field The field to aggregate over. Can be a field name or *.
* @param aggregateFunction The function to use for aggregation, e.g. sum, max etc.
* @param options Query options, particularly options.dataType.
*/
aggregate<V>(field: string, aggregateFunction: string, options: FindOptions): PromiseT<V>;
/**
* Count the number of records matching the provided where clause.
*
* @param options Conditions and options for the query.
*/
count(options?: FindOptions): PromiseT<number>;
/**
* Find all the rows matching your query, within a specified offset / limit, and get the total number of rows
* matching your query. This is very usefull for paging.
*
* @param findOptions Filtering options
* @param queryOptions Query options
*/
findAndCountAll(findOptions?: FindOptions, queryOptions?: QueryOptions): PromiseT<FindAndCountResult<TInstance>>;
/**
* Find the maximum value of field.
*
* @param field
* @param options
*/
max<V>(field: string, options?: FindOptions): PromiseT<V>;
/**
* Find the minimum value of field.
*
* @param field
* @param options
*/
min<V>(field: string, options?: FindOptions): PromiseT<V>;
/**
* Find the sum of field.
*
* @param field
* @param options
*/
sum(field: string, options?: FindOptions): PromiseT<number>;
/**
* Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty.
*
* @param values any from which to build entity instance.
* @param options any construction options.
*/
build(values: TPojo, options?: BuildOptions): TInstance;
/**
* Builds a new model instance and calls save on it..
*
* @param values
* @param options
*/
create(values: TPojo, options?: CopyOptions): PromiseT<TInstance>;
/**
* Find a row that matches the query, or build (but don't save) the row if none is found. The successfull result
* of the promise will be (instance, initialized) - Make sure to use .spread().
*
* @param where A hash of search attributes. Note that this method differs from finders, in that the syntax
* is { attr1: 42 } and NOT { where: { attr1: 42}}. This may be subject to change in 2.0
* @param defaults Default values to use if building a new instance
* @param options Options passed to the find call
*/
findOrInitialize(where: any, defaults?: TPojo, options?: QueryOptions): PromiseT<TInstance>;
/**
* Find a row that matches the query, or build and save the row if none is found The successfull result of the
* promise will be (instance, created) - Make sure to use .spread().
*
* @param where A hash of search attributes. Note that this method differs from finders, in that the syntax is
* { attr1: 42 } and NOT { where: { attr1: 42}}. This is subject to change in 2.0
* @param defaults Default values to use if creating a new instance
* @param options Options passed to the find and create calls.
*/
findOrCreate(where: any, defaults?: TPojo, options?: FindOrCreateOptions): PromiseT<TInstance>;
/**
* Create and insert multiple instances in bulk.
*
* @param records List of objects (key/value pairs) to create instances from.
* @param options
*/
bulkCreate(records: Array<TPojo>, options?: BulkCreateOptions): PromiseT<Array<TInstance>>;
/**
* Delete multiple instances.
*/
destroy(where?: any, options?: DestroyOptions): Promise;
/**
* Update multiple instances that match the where options.
*
* @param attrValueHash A hash of fields to change and their new values
* @param where Options to describe the scope of the search. Note that these options are not wrapped in a
* { where: ... } is in find / findAll calls etc. This is probably due to change in 2.0.
*/
update(attrValueHash: TPojo, where: any, options?: UpdateOptions): Promise;
/**
* Run a describe query on the table. The result will be return to the listener as a hash of attributes and their
* types.
*/
describe(): PromiseT<any>;
/**
* A proxy to the node-sql query builder, which allows you to build your query through a chain of method calls.
* The returned instance already has all the fields property populated with the field of the model.
*/
dataset(): any;
}
interface Instance<TInstance, TPojo> {
/**
* Returns true if this instance has not yet been persisted to the database.
*/
isNewRecord: boolean;
/**
* Returns the Model the instance was created from.
*/
Model: Model<TInstance, TPojo>;
/**
* A reference to the sequelize instance.
*/
sequelize: Sequelize;
/**
* If timestamps and paranoid are enabled, returns whether the deletedAt timestamp of this instance is set.
* Otherwise, always returns false.
*/
isDeleted: boolean;
/**
* Get the values of this Instance. Proxies to this.get.
*/
values: TPojo;
/**
* A getter for this.changed(). Returns true if any keys have changed.
*/
isDirty: boolean;
/**
* Get the values of the primary keys of this instance.
*/
primaryKeyValues: TPojo;
/**
* Get the value of the underlying data value.
*
* @param key Field to retrieve.
*/
getDataValue(key: string): any;
/**
* Update the underlying data value.
*
* @param key Field to set.
* @param value Value to set.
*/
setDataValue(key: string, value: any): void;
/**
* Retrieves the value for the key when specified. If no key is given, returns all values of the instance, also
* invoking virtual getters.
*/
get(key?: string): any;
/**
* Set is used to update values on the instance (the sequelize representation of the instance that is, remember
* that nothing will be persisted before you actually call save).
*/
set(key: string, value: any, options?: SetOptions): void;
/**
* If changed is called with a string it will return a boolean indicating whether the value of that key in
* dataValues is different from the value in _previousDataValues. If changed is called without an argument, it will
* return an array of keys that have changed.
*/
changed(key: string): any;
/**
* If changed is called with a string it will return a boolean indicating whether the value of that key in
* dataValues is different from the value in _previousDataValues. If changed is called without an argument, it will
* return an array of keys that have changed.
*/
changed(): Array<string>;
/**
* Returns the previous value for key from _previousDataValues.
*/
previous(key: string): any;
/**
* Validate this instance, and if the validation passes, persist it to the database.
*/
save(fields?: Array<string>, options?: SaveOptions): PromiseT<TInstance>;
/**
* Refresh the current instance in-place, i.e. update the object with current data from the DB and return the same
* object. This is different from doing a find(Instance.id), because that would create and return a new instance.
* With this method, all references to the Instance are updated with the new data and no new objects are created.
*/
reload(options?: FindOptions): PromiseT<TInstance>;
/**
* Validate the attribute of this instance according to validation rules set in the model definition.
*/
validate(options?: ValidateOptions): PromiseT<Error>;
/**
* This is the same as calling setAttributes, then calling save.
*/
updateAttributes(updates: TPojo, options: SaveOptions): PromiseT<TInstance>;
/**
* Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will either be
* completely deleted, or have its deletedAt timestamp set to the current time.
*
* @param options Allows caller to specify if delete should be forced.
*/
destroy(options?: DestroyInstanceOptions): Promise;
/**
* Increment the value of one or more columns. This is done in the database, which means it does not use the
* values currently stored on the Instance.
*
* @param fields If a string is provided, that column is incremented by the value of by given in options. If an
* array is provided, the same is true for each column. If and object is provided, each column is
* incremented by the value given.
* @param options Increment options.
*/
increment(fields: any, options?: IncrementOptions): Promise;
/**
* Decrement the value of one or more columns. This is done in the database, which means it does not use the
* values currently stored on the Instance.
*
* @param fields If a string is provided, that column is decremented by the value of by given in options. If an
* array is provided, the same is true for each column. If and object is provided, each column is
* decremented by the value given.
* @param options Decrement options.
*/
decrement(fields: any, options?: IncrementOptions): Promise;
/**
* Check whether all values of this and other Instance are the same.
*/
equal(other: TInstance): boolean;
/**
* Check if this is eqaul to one of others by calling equals.
*
* @param others Other instances to compare to.
*/
equalsOneOf(others: Array<TInstance>): boolean;
/**
* Convert the instance to a JSON representation. Proxies to calling get with no keys. This means get all values
* gotten from the DB, and apply all custom getters.
*/
toJSON(): TPojo;
}
interface Transaction extends TransactionStatic {
/**
* Commit the transaction.
*/
commit(): Transaction;
/**
* Rollback (abort) the transaction.
*/
rollback(): Transaction;
}
interface TransactionStatic {
/**
* The possible isolation levels to use when starting a transaction
*/
ISOLATION_LEVELS: TransactionIsolationLevels;
/**
* Possible options for row locking. Used in conjuction with find calls.
*/
LOCK: TransactionLocks;
}
interface TransactionIsolationLevels {
READ_UNCOMMITTED: string;// "READ UNCOMMITTED"
READ_COMMITTED: string; // "READ COMMITTED"
REPEATABLE_READ: string; // "REPEATABLE READ"
SERIALIZABLE: string; // "SERIALIZABLE"
}
interface TransactionLocks {
UPDATE: string; // UPDATE
SHARE: string; // SHARE
}
interface Hooks {
/**
* Add a named hook to the model.
*
* @param hooktype
*/
addHook(hooktype: string, name: string, fn: (...args: Array<any>) => void): boolean;
/**
* Add a hook to the model.
*
* @param hooktype
*/
addHook(hooktype: string, fn: (...args: Array<any>) => void): boolean;
/**
* A named hook that is run before validation.
*/
beforeValidate<T>(name: string, validator: (dao: T, callback: (err?: Error) => void) => void): void;
/**
* A hook that is run before validation.
*/
beforeValidate<T>(validator: (dao: T, callback: (err?: Error) => void) => void): void;
/**
* A named hook that is run before validation.
*/
afterValidate<T>(name: string, validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run before validation.
*/
afterValidate<T>(validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run before creating a single instance.
*/
beforeCreate<T>(name: string, validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run before creating a single instance.
*/
beforeCreate<T>(validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run after creating a single instance.
*/
afterCreate<T>(name: string, validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run after creating a single instance.
*/
afterCreate<T>(validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run before destroying a single instance.
*/
beforeDestroy<T>(name: string, validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run before destroying a single instance.
*/
beforeDestroy<T>(validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run after destroying a single instance.
*/
afterDestroy<T>(name: string, validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run after destroying a single instance.
*/
afterDestroy<T>(validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run before updating a single instance.
*/
beforeUpdate<T>(name: string, validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run before updating a single instance.
*/
beforeUpdate<T>(validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run after updating a single instance.
*/
afterUpdate<T>(name: string, validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run after updating a single instance.
*/
afterUpdate<T>(validator: (dao: T, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run before creating instances in bulk.
*/
beforeBulkCreate<T>(name: string, validator: (daos: Array<T>, fields: Array<string>, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run before creating instances in bulk.
*/
beforeBulkCreate<T>(validator: (daos: Array<T>, fields: Array<string>, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run after creating instances in bulk.
*/
afterBulkCreate<T>(name: string, validator: (daos: Array<T>, fields: Array<string>, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A hook that is run after creating instances in bulk.
*/
afterBulkCreate<T>(validator: (daos: Array<T>, fields: Array<string>, callback: (err?: Error, dao?: T) => void) => void): void;
/**
* A named hook that is run before destroying instances in bulk.
*/
beforeBulkDestroy<T>(name: string, validator: (where: any, callback: (err?: Error, where?: any) => void) => void): void;
/**
* A hook that is run before destroying instances in bulk.
*/
beforeBulkDestroy<T>(validator: (where: any, callback: (err?: Error, where?: any) => void) => void): void;
/**
* A named hook that is run after destroying instances in bulk.
*/
afterBulkDestroy<T>(name: string, validator: (where: any, callback: (err?: Error, where?: any) => void) => void): void;
/**
* A hook that is run after destroying instances in bulk.
*/
afterBulkDestroy<T>(validator: (where: any, callback: (err?: Error, where?: any) => void) => void): void;
/**
* A named hook that is run before updating instances in bulk.
*/
beforeBulkUpdate<T>(name: string, validator: (instances: Array<T>, where: any, callback: (err?: Error, instances?: Array<T>, where?: any) => void) => void): void;
/**
* A hook that is run before updating instances in bulk.
*/
beforeBulkUpdate<T>(validator: (instances: Array<T>, where: any, callback: (err?: Error, instances?: Array<T>, where?: any) => void) => void): void;
/**
* A named hook that is run after updating instances in bulk.
*/
afterBulkUpdate<T>(name: string, validator: (instances: Array<T>, where: any, callback: (err?: Error, instances?: Array<T>, where?: any) => void) => void): void;
/**
* A hook that is run after updating instances in bulk.
*/
afterBulkUpdate<T>(validator: (instances: Array<T>, where: any, callback: (err?: Error, instances?: Array<T>, where?: any) => void) => void): void;
}
interface Associations {
/**
* Creates an association between this (the source) and the provided target. The foreign key is added on the target.
*
* @param target
* @param options
*/
hasOne<TInstance, TPojo>(target: Model<TInstance, TPojo>, options?: AssociationOptions): void;
/**
* Creates an association between this (the source) and the provided target. The foreign key is added on the source.
*
* @param target
* @param options
*/
belongsTo<TInstance, TPojo>(target: Model<TInstance, TPojo>, options?: AssociationOptions): void;
/**
* Creates an association to connect sources with multiple targets. Furthermore the targets can also have connections to multiple sources.
*
* @param target
* @param options
*/
belongsToMany<TInstance, TPojo>(target: Model<TInstance, TPojo>, options?: AssociationOptions): void;
/**
* Create an association that is either 1:m or n:m.
*
* @param target
* @param options
*/
hasMany<TInstance, TPojo>(target: Model<TInstance, TPojo>, options?: AssociationOptions): void;
}
/**
* Extension of external project that doesn't have definitions.
*
* See https://github.com/chriso/validator.js and https://github.com/sequelize/sequelize/blob/master/lib/instance-validator.js
*/
interface Validator {
}
/**
* Custom class defined, but no extra methods or functionality even.
*/
interface ValidationError extends Error {
}
interface QueryChainer {
/**
* Add an query to the chainer. This can be done in two ways - either by invoking the method like you would
* normally, and then adding the returned emitter to the chainer, or by passing the class that you want to call a
* method on, the name of the method, and its parameters to the chainer. The second form might sound a bit
* cumbersome, but it is used when you want to run queries in serial.
*
* @param emitterOrKlass
* @param method
* @param params
* @param options
*/
add(emitterOrKlass: any, method?: string, params?: any, options?: any): QueryChainer;
/**
* Run the query chainer. In reality, this means, wait for all the added emitters to finish, since the queries
* began executing as soon as you invoked their methods.
*/
run(): EventEmitter;
/**
* Run the chainer serially, so that each query waits for the previous one to finish before it starts.
*
* @param options @see QueryChainerRunSeriallyOptions
*/
runSerially(options?: QueryChainerRunSeriallyOptions): EventEmitter;
}
interface QueryInterface {
/**
* Returns the dialect-specific sql generator.
*/
QueryGenerator: QueryGenerator;
/**
* Queries the schema (table list).
*
* @param schema The schema to query. Applies only to Postgres.
*/
createSchema(schema?: string): EventEmitter;
/**
* Drops the specified schema (table).
*
* @param schema The name of the table to drop.
*/
dropSchema(schema: string): EventEmitter;
/**
* Drops all tables.
*/
dropAllSchemas(): EventEmitter;
/**
* Queries all table names in the database.