| 1 | import type * as Effect from "effect/Effect" |
| 2 | import type * as Scope from "effect/Scope" |
| 3 | import type { SqlError } from "effect/sql/SqlError" |
| 4 | |
| 5 | /** @internal */ |
| 6 | export const internalsKey = "~@effect/sql-pg/PgConnection/internals" as const |
| 7 | |
| 8 | /** @internal */ |
| 9 | export interface ConnectionInternals { |
| 10 | /** The pool item identity: the unpinned base connection. */ |
| 11 | readonly base: object |
| 12 | readonly deadError: () => SqlError | undefined |
| 13 | /** Fired when a pool must stop reusing the connection. */ |
| 14 | readonly retireHooks: Set<() => void> |
| 15 | /** |
| 16 | * Installed by a multiplexed pool so that pinning the session also takes it |
| 17 | * out of shared circulation for as long as the pin lasts. Every route to an |
| 18 | * exclusive session goes through `pin`, including `stream` and `listen`, so |
| 19 | * this is the one place that covers them all. |
| 20 | */ |
| 21 | reserve?: Effect.Effect<void, never, Scope.Scope> | undefined |
| 22 | } |
| 23 | |
| 24 | /** @internal */ |
| 25 | export const connectionInternals = (connection: object): ConnectionInternals => |
| 26 | (connection as Record<typeof internalsKey, ConnectionInternals>)[internalsKey] |