@loopback/repository 2.9.0 → 2.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.md +1 -6
- package/dist/decorators/metadata.js +3 -3
- package/dist/decorators/metadata.js.map +1 -1
- package/dist/define-model-class.js +3 -1
- package/dist/define-model-class.js.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js.map +1 -1
- package/dist/mixins/repository.mixin.js +0 -2
- package/dist/mixins/repository.mixin.js.map +1 -1
- package/dist/model.d.ts +19 -2
- package/dist/model.js +54 -0
- package/dist/model.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.helpers.d.ts +1 -0
- package/dist/relations/belongs-to/belongs-to.helpers.js +13 -6
- package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many-through-repository.factory.js +4 -1
- package/dist/relations/has-many/has-many-through-repository.factory.js.map +1 -1
- package/dist/relations/has-many/has-many-through.helpers.d.ts +35 -0
- package/dist/relations/has-many/has-many-through.helpers.js +44 -1
- package/dist/relations/has-many/has-many-through.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many-through.repository.d.ts +2 -1
- package/dist/relations/has-many/has-many-through.repository.js +21 -5
- package/dist/relations/has-many/has-many-through.repository.js.map +1 -1
- package/dist/relations/relation.types.d.ts +1 -1
- package/dist/relations/relation.types.js +1 -1
- package/dist/repositories/legacy-juggler-bridge.d.ts +75 -0
- package/dist/repositories/legacy-juggler-bridge.js +2 -2
- package/dist/repositories/legacy-juggler-bridge.js.map +1 -1
- package/dist/repositories/repository.js.map +1 -1
- package/package.json +12 -12
- package/src/decorators/metadata.ts +3 -3
- package/src/define-model-class.ts +4 -1
- package/src/index.ts +0 -6
- package/src/mixins/repository.mixin.ts +0 -2
- package/src/model.ts +74 -2
- package/src/relations/belongs-to/belongs-to.helpers.ts +19 -8
- package/src/relations/has-many/has-many-through-repository.factory.ts +5 -1
- package/src/relations/has-many/has-many-through.helpers.ts +49 -0
- package/src/relations/has-many/has-many-through.repository.ts +26 -9
- package/src/relations/relation.types.ts +1 -1
- package/src/repositories/legacy-juggler-bridge.ts +91 -7
- package/src/repositories/repository.ts +2 -1
|
@@ -573,12 +573,95 @@ export class DefaultCrudRepository<
|
|
|
573
573
|
return ensurePromise(this.modelClass.exists(id, options));
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
-
|
|
576
|
+
/**
|
|
577
|
+
* Execute a SQL command.
|
|
578
|
+
*
|
|
579
|
+
* **WARNING:** In general, it is always better to perform database actions
|
|
580
|
+
* through repository methods. Directly executing SQL may lead to unexpected
|
|
581
|
+
* results, corrupted data, security vulnerabilities and other issues.
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
*
|
|
585
|
+
* ```ts
|
|
586
|
+
* // MySQL
|
|
587
|
+
* const result = await repo.execute(
|
|
588
|
+
* 'SELECT * FROM Products WHERE size > ?',
|
|
589
|
+
* [42]
|
|
590
|
+
* );
|
|
591
|
+
*
|
|
592
|
+
* // PostgreSQL
|
|
593
|
+
* const result = await repo.execute(
|
|
594
|
+
* 'SELECT * FROM Products WHERE size > $1',
|
|
595
|
+
* [42]
|
|
596
|
+
* );
|
|
597
|
+
* ```
|
|
598
|
+
*
|
|
599
|
+
* @param command A parameterized SQL command or query.
|
|
600
|
+
* Check your database documentation for information on which characters to
|
|
601
|
+
* use as parameter placeholders.
|
|
602
|
+
* @param parameters List of parameter values to use.
|
|
603
|
+
* @param options Additional options, for example `transaction`.
|
|
604
|
+
* @returns A promise which resolves to the command output as returned by the
|
|
605
|
+
* database driver. The output type (data structure) is database specific and
|
|
606
|
+
* often depends on the command executed.
|
|
607
|
+
*/
|
|
608
|
+
execute(
|
|
577
609
|
command: Command,
|
|
578
610
|
parameters: NamedParameters | PositionalParameters,
|
|
579
611
|
options?: Options,
|
|
580
|
-
): Promise<AnyObject
|
|
581
|
-
|
|
612
|
+
): Promise<AnyObject>;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Execute a MongoDB command.
|
|
616
|
+
*
|
|
617
|
+
* **WARNING:** In general, it is always better to perform database actions
|
|
618
|
+
* through repository methods. Directly executing MongoDB commands may lead
|
|
619
|
+
* to unexpected results and other issues.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
*
|
|
623
|
+
* ```ts
|
|
624
|
+
* const result = await repo.execute('MyCollection', 'aggregate', [
|
|
625
|
+
* {$lookup: {
|
|
626
|
+
* // ...
|
|
627
|
+
* }},
|
|
628
|
+
* {$unwind: '$data'},
|
|
629
|
+
* {$out: 'tempData'}
|
|
630
|
+
* ]);
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* @param collectionName The name of the collection to execute the command on.
|
|
634
|
+
* @param command The command name. See
|
|
635
|
+
* [Collection API docs](http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html)
|
|
636
|
+
* for the list of commands supported by the MongoDB client.
|
|
637
|
+
* @param parameters Command parameters (arguments), as described in MongoDB API
|
|
638
|
+
* docs for individual collection methods.
|
|
639
|
+
* @returns A promise which resolves to the command output as returned by the
|
|
640
|
+
* database driver.
|
|
641
|
+
*/
|
|
642
|
+
execute(
|
|
643
|
+
collectionName: string,
|
|
644
|
+
command: string,
|
|
645
|
+
...parameters: PositionalParameters
|
|
646
|
+
): Promise<AnyObject>;
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Execute a raw database command using a connector that's not described
|
|
650
|
+
* by LoopBack's `execute` API yet.
|
|
651
|
+
*
|
|
652
|
+
* **WARNING:** In general, it is always better to perform database actions
|
|
653
|
+
* through repository methods. Directly executing database commands may lead
|
|
654
|
+
* to unexpected results and other issues.
|
|
655
|
+
*
|
|
656
|
+
* @param args Command and parameters, please consult your connector's
|
|
657
|
+
* documentation to learn about supported commands and their parameters.
|
|
658
|
+
* @returns A promise which resolves to the command output as returned by the
|
|
659
|
+
* database driver.
|
|
660
|
+
*/
|
|
661
|
+
execute(...args: PositionalParameters): Promise<AnyObject>;
|
|
662
|
+
|
|
663
|
+
async execute(...args: PositionalParameters): Promise<AnyObject> {
|
|
664
|
+
return ensurePromise(this.dataSource.execute(...args));
|
|
582
665
|
}
|
|
583
666
|
|
|
584
667
|
protected toEntity<R extends T>(model: juggler.PersistedModel): R {
|
|
@@ -680,10 +763,11 @@ export class DefaultCrudRepository<
|
|
|
680
763
|
*/
|
|
681
764
|
|
|
682
765
|
export class DefaultTransactionalRepository<
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
>
|
|
766
|
+
T extends Entity,
|
|
767
|
+
ID,
|
|
768
|
+
Relations extends object = {}
|
|
769
|
+
>
|
|
770
|
+
extends DefaultCrudRepository<T, ID, Relations>
|
|
687
771
|
implements TransactionalEntityRepository<T, ID, Relations> {
|
|
688
772
|
async beginTransaction(
|
|
689
773
|
options?: IsolationLevel | Options,
|
|
@@ -138,7 +138,8 @@ export interface EntityCrudRepository<
|
|
|
138
138
|
T extends Entity,
|
|
139
139
|
ID,
|
|
140
140
|
Relations extends object = {}
|
|
141
|
-
> extends EntityRepository<T, ID>,
|
|
141
|
+
> extends EntityRepository<T, ID>,
|
|
142
|
+
CrudRepository<T, Relations> {
|
|
142
143
|
// entityClass should have type "typeof T", but that's not supported by TSC
|
|
143
144
|
entityClass: typeof Entity & {prototype: T};
|
|
144
145
|
inclusionResolvers: Map<string, InclusionResolver<T, Entity>>;
|