| 57 | } |
| 58 | |
| 59 | export class PivotCollectionPersister<Entity extends object> { |
| 60 | readonly #inserts = new Map<string, InsertStatement<Entity>>(); |
| 61 | readonly #upserts = new Map<string, InsertStatement<Entity>>(); |
| 62 | readonly #deletes = new Map<string, DeleteStatement<Entity>>(); |
| 63 | readonly #batchSize: number; |
| 64 | #order = 0; |
| 65 | readonly #meta: EntityMetadata<Entity>; |
| 66 | readonly #driver: AbstractSqlDriver; |
| 67 | readonly #ctx?: Transaction; |
| 68 | readonly #schema?: string; |
| 69 | readonly #loggerContext?: Dictionary; |
| 70 | readonly #abort?: AbortQueryOptions; |
| 71 | |
| 72 | constructor( |
| 73 | meta: EntityMetadata<Entity>, |
| 74 | driver: AbstractSqlDriver, |
| 75 | ctx?: Transaction, |
| 76 | schema?: string, |
| 77 | loggerContext?: Dictionary, |
| 78 | abort?: AbortQueryOptions, |
| 79 | ) { |
| 80 | this.#meta = meta; |
| 81 | this.#driver = driver; |
| 82 | this.#ctx = ctx; |
| 83 | this.#schema = schema; |
| 84 | this.#loggerContext = loggerContext; |
| 85 | this.#abort = abort; |
| 86 | this.#batchSize = this.#driver.config.get('batchSize'); |
| 87 | } |
| 88 | |
| 89 | enqueueUpdate( |
| 90 | prop: EntityProperty<Entity>, |
| 91 | insertDiff: Primary<Entity>[][], |
| 92 | deleteDiff: Primary<Entity>[][] | boolean, |
| 93 | pks: Primary<Entity>[], |
| 94 | isInitialized = true, |
| 95 | ) { |
| 96 | if (insertDiff.length) { |
| 97 | if (isInitialized) { |
| 98 | this.enqueueInsert(prop, insertDiff, pks); |
| 99 | } else { |
| 100 | this.enqueueUpsert(prop, insertDiff, pks); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if (deleteDiff === true || (Array.isArray(deleteDiff) && deleteDiff.length)) { |
| 105 | this.enqueueDelete(prop, deleteDiff, pks); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | private enqueueInsert(prop: EntityProperty<Entity>, insertDiff: Primary<Entity>[][], pks: Primary<Entity>[]) { |
| 110 | for (const fks of insertDiff) { |
| 111 | const statement = this.createInsertStatement(prop, fks, pks); |
| 112 | const hash = statement.getHash(); |
| 113 | |
| 114 | if (prop.owner || !this.#inserts.has(hash)) { |
| 115 | this.#inserts.set(hash, statement); |
| 116 | } |
nothing calls this directly
no outgoing calls
no test coverage detected