@@ -50,14 +50,15 @@ namespace async_postgres::lua {
5050 throw std::runtime_error (" query already in progress" );
5151 }
5252
53- async_postgres::SimpleCommand command = {lua->GetString (2 )};
54- async_postgres::Query query = {std::move (command)};
53+ state->query = std::make_shared<async_postgres::Query>(
54+ async_postgres::SimpleCommand{
55+ lua->GetString (2 ),
56+ });
5557
5658 if (lua->IsType (3 , GLua::Type::Function)) {
57- query. callback = GLua::AutoReference (lua, 3 );
59+ state-> query -> callback = GLua::AutoReference (lua, 3 );
5860 }
5961
60- state->query = std::move (query);
6162 return 0 ;
6263 }
6364
@@ -71,17 +72,16 @@ namespace async_postgres::lua {
7172 throw std::runtime_error (" query already in progress" );
7273 }
7374
74- async_postgres::ParameterizedCommand command = {
75- lua-> GetString ( 2 ),
76- async_postgres::array_to_params (lua, 3 ),
77- };
78- async_postgres::Query query = { std::move (command)} ;
75+ state-> query = std::make_shared<async_postgres::Query>(
76+ async_postgres::ParameterizedCommand{
77+ lua-> GetString ( 2 ),
78+ async_postgres::array_to_params (lua, 3 ),
79+ }) ;
7980
8081 if (lua->IsType (4 , GLua::Type::Function)) {
81- query. callback = GLua::AutoReference (lua, 4 );
82+ state-> query -> callback = GLua::AutoReference (lua, 4 );
8283 }
8384
84- state->query = std::move (query);
8585 return 0 ;
8686 }
8787
@@ -95,15 +95,16 @@ namespace async_postgres::lua {
9595 throw std::runtime_error (" query already in progress" );
9696 }
9797
98- async_postgres::CreatePreparedCommand command = {lua->GetString (2 ),
99- lua->GetString (3 )};
100- async_postgres::Query query = {std::move (command)};
98+ state->query = std::make_shared<async_postgres::Query>(
99+ async_postgres::CreatePreparedCommand{
100+ lua->GetString (2 ),
101+ lua->GetString (3 ),
102+ });
101103
102104 if (lua->IsType (4 , GLua::Type::Function)) {
103- query. callback = GLua::AutoReference (lua, 4 );
105+ state-> query -> callback = GLua::AutoReference (lua, 4 );
104106 }
105107
106- state->query = std::move (query);
107108 return 0 ;
108109 }
109110
@@ -117,17 +118,16 @@ namespace async_postgres::lua {
117118 throw std::runtime_error (" query already in progress" );
118119 }
119120
120- async_postgres::PreparedCommand command = {
121- lua-> GetString ( 2 ),
122- async_postgres::array_to_params (lua, 3 ),
123- };
124- async_postgres::Query query = { std::move (command)} ;
121+ state-> query = std::make_shared<async_postgres::Query>(
122+ async_postgres::PreparedCommand{
123+ lua-> GetString ( 2 ),
124+ async_postgres::array_to_params (lua, 3 ),
125+ }) ;
125126
126127 if (lua->IsType (4 , GLua::Type::Function)) {
127- query. callback = GLua::AutoReference (lua, 4 );
128+ state-> query -> callback = GLua::AutoReference (lua, 4 );
128129 }
129130
130- state->query = std::move (query);
131131 return 0 ;
132132 }
133133
@@ -140,14 +140,15 @@ namespace async_postgres::lua {
140140 throw std::runtime_error (" query already in progress" );
141141 }
142142
143- async_postgres::DescribePreparedCommand command = {lua->GetString (2 )};
144- async_postgres::Query query = {std::move (command)};
143+ state->query = std::make_shared<async_postgres::Query>(
144+ async_postgres::DescribePreparedCommand{
145+ lua->GetString (2 ),
146+ });
145147
146148 if (lua->IsType (3 , GLua::Type::Function)) {
147- query. callback = GLua::AutoReference (lua, 3 );
149+ state-> query -> callback = GLua::AutoReference (lua, 3 );
148150 }
149151
150- state->query = std::move (query);
151152 return 0 ;
152153 }
153154
@@ -160,14 +161,15 @@ namespace async_postgres::lua {
160161 throw std::runtime_error (" query already in progress" );
161162 }
162163
163- async_postgres::DescribePortalCommand command = {lua->GetString (2 )};
164- async_postgres::Query query = {std::move (command)};
164+ state->query = std::make_shared<async_postgres::Query>(
165+ async_postgres::DescribePortalCommand{
166+ lua->GetString (2 ),
167+ });
165168
166169 if (lua->IsType (3 , GLua::Type::Function)) {
167- query. callback = GLua::AutoReference (lua, 3 );
170+ state-> query -> callback = GLua::AutoReference (lua, 3 );
168171 }
169172
170- state->query = std::move (query);
171173 return 0 ;
172174 }
173175
@@ -201,9 +203,8 @@ namespace async_postgres::lua {
201203
202204 auto state = lua_connection_state ();
203205 if (state->reset_event ) {
204- auto & event = state->reset_event .value ();
205- while (state->reset_event .has_value () &&
206- &event == &state->reset_event .value ()) {
206+ auto event = state->reset_event ;
207+ while (event == state->reset_event ) {
207208 bool write =
208209 state->reset_event ->status == PGRES_POLLING_WRITING;
209210 bool read = state->reset_event ->status == PGRES_POLLING_READING;
@@ -220,16 +221,15 @@ namespace async_postgres::lua {
220221 }
221222
222223 if (state->query ) {
223- auto & query = state->query . value () ;
224+ auto query = state->query ;
224225
225226 // if query wasn't sent, send in through process_query
226- if (!query. sent ) {
227+ if (!query-> sent ) {
227228 async_postgres::process_query (lua, state);
228229 }
229230
230231 // while query is the same and it's not done
231- while (state->query .has_value () &&
232- &query == &state->query .value ()) {
232+ while (query == state->query ) {
233233 async_postgres::process_result (lua, state,
234234 pg::getResult (state->conn ));
235235 }
@@ -253,14 +253,14 @@ namespace async_postgres::lua {
253253 lua_protected_fn (querying) {
254254 lua->CheckType (1 , async_postgres::connection_meta);
255255 auto state = lua_connection_state ();
256- lua->PushBool (state->query . has_value () );
256+ lua->PushBool (!! state->query );
257257 return 1 ;
258258 }
259259
260260 lua_protected_fn (resetting) {
261261 lua->CheckType (1 , async_postgres::connection_meta);
262262 auto state = lua_connection_state ();
263- lua->PushBool (state->reset_event . has_value () );
263+ lua->PushBool (!! state->reset_event );
264264 return 1 ;
265265 }
266266} // namespace async_postgres::lua
0 commit comments