* invocationCallOrder of the first `tx.execute(...)` whose SQL contains * `substring` — checks the template strings, the interpolated values (the * advisory key is passed as a value), and `sql.raw` output.
(substring: string)
| 52 | * advisory key is passed as a value), and `sql.raw` output. |
| 53 | */ |
| 54 | function executeOrderContaining(substring: string): number { |
| 55 | const { calls, invocationCallOrder } = dbChainMockFns.execute.mock |
| 56 | for (let i = 0; i < calls.length; i++) { |
| 57 | const arg = calls[i][0] as { strings?: unknown; values?: unknown; rawSql?: unknown } | undefined |
| 58 | const haystacks: string[] = [] |
| 59 | if (Array.isArray(arg?.strings)) { |
| 60 | haystacks.push( |
| 61 | ...(arg.strings as unknown[]).filter((s): s is string => typeof s === 'string') |
| 62 | ) |
| 63 | } |
| 64 | if (Array.isArray(arg?.values)) { |
| 65 | haystacks.push(...(arg.values as unknown[]).filter((v): v is string => typeof v === 'string')) |
| 66 | } |
| 67 | if (typeof arg?.rawSql === 'string') haystacks.push(arg.rawSql) |
| 68 | if (haystacks.some((s) => s.includes(substring))) return invocationCallOrder[i] |
| 69 | } |
| 70 | return -1 |
| 71 | } |
| 72 | |
| 73 | /** invocationCallOrder of the first `tx.update(table)` call. */ |
| 74 | function updateOrderForTable(table: unknown): number { |