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

Function Postgres

cf/src/index.js:50–429  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

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