( statements: ReadonlyArray<Statement<unknown>>, acquirer: Acquirer, borrower: Borrower | undefined, spanAttributes: ReadonlyArray<readonly [string, unknown]> )
| 1697 | * @internal |
| 1698 | */ |
| 1699 | export const executeBatch = ( |
| 1700 | statements: ReadonlyArray<Statement<unknown>>, |
| 1701 | acquirer: Acquirer, |
| 1702 | borrower: Borrower | undefined, |
| 1703 | spanAttributes: ReadonlyArray<readonly [string, unknown]> |
| 1704 | ): Effect.Effect<any, SqlError> => { |
| 1705 | if (statements.length === 0) return Effect.succeed([]) |
| 1706 | // OpenTelemetry names multi-statement batches `BATCH <target>`. |
| 1707 | const isBatch = statements.length > 1 |
| 1708 | const target = spanTarget(spanAttributes) |
| 1709 | const name = !isBatch ? spanName(spanAttributes) : target === undefined ? "BATCH" : `BATCH ${target}` |
| 1710 | return Effect.useSpan(name, { kind: "client" }, (span) => |
| 1711 | Effect.withFiber((fiber) => { |
| 1712 | const transform = fiber.getRef(CurrentTransformer) |
| 1713 | const impls = statements as ReadonlyArray<StatementImpl<unknown>> |
| 1714 | const resolved = transform === undefined |
| 1715 | ? Effect.succeed(impls) |
| 1716 | : Effect.forEach(impls, (statement) => applyTransformer(statement, transform, fiber, span)) |
| 1717 | return Effect.flatMap(resolved, (statements) => { |
| 1718 | const compiled = statements.map((statement) => statement.compile()) |
| 1719 | for (const [key, value] of spanAttributes) { |
| 1720 | span.attribute(key, value) |
| 1721 | } |
| 1722 | span.attribute(ATTR_SQL_METHOD, "executeBatch") |
| 1723 | if (isBatch) { |
| 1724 | span.attribute(ATTR_DB_OPERATION_NAME, "BATCH") |
| 1725 | span.attribute(ATTR_DB_OPERATION_BATCH_SIZE, statements.length) |
| 1726 | } |
| 1727 | span.attribute(ATTR_DB_QUERY_TEXT, compiled.map(([sql]) => sql).join("; ")) |
| 1728 | return runOnConnection(fiber, span, acquirer, borrower, (connection) => |
| 1729 | connection.executeBatch === undefined |
| 1730 | ? Effect.forEach( |
| 1731 | compiled, |
| 1732 | ([sql, params], index) => connection.execute(sql, params, statements[index].transformRows) |
| 1733 | ) |
| 1734 | : Effect.map(connection.executeBatch(compiled), (results) => |
| 1735 | results.map((rows, index) => { |
| 1736 | const transformRows = statements[index].transformRows |
| 1737 | return transformRows === undefined ? rows : transformRows(rows) |
| 1738 | }))) |
| 1739 | }) |
| 1740 | })) |
| 1741 | } |
| 1742 | |
| 1743 | const isSegment = (u: unknown): u is Segment => hasProperty(u, SegmentTypeId) |
| 1744 |
nothing calls this directly
no test coverage detected