• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 21057550101

16 Jan 2026 06:13AM UTC coverage: 80.915% (+0.01%) from 80.901%
21057550101

push

github

web-flow
feat: support `INSERT INTO ... SELECT FROM ...` in QueryBuilder (#11896)

26971 of 32788 branches covered (82.26%)

Branch coverage included in aggregate %.

198 of 214 new or added lines in 2 files covered. (92.52%)

141 existing lines in 2 files now uncovered.

91946 of 114177 relevant lines covered (80.53%)

69579.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.48
/src/query-builder/QueryExpressionMap.ts
1
import { Alias } from "./Alias"
26 ✔
2
import { ObjectLiteral } from "../common/ObjectLiteral"
26 ✔
3
import { OrderByCondition } from "../find-options/OrderByCondition"
26 ✔
4
import { JoinAttribute } from "./JoinAttribute"
26 ✔
5
import { QueryBuilder } from "./QueryBuilder"
26 ✔
6
import { QueryBuilderCteOptions } from "./QueryBuilderCte"
26 ✔
7
import { RelationIdAttribute } from "./relation-id/RelationIdAttribute"
26 ✔
8
import { RelationCountAttribute } from "./relation-count/RelationCountAttribute"
26 ✔
9
import { DataSource } from "../data-source/DataSource"
26 ✔
10
import { EntityMetadata } from "../metadata/EntityMetadata"
26 ✔
11
import { SelectQuery } from "./SelectQuery"
26 ✔
12
import { ColumnMetadata } from "../metadata/ColumnMetadata"
26 ✔
13
import { RelationMetadata } from "../metadata/RelationMetadata"
26 ✔
14
import { SelectQueryBuilderOption } from "./SelectQueryBuilderOption"
26 ✔
15
import { TypeORMError } from "../error"
26 ✔
16
import { WhereClause } from "./WhereClause"
26 ✔
17
import { UpsertType } from "../driver/types/UpsertType"
26 ✔
18
import { CockroachConnectionOptions } from "../driver/cockroachdb/CockroachConnectionOptions"
26 ✔
19

26 ✔
20
/**
26 ✔
21
 * Contains all properties of the QueryBuilder that needs to be build a final query.
26 ✔
22
 */
26 ✔
23
export class QueryExpressionMap {
26 ✔
24
    // -------------------------------------------------------------------------
26 ✔
25
    // Public Properties
26 ✔
26
    // -------------------------------------------------------------------------
26 ✔
27

26 ✔
28
    /**
26 ✔
29
     * Strategy to load relations.
26 ✔
30
     */
26 ✔
31
    relationLoadStrategy: "join" | "query" = "join"
26 ✔
32

26 ✔
33
    /**
26 ✔
34
     * Indicates if QueryBuilder used to select entities and not a raw results.
26 ✔
35
     */
26 ✔
36
    queryEntity: boolean = false
26 ✔
37

26 ✔
38
    /**
26 ✔
39
     * Main alias is a main selection object selected by QueryBuilder.
26 ✔
40
     */
26 ✔
41
    mainAlias?: Alias
26 ✔
42

26 ✔
43
    /**
26 ✔
44
     * All aliases (including main alias) used in the query.
26 ✔
45
     */
26 ✔
46
    aliases: Alias[] = []
26 ✔
47

26 ✔
48
    /**
26 ✔
49
     * Represents query type. QueryBuilder is able to build SELECT, UPDATE and DELETE queries.
26 ✔
50
     */
26 ✔
51
    queryType:
26 ✔
52
        | "select"
26 ✔
53
        | "update"
26 ✔
54
        | "delete"
26 ✔
55
        | "insert"
26 ✔
56
        | "relation"
26 ✔
57
        | "soft-delete"
26 ✔
58
        | "restore" = "select"
26 ✔
59

26 ✔
60
    /**
26 ✔
61
     * Data needs to be SELECT-ed.
26 ✔
62
     */
26 ✔
63
    selects: SelectQuery[] = []
26 ✔
64

26 ✔
65
    /**
26 ✔
66
     * Max execution time in millisecond.
26 ✔
67
     */
26 ✔
68
    maxExecutionTime: number = 0
26 ✔
69

26 ✔
70
    /**
26 ✔
71
     * Whether SELECT is DISTINCT.
26 ✔
72
     */
26 ✔
73
    selectDistinct: boolean = false
26 ✔
74

26 ✔
75
    /**
26 ✔
76
     * SELECT DISTINCT ON query (postgres).
26 ✔
77
     */
26 ✔
78
    selectDistinctOn: string[] = []
26 ✔
79

26 ✔
80
    /**
26 ✔
81
     * FROM-s to be selected.
26 ✔
82
     */
26 ✔
83
    // froms: { target: string, alias: string }[] = [];
26 ✔
84

26 ✔
85
    /**
26 ✔
86
     * If update query was used, it needs "update set" - properties which will be updated by this query.
26 ✔
87
     * If insert query was used, it needs "insert set" - values that needs to be inserted.
26 ✔
88
     */
26 ✔
89
    valuesSet?: ObjectLiteral | ObjectLiteral[]
26 ✔
90

26 ✔
91
    /**
26 ✔
92
     * Optional returning (or output) clause for insert, update or delete queries.
26 ✔
93
     */
26 ✔
94
    returning: string | string[]
26 ✔
95

26 ✔
96
    /**
26 ✔
97
     * Extra returning columns to be added to the returning statement if driver supports it.
26 ✔
98
     */
26 ✔
99
    extraReturningColumns: ColumnMetadata[] = []
26 ✔
100

26 ✔
101
    /**
26 ✔
102
     * Optional on conflict statement used in insertion query in postgres.
26 ✔
103
     */
26 ✔
104
    onConflict: string = ""
26 ✔
105

26 ✔
106
    /**
26 ✔
107
     * Optional on ignore statement used in insertion query in databases.
26 ✔
108
     */
26 ✔
109
    onIgnore: boolean = false
26 ✔
110

26 ✔
111
    /**
26 ✔
112
     * Optional on update statement used in insertion query in databases.
26 ✔
113
     */
26 ✔
114
    onUpdate: {
26 ✔
115
        conflict?: string | string[]
26 ✔
116
        columns?: string[]
26 ✔
117
        overwrite?: string[]
26 ✔
118
        skipUpdateIfNoValuesChanged?: boolean
26 ✔
119
        indexPredicate?: string
26 ✔
120
        upsertType?: UpsertType
26 ✔
121
        overwriteCondition?: WhereClause[]
26 ✔
122
    }
26 ✔
123

26 ✔
124
    /**
26 ✔
125
     * JOIN queries.
26 ✔
126
     */
26 ✔
127
    joinAttributes: JoinAttribute[] = []
26 ✔
128

26 ✔
129
    /**
26 ✔
130
     * RelationId queries.
26 ✔
131
     */
26 ✔
132
    relationIdAttributes: RelationIdAttribute[] = []
26 ✔
133

26 ✔
134
    /**
26 ✔
135
     * Relation count queries.
26 ✔
136
     */
26 ✔
137
    relationCountAttributes: RelationCountAttribute[] = []
26 ✔
138

26 ✔
139
    /**
26 ✔
140
     * WHERE queries.
26 ✔
141
     */
26 ✔
142
    wheres: WhereClause[] = []
26 ✔
143

26 ✔
144
    /**
26 ✔
145
     * HAVING queries.
26 ✔
146
     */
26 ✔
147
    havings: { type: "simple" | "and" | "or"; condition: string }[] = []
26 ✔
148

26 ✔
149
    /**
26 ✔
150
     * ORDER BY queries.
26 ✔
151
     */
26 ✔
152
    orderBys: OrderByCondition = {}
26 ✔
153

26 ✔
154
    /**
26 ✔
155
     * GROUP BY queries.
26 ✔
156
     */
26 ✔
157
    groupBys: string[] = []
26 ✔
158

26 ✔
159
    /**
26 ✔
160
     * LIMIT query.
26 ✔
161
     */
26 ✔
162
    limit?: number
26 ✔
163

26 ✔
164
    /**
26 ✔
165
     * OFFSET query.
26 ✔
166
     */
26 ✔
167
    offset?: number
26 ✔
168

26 ✔
169
    /**
26 ✔
170
     * Number of rows to skip of result using pagination.
26 ✔
171
     */
26 ✔
172
    skip?: number
26 ✔
173

26 ✔
174
    /**
26 ✔
175
     * Number of rows to take using pagination.
26 ✔
176
     */
26 ✔
177
    take?: number
26 ✔
178

26 ✔
179
    /**
26 ✔
180
     * Use certain index for the query.
26 ✔
181
     *
26 ✔
182
     * SELECT * FROM table_name USE INDEX (col1_index, col2_index) WHERE col1=1 AND col2=2 AND col3=3;
26 ✔
183
     */
26 ✔
184
    useIndex?: string
26 ✔
185

26 ✔
186
    /**
26 ✔
187
     * Locking mode.
26 ✔
188
     */
26 ✔
189
    lockMode?:
26 ✔
190
        | "optimistic"
26 ✔
191
        | "pessimistic_read"
26 ✔
192
        | "pessimistic_write"
26 ✔
193
        | "dirty_read"
26 ✔
194
        /*
26 ✔
195
            "pessimistic_partial_write" and "pessimistic_write_or_fail" are deprecated and
26 ✔
196
            will be removed in a future version.
26 ✔
197

26 ✔
198
            Use onLocked instead.
26 ✔
199
         */
26 ✔
200
        | "pessimistic_partial_write"
26 ✔
201
        | "pessimistic_write_or_fail"
26 ✔
202
        | "for_no_key_update"
26 ✔
203
        | "for_key_share"
26 ✔
204

26 ✔
205
    /**
26 ✔
206
     * Current version of the entity, used for locking.
26 ✔
207
     */
26 ✔
208
    lockVersion?: number | Date
26 ✔
209

26 ✔
210
    /**
26 ✔
211
     * Tables to be specified in the "FOR UPDATE OF" clause, referred by their alias
26 ✔
212
     */
26 ✔
213
    lockTables?: string[]
26 ✔
214

26 ✔
215
    /**
26 ✔
216
     * Modify behavior when encountering locked rows. NOWAIT or SKIP LOCKED
26 ✔
217
     */
26 ✔
218
    onLocked?: "nowait" | "skip_locked"
26 ✔
219

26 ✔
220
    /**
26 ✔
221
     * Indicates if soft-deleted rows should be included in entity result.
26 ✔
222
     * By default the soft-deleted rows are not included.
26 ✔
223
     */
26 ✔
224
    withDeleted: boolean = false
26 ✔
225

26 ✔
226
    /**
26 ✔
227
     * Parameters used to be escaped in final query.
26 ✔
228
     */
26 ✔
229
    parameters: ObjectLiteral = {}
26 ✔
230

26 ✔
231
    /**
26 ✔
232
     * Indicates if alias, table names and column names will be escaped by driver, or not.
26 ✔
233
     *
26 ✔
234
     * todo: rename to isQuotingDisabled, also think if it should be named "escaping"
26 ✔
235
     */
26 ✔
236
    disableEscaping: boolean = true
26 ✔
237

26 ✔
238
    /**
26 ✔
239
     * Indicates if virtual columns should be included in entity result.
26 ✔
240
     *
26 ✔
241
     * todo: what to do with it? is it properly used? what about persistence?
26 ✔
242
     */
26 ✔
243
    enableRelationIdValues: boolean = false
26 ✔
244

26 ✔
245
    /**
26 ✔
246
     * Extra where condition appended to the end of original where conditions with AND keyword.
26 ✔
247
     * Original condition will be wrapped into brackets.
26 ✔
248
     */
26 ✔
249
    extraAppendedAndWhereCondition: string = ""
26 ✔
250

26 ✔
251
    /**
26 ✔
252
     * Indicates if query builder creates a subquery.
26 ✔
253
     */
26 ✔
254
    subQuery: boolean = false
26 ✔
255

26 ✔
256
    /**
26 ✔
257
     * Indicates if property names are prefixed with alias names during property replacement.
26 ✔
258
     * By default this is enabled, however we need this because aliases are not supported in UPDATE and DELETE queries,
26 ✔
259
     * but user can use them in WHERE expressions.
26 ✔
260
     */
26 ✔
261
    aliasNamePrefixingEnabled: boolean = true
26 ✔
262

26 ✔
263
    /**
26 ✔
264
     * Indicates if query result cache is enabled or not.
26 ✔
265
     * It is undefined by default to avoid overriding the `alwaysEnabled` config
26 ✔
266
     */
26 ✔
267
    cache?: boolean
26 ✔
268

26 ✔
269
    /**
26 ✔
270
     * Time in milliseconds in which cache will expire.
26 ✔
271
     * If not set then global caching time will be used.
26 ✔
272
     */
26 ✔
273
    cacheDuration: number
26 ✔
274

26 ✔
275
    /**
26 ✔
276
     * Cache id.
26 ✔
277
     * Used to identifier your cache queries.
26 ✔
278
     */
26 ✔
279
    cacheId: string
26 ✔
280

26 ✔
281
    /**
26 ✔
282
     * Options that define QueryBuilder behaviour.
26 ✔
283
     */
26 ✔
284
    options: SelectQueryBuilderOption[] = []
26 ✔
285

26 ✔
286
    /**
26 ✔
287
     * Property path of relation to work with.
26 ✔
288
     * Used in relational query builder.
26 ✔
289
     */
26 ✔
290
    relationPropertyPath: string
26 ✔
291

26 ✔
292
    /**
26 ✔
293
     * Entity (target) which relations will be updated.
26 ✔
294
     */
26 ✔
295
    of: any | any[]
26 ✔
296

26 ✔
297
    /**
26 ✔
298
     * List of columns where data should be inserted.
26 ✔
299
     * Used in INSERT query.
26 ✔
300
     */
26 ✔
301
    insertColumns: string[] = []
26 ✔
302

26 ✔
303
    /**
26 ✔
304
     * SelectQueryBuilder to use for INSERT INTO ... SELECT FROM.
26 ✔
305
     * When set, the insert will use a SELECT query as the source of values.
26 ✔
306
     */
26 ✔
307
    insertFromSelect?: QueryBuilder<any>
26 ✔
308

26 ✔
309
    /**
26 ✔
310
     * Used if user wants to update or delete a specific entities.
26 ✔
311
     */
26 ✔
312
    whereEntities: ObjectLiteral[] = []
26 ✔
313

26 ✔
314
    /**
26 ✔
315
     * Indicates if entity must be updated after insertion / updation.
26 ✔
316
     * This may produce extra query or use RETURNING / OUTPUT statement (depend on database).
26 ✔
317
     */
26 ✔
318
    updateEntity: boolean = true
26 ✔
319

26 ✔
320
    /**
26 ✔
321
     * Indicates if listeners and subscribers must be called before and after query execution.
26 ✔
322
     */
26 ✔
323
    callListeners: boolean = true
26 ✔
324

26 ✔
325
    /**
26 ✔
326
     * Indicates if query must be wrapped into transaction.
26 ✔
327
     */
26 ✔
328
    useTransaction: boolean = false
26 ✔
329

26 ✔
330
    /**
26 ✔
331
     * Indicates if query should be time travel query
26 ✔
332
     * https://www.cockroachlabs.com/docs/stable/as-of-system-time.html
26 ✔
333
     */
26 ✔
334
    timeTravel?: boolean | string
26 ✔
335

26 ✔
336
    /**
26 ✔
337
     * Extra parameters.
26 ✔
338
     *
26 ✔
339
     * @deprecated Use standard parameters instead
26 ✔
340
     */
26 ✔
341
    nativeParameters: ObjectLiteral = {}
26 ✔
342

26 ✔
343
    /**
26 ✔
344
     * Query Comment to include extra information for debugging or other purposes.
26 ✔
345
     */
26 ✔
346
    comment?: string
26 ✔
347

26 ✔
348
    /**
26 ✔
349
     * Items from an entity that have been locally generated & are recorded here for later use.
26 ✔
350
     * Examples include the UUID generation when the database does not natively support it.
26 ✔
351
     * These are included in the entity index order.
26 ✔
352
     */
26 ✔
353
    locallyGenerated: { [key: number]: ObjectLiteral } = {}
26 ✔
354

26 ✔
355
    commonTableExpressions: {
26 ✔
356
        queryBuilder: QueryBuilder<any> | string
26 ✔
357
        alias: string
26 ✔
358
        options: QueryBuilderCteOptions
26 ✔
359
    }[] = []
26 ✔
360

26 ✔
361
    // -------------------------------------------------------------------------
26 ✔
362
    // Constructor
26 ✔
363
    // -------------------------------------------------------------------------
26 ✔
364

26 ✔
365
    constructor(protected connection: DataSource) {
26 ✔
366
        if (connection.options.relationLoadStrategy) {
889,737 ✔
367
            this.relationLoadStrategy = connection.options.relationLoadStrategy
91,780 ✔
368
        }
91,780 ✔
369

889,737 ✔
370
        this.timeTravel =
889,737 ✔
371
            (connection.options as CockroachConnectionOptions)
889,737 ✔
372
                ?.timeTravelQueries || false
889,737 ✔
373
    }
889,737 ✔
374

26 ✔
375
    // -------------------------------------------------------------------------
26 ✔
376
    // Accessors
26 ✔
377
    // -------------------------------------------------------------------------
26 ✔
378

26 ✔
379
    /**
26 ✔
380
     * Get all ORDER BY queries - if order by is specified by user then it uses them,
26 ✔
381
     * otherwise it uses default entity order by if it was set.
26 ✔
382
     */
26 ✔
383
    get allOrderBys() {
26 ✔
384
        if (
306,131 ✔
385
            !Object.keys(this.orderBys).length &&
306,131 ✔
386
            this.mainAlias!.hasMetadata &&
306,131 ✔
387
            this.options.indexOf("disable-global-order") === -1
277,685 ✔
388
        ) {
306,131 ✔
389
            const entityOrderBy = this.mainAlias!.metadata.orderBy || {}
276,473 ✔
390
            return Object.keys(entityOrderBy).reduce((orderBy, key) => {
276,473 ✔
391
                orderBy[this.mainAlias!.name + "." + key] = entityOrderBy[key]
224 ✔
392
                return orderBy
224 ✔
393
            }, {} as OrderByCondition)
276,473 ✔
394
        }
276,473 ✔
395

29,658 ✔
396
        return this.orderBys
29,658 ✔
397
    }
29,658 ✔
398

26 ✔
399
    // -------------------------------------------------------------------------
26 ✔
400
    // Public Methods
26 ✔
401
    // -------------------------------------------------------------------------
26 ✔
402

26 ✔
403
    /**
26 ✔
404
     * Creates a main alias and adds it to the current expression map.
26 ✔
405
     */
26 ✔
406
    setMainAlias(alias: Alias): Alias {
26 ✔
407
        // if main alias is already set then remove it from the array
562,320 ✔
408
        // if (this.mainAlias)
562,320 ✔
409
        //     this.aliases.splice(this.aliases.indexOf(this.mainAlias));
562,320 ✔
410

562,320 ✔
411
        // set new main alias
562,320 ✔
412
        this.mainAlias = alias
562,320 ✔
413

562,320 ✔
414
        return alias
562,320 ✔
415
    }
562,320 ✔
416

26 ✔
417
    /**
26 ✔
418
     * Creates a new alias and adds it to the current expression map.
26 ✔
419
     */
26 ✔
420
    createAlias(options: {
26 ✔
421
        type: "from" | "select" | "join" | "other"
1,543,747 ✔
422
        name?: string
1,543,747 ✔
423
        target?: Function | string
1,543,747 ✔
424
        tablePath?: string
1,543,747 ✔
425
        subQuery?: string
1,543,747 ✔
426
        metadata?: EntityMetadata
1,543,747 ✔
427
    }): Alias {
1,543,747 ✔
428
        let aliasName = options.name
1,543,747 ✔
429
        if (!aliasName && options.tablePath) aliasName = options.tablePath
1,543,747 ✔
430
        if (!aliasName && typeof options.target === "function")
1,543,747 !
431
            aliasName = options.target.name
1,543,747 !
432
        if (!aliasName && typeof options.target === "string")
1,543,747 !
433
            aliasName = options.target
1,543,747 !
434

1,543,747 ✔
435
        const alias = new Alias()
1,543,747 ✔
436
        alias.type = options.type
1,543,747 ✔
437
        if (aliasName) alias.name = aliasName
1,543,747 ✔
438
        if (options.metadata) alias.metadata = options.metadata
1,543,747 ✔
439
        if (options.target && !alias.hasMetadata)
1,543,747 !
440
            alias.metadata = this.connection.getMetadata(options.target)
1,543,747 !
441
        if (options.tablePath) alias.tablePath = options.tablePath
1,543,747 ✔
442
        if (options.subQuery) alias.subQuery = options.subQuery
1,543,747 ✔
443

1,543,747 ✔
444
        this.aliases.push(alias)
1,543,747 ✔
445
        return alias
1,543,747 ✔
446
    }
1,543,747 ✔
447

26 ✔
448
    /**
26 ✔
449
     * Finds alias with the given name.
26 ✔
450
     * If alias was not found it throw an exception.
26 ✔
451
     */
26 ✔
452
    findAliasByName(aliasName: string): Alias {
26 ✔
453
        const alias = this.aliases.find((alias) => alias.name === aliasName)
1,380,483 ✔
454
        if (!alias)
1,380,483 ✔
455
            throw new TypeORMError(
1,380,483 !
UNCOV
456
                `"${aliasName}" alias was not found. Maybe you forgot to join it?`,
×
457
            )
×
458

1,380,483 ✔
459
        return alias
1,380,483 ✔
460
    }
1,380,483 ✔
461

26 ✔
462
    findColumnByAliasExpression(
26 ✔
UNCOV
463
        aliasExpression: string,
×
UNCOV
464
    ): ColumnMetadata | undefined {
×
UNCOV
465
        const [aliasName, propertyPath] = aliasExpression.split(".")
×
UNCOV
466
        const alias = this.findAliasByName(aliasName)
×
UNCOV
467
        return alias.metadata.findColumnWithPropertyName(propertyPath)
×
UNCOV
468
    }
×
469

26 ✔
470
    /**
26 ✔
471
     * Gets relation metadata of the relation this query builder works with.
26 ✔
472
     *
26 ✔
473
     * todo: add proper exceptions
26 ✔
474
     */
26 ✔
475
    get relationMetadata(): RelationMetadata {
26 ✔
476
        if (!this.mainAlias)
3,540 ✔
477
            throw new TypeORMError(`Entity to work with is not specified!`) // todo: better message
3,540 !
478

3,540 ✔
479
        const relationMetadata =
3,540 ✔
480
            this.mainAlias.metadata.findRelationWithPropertyPath(
3,540 ✔
481
                this.relationPropertyPath,
3,540 ✔
482
            )
3,540 ✔
483
        if (!relationMetadata)
3,540 ✔
484
            throw new TypeORMError(
3,540 !
UNCOV
485
                `Relation ${this.relationPropertyPath} was not found in entity ${this.mainAlias.name}`,
×
486
            ) // todo: better message
3,540 ✔
487

3,540 ✔
488
        return relationMetadata
3,540 ✔
489
    }
3,540 ✔
490

26 ✔
491
    /**
26 ✔
492
     * Copies all properties of the current QueryExpressionMap into a new one.
26 ✔
493
     * Useful when QueryBuilder needs to create a copy of itself.
26 ✔
494
     */
26 ✔
495
    clone(): QueryExpressionMap {
26 ✔
496
        const map = new QueryExpressionMap(this.connection)
287,875 ✔
497
        map.queryType = this.queryType
287,875 ✔
498
        map.selects = this.selects.map((select) => select)
287,875 ✔
499
        map.maxExecutionTime = this.maxExecutionTime
287,875 ✔
500
        map.selectDistinct = this.selectDistinct
287,875 ✔
501
        map.selectDistinctOn = this.selectDistinctOn
287,875 ✔
502
        this.aliases.forEach((alias) => map.aliases.push(new Alias(alias)))
287,875 ✔
503
        map.relationLoadStrategy = this.relationLoadStrategy
287,875 ✔
504
        map.mainAlias = this.mainAlias
287,875 ✔
505
        map.valuesSet = this.valuesSet
287,875 ✔
506
        map.returning = this.returning
287,875 ✔
507
        map.onConflict = this.onConflict
287,875 ✔
508
        map.onIgnore = this.onIgnore
287,875 ✔
509
        map.onUpdate = this.onUpdate
287,875 ✔
510
        map.joinAttributes = this.joinAttributes.map(
287,875 ✔
511
            (join) => new JoinAttribute(this.connection, this, join),
287,875 ✔
512
        )
287,875 ✔
513
        map.relationIdAttributes = this.relationIdAttributes.map(
287,875 ✔
514
            (relationId) => new RelationIdAttribute(this, relationId),
287,875 ✔
515
        )
287,875 ✔
516
        map.relationCountAttributes = this.relationCountAttributes.map(
287,875 ✔
517
            (relationCount) => new RelationCountAttribute(this, relationCount),
287,875 ✔
518
        )
287,875 ✔
519
        map.wheres = this.wheres.map((where) => ({ ...where }))
287,875 ✔
520
        map.havings = this.havings.map((having) => ({ ...having }))
287,875 ✔
521
        map.orderBys = Object.assign({}, this.orderBys)
287,875 ✔
522
        map.groupBys = this.groupBys.map((groupBy) => groupBy)
287,875 ✔
523
        map.limit = this.limit
287,875 ✔
524
        map.offset = this.offset
287,875 ✔
525
        map.skip = this.skip
287,875 ✔
526
        map.take = this.take
287,875 ✔
527
        map.useIndex = this.useIndex
287,875 ✔
528
        map.lockMode = this.lockMode
287,875 ✔
529
        map.onLocked = this.onLocked
287,875 ✔
530
        map.lockVersion = this.lockVersion
287,875 ✔
531
        map.lockTables = this.lockTables
287,875 ✔
532
        map.withDeleted = this.withDeleted
287,875 ✔
533
        map.parameters = Object.assign({}, this.parameters)
287,875 ✔
534
        map.disableEscaping = this.disableEscaping
287,875 ✔
535
        map.enableRelationIdValues = this.enableRelationIdValues
287,875 ✔
536
        map.extraAppendedAndWhereCondition = this.extraAppendedAndWhereCondition
287,875 ✔
537
        map.subQuery = this.subQuery
287,875 ✔
538
        map.aliasNamePrefixingEnabled = this.aliasNamePrefixingEnabled
287,875 ✔
539
        map.cache = this.cache
287,875 ✔
540
        map.cacheId = this.cacheId
287,875 ✔
541
        map.cacheDuration = this.cacheDuration
287,875 ✔
542
        map.relationPropertyPath = this.relationPropertyPath
287,875 ✔
543
        map.of = this.of
287,875 ✔
544
        map.insertColumns = this.insertColumns
287,875 ✔
545
        map.insertFromSelect = this.insertFromSelect
287,875 ✔
546
            ? this.insertFromSelect.clone()
287,875 !
547
            : undefined
287,875 ✔
548
        map.whereEntities = this.whereEntities
287,875 ✔
549
        map.updateEntity = this.updateEntity
287,875 ✔
550
        map.callListeners = this.callListeners
287,875 ✔
551
        map.useTransaction = this.useTransaction
287,875 ✔
552
        map.timeTravel = this.timeTravel
287,875 ✔
553
        map.nativeParameters = Object.assign({}, this.nativeParameters)
287,875 ✔
554
        map.comment = this.comment
287,875 ✔
555
        map.commonTableExpressions = this.commonTableExpressions.map(
287,875 ✔
556
            (cteOptions) => ({
287,875 ✔
UNCOV
557
                alias: cteOptions.alias,
×
UNCOV
558
                queryBuilder:
×
UNCOV
559
                    typeof cteOptions.queryBuilder === "string"
×
UNCOV
560
                        ? cteOptions.queryBuilder
×
UNCOV
561
                        : cteOptions.queryBuilder.clone(),
×
UNCOV
562
                options: cteOptions.options,
×
563
            }),
287,875 ✔
564
        )
287,875 ✔
565
        return map
287,875 ✔
566
    }
287,875 ✔
567
}
26 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc