@@ -119,6 +119,10 @@ if async_postgres.LUA_API_VERSION ~= 1 then
119
119
" expected 1, got " .. async_postgres .LUA_API_VERSION )
120
120
end
121
121
122
+
123
+ --- @class async_postgres_module : async_postgres
124
+ local module = setmetatable ({}, { __index = async_postgres })
125
+
122
126
local Queue = {}
123
127
Queue .__index = Queue
124
128
692
696
--- connectiong url format can be found at https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
693
697
--- @param url string connection url , see libpq documentation for more information
694
698
--- @return PGClient
695
- function async_postgres .Client (url )
699
+ function module .Client (url )
696
700
--- @class PGClient
697
701
local client = setmetatable ({
698
702
url = url ,
@@ -887,7 +891,7 @@ function Pool:processQueue()
887
891
local waiters = self .queue :size ()
888
892
local threshold = clients * self .threshold
889
893
if clients < self .max and waiters > threshold then
890
- local client = async_postgres .Client (self .url )
894
+ local client = module .Client (self .url )
891
895
client .onError = function (client , message )
892
896
return self :onError (message )
893
897
end
@@ -1075,11 +1079,11 @@ end
1075
1079
--- Creates a new connection pool with given connection url,
1076
1080
--- then use :connect() to get available connection,
1077
1081
--- and then :release() to release it back to the pool
1078
- function async_postgres .Pool (url )
1082
+ function module .Pool (url )
1079
1083
--- @class PGPool
1080
1084
local pool = setmetatable ({
1081
1085
url = url ,
1082
- clients = { async_postgres .Client (url ) },
1086
+ clients = { module .Client (url ) },
1083
1087
queue = Queue .new (),
1084
1088
max = 10 ,
1085
1089
threshold = 5 ,
@@ -1093,3 +1097,5 @@ function async_postgres.Pool(url)
1093
1097
1094
1098
return pool
1095
1099
end
1100
+
1101
+ return module
0 commit comments