MCPcopy Create free account
hub / github.com/porsager/postgres / Postgres

Function Postgres

cjs/src/index.js:49–428  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

47module.exports = Postgres
48
49function Postgres(a, b) {
50 const options = parseOptions(a, b)
51 , subscribe = options.no_subscribe || Subscribe(Postgres, { ...options })
52
53 let ending = false
54
55 const queries = Queue()
56 , connecting = Queue()
57 , reserved = Queue()
58 , closed = Queue()
59 , ended = Queue()
60 , open = Queue()
61 , busy = Queue()
62 , full = Queue()
63 , queues = { connecting, reserved, closed, ended, open, busy, full }
64
65 const connections = [...Array(options.max)].map(() => Connection(options, queues, { onopen, onend, onclose }))
66
67 const sql = Sql(handler)
68
69 Object.assign(sql, {
70 get parameters() { return options.parameters },
71 largeObject: largeObject.bind(null, sql),
72 subscribe,
73 CLOSE,
74 END: CLOSE,
75 PostgresError,
76 options,
77 reserve,
78 listen,
79 begin,
80 close,
81 end
82 })
83
84 return sql
85
86 function Sql(handler) {
87 handler.debug = options.debug
88
89 Object.entries(options.types).reduce((acc, [name, type]) => {
90 acc[name] = (x) => new Parameter(x, type.to)
91 return acc
92 }, typed)
93
94 Object.assign(sql, {
95 types: typed,
96 typed,
97 unsafe,
98 notify,
99 array,
100 json,
101 file
102 })
103
104 return sql
105
106 function typed(value, type) {

Callers 1

listenFunction · 0.70

Calls 5

parseOptionsFunction · 0.70
SubscribeFunction · 0.70
QueueFunction · 0.70
ConnectionFunction · 0.70
SqlFunction · 0.70

Tested by

no test coverage detected