MCPcopy Create free account
hub / github.com/Effect-TS/effect / PgConnectionImpl

Class PgConnectionImpl

packages/sql/pg/src/PgConnection.ts:513–1031  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

511const streamPauseThreshold = 512
512
513class PgConnectionImpl implements PgConnection {
514 readonly [TypeId]: TypeId = TypeId
515 readonly config: Config
516 readonly processId: number
517 readonly session: Session
518 /** The custom codec registry, or `undefined` for the builtin catalogue. */
519 readonly registry: PgTypes.Registry | undefined
520 readonly bindEncoder: BindEncoder
521 /** The statements this session has named, or `undefined` when disabled. */
522 readonly prepared: PreparedCache | undefined
523 readonly resolved: ResolvedConfig
524 readonly multiplex: boolean
525 /** Serializes statements: one in-flight extended-query cycle. */
526 readonly wire = Semaphore.makeUnsafe(1)
527 /** Exclusive-ownership queue used by `pin` and unpinned statements. */
528 readonly owner = Semaphore.makeUnsafe(1)
529 pinned = false
530 consumer: Consumer | undefined
531 deadWith: SqlError | undefined
532 closed = false
533 cancelPending = false
534 /** Reported by the latest `ReadyForQuery`. */
535 transactionStatus: PgProtocol.TransactionStatus = "I"
536 readonly channels = new Map<string, Set<Queue.Queue<Notification, SqlError>>>()
537 readonly retireHooks = new Set<() => void>()
538 /** Queued but not yet written; drained into `pipelineInFlight` on flush. */
539 readonly pipelinePending: Array<PipelineEntry> = []
540 /** Written and awaiting their `ReadyForQuery`, oldest first. */
541 readonly pipelineInFlight: Array<PipelineEntry> = []
542 pipelineHead = 0
543 pipelineFlushScheduled = false
544 readonly pipelineIdleWaiters = new Set<() => void>()
545 readonly [internalsKey]: ConnectionInternals
546
547 constructor(config: Config, resolved: ResolvedConfig, session: Session, registry: PgTypes.Registry | undefined) {
548 this.config = config
549 this.resolved = resolved
550 this.session = session
551 this.processId = session.processId
552 this.registry = registry
553 this.bindEncoder = makeBindEncoder(registry)
554 this.prepared = preparedCacheFor(config)
555 this.multiplex = config.multiplex ?? false
556 this[internalsKey] = {
557 base: this,
558 deadError: () => this.deadWith,
559 retireHooks: this.retireHooks,
560 onTransportClose: (f) => {
561 if (session.socket.closed) f()
562 else session.socket.once("close", f)
563 }
564 }
565 session.parser.onFieldError = this.onFieldError
566 session.socket.on("data", this.onData)
567 session.socket.on("error", this.onSocketError)
568 session.socket.on("close", this.onSocketClose)
569 }
570

Callers

nothing calls this directly

Calls 15

fatalMethod · 0.95
connectionQueryErrorFunction · 0.85
queryErrorFunction · 0.85
unconfirmedCancelErrorFunction · 0.85
classifyFieldsFunction · 0.85
encodeQueryFunction · 0.85
encodeBatchFunction · 0.85
retryStaleFunction · 0.85
runQueryFunction · 0.85
sendCancelRequestFunction · 0.85
streamRowsFunction · 0.85
listenChannelFunction · 0.85

Tested by

no test coverage detected