| 654 | } |
| 655 | |
| 656 | protected createReplicas(cb: (c: ConnectionOptions) => C): C[] { |
| 657 | const replicas = this.config.get('replicas', []) as ConnectionOptions[]; |
| 658 | const ret: C[] = []; |
| 659 | const props = [ |
| 660 | 'dbName', |
| 661 | 'clientUrl', |
| 662 | 'host', |
| 663 | 'port', |
| 664 | 'user', |
| 665 | 'password', |
| 666 | 'multipleStatements', |
| 667 | 'pool', |
| 668 | 'name', |
| 669 | 'driverOptions', |
| 670 | ] as const; |
| 671 | |
| 672 | for (const conf of replicas) { |
| 673 | const replicaConfig = Utils.copy(conf) as Dictionary; |
| 674 | |
| 675 | for (const prop of props) { |
| 676 | if (conf[prop]) { |
| 677 | continue; |
| 678 | } |
| 679 | |
| 680 | // do not copy options that can be inferred from explicitly provided `clientUrl` |
| 681 | if (conf.clientUrl && ['clientUrl', 'host', 'port', 'user', 'password'].includes(prop)) { |
| 682 | continue; |
| 683 | } |
| 684 | |
| 685 | if (conf.clientUrl && prop === 'dbName' && new URL(conf.clientUrl).pathname) { |
| 686 | continue; |
| 687 | } |
| 688 | |
| 689 | replicaConfig[prop] = this.config.get(prop); |
| 690 | } |
| 691 | |
| 692 | ret.push(cb(replicaConfig as ConnectionOptions)); |
| 693 | } |
| 694 | |
| 695 | return ret; |
| 696 | } |
| 697 | |
| 698 | /** Acquires a pessimistic lock on the given entity. */ |
| 699 | async lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void> { |