MCPcopy
hub / github.com/brianc/node-postgres / connect

Method connect

packages/pg-cloudflare/src/index.ts:34–62  ·  view source on GitHub ↗
(port: number, host: string, connectListener?: (...args: unknown[]) => void)

Source from the content-addressed store, hash-verified

32 }
33
34 async connect(port: number, host: string, connectListener?: (...args: unknown[]) => void) {
35 try {
36 log('connecting')
37 if (connectListener) this.once('connect', connectListener)
38
39 const options: SocketOptions = this.ssl ? { secureTransport: 'starttls' } : {}
40 const mod = await import('cloudflare:sockets')
41 const connect = mod.connect
42 this._cfSocket = connect(`${host}:${port}`, options)
43 this._cfWriter = this._cfSocket.writable.getWriter()
44 this._addClosedHandler()
45
46 this._cfReader = this._cfSocket.readable.getReader()
47 if (this.ssl) {
48 this._listenOnce().catch((e) => this.emit('error', e))
49 } else {
50 this._listen().catch((e) => this.emit('error', e))
51 }
52
53 await this._cfWriter!.ready
54 log('socket ready')
55 this.writable = true
56 this.emit('connect')
57
58 return this
59 } catch (e) {
60 this.emit('error', e)
61 }
62 }
63
64 async _listen() {
65 // eslint-disable-next-line no-constant-condition

Callers 9

poolQueryPromiseFunction · 0.45
runFunction · 0.45
close.jsFile · 0.45
transactions.jsFile · 0.45
query-config.jsFile · 0.45
index.jsFile · 0.45
error-handling.jsFile · 0.45
promises.jsFile · 0.45

Calls 5

_addClosedHandlerMethod · 0.95
_listenOnceMethod · 0.95
_listenMethod · 0.95
connectFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected