@@ -50,14 +50,15 @@ namespace async_postgres::lua {
50
50
throw std::runtime_error (" query already in progress" );
51
51
}
52
52
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
+ });
55
57
56
58
if (lua->IsType (3 , GLua::Type::Function)) {
57
- query. callback = GLua::AutoReference (lua, 3 );
59
+ state-> query -> callback = GLua::AutoReference (lua, 3 );
58
60
}
59
61
60
- state->query = std::move (query);
61
62
return 0 ;
62
63
}
63
64
@@ -71,17 +72,16 @@ namespace async_postgres::lua {
71
72
throw std::runtime_error (" query already in progress" );
72
73
}
73
74
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
+ }) ;
79
80
80
81
if (lua->IsType (4 , GLua::Type::Function)) {
81
- query. callback = GLua::AutoReference (lua, 4 );
82
+ state-> query -> callback = GLua::AutoReference (lua, 4 );
82
83
}
83
84
84
- state->query = std::move (query);
85
85
return 0 ;
86
86
}
87
87
@@ -95,15 +95,16 @@ namespace async_postgres::lua {
95
95
throw std::runtime_error (" query already in progress" );
96
96
}
97
97
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
+ });
101
103
102
104
if (lua->IsType (4 , GLua::Type::Function)) {
103
- query. callback = GLua::AutoReference (lua, 4 );
105
+ state-> query -> callback = GLua::AutoReference (lua, 4 );
104
106
}
105
107
106
- state->query = std::move (query);
107
108
return 0 ;
108
109
}
109
110
@@ -117,17 +118,16 @@ namespace async_postgres::lua {
117
118
throw std::runtime_error (" query already in progress" );
118
119
}
119
120
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
+ }) ;
125
126
126
127
if (lua->IsType (4 , GLua::Type::Function)) {
127
- query. callback = GLua::AutoReference (lua, 4 );
128
+ state-> query -> callback = GLua::AutoReference (lua, 4 );
128
129
}
129
130
130
- state->query = std::move (query);
131
131
return 0 ;
132
132
}
133
133
@@ -140,14 +140,15 @@ namespace async_postgres::lua {
140
140
throw std::runtime_error (" query already in progress" );
141
141
}
142
142
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
+ });
145
147
146
148
if (lua->IsType (3 , GLua::Type::Function)) {
147
- query. callback = GLua::AutoReference (lua, 3 );
149
+ state-> query -> callback = GLua::AutoReference (lua, 3 );
148
150
}
149
151
150
- state->query = std::move (query);
151
152
return 0 ;
152
153
}
153
154
@@ -160,14 +161,15 @@ namespace async_postgres::lua {
160
161
throw std::runtime_error (" query already in progress" );
161
162
}
162
163
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
+ });
165
168
166
169
if (lua->IsType (3 , GLua::Type::Function)) {
167
- query. callback = GLua::AutoReference (lua, 3 );
170
+ state-> query -> callback = GLua::AutoReference (lua, 3 );
168
171
}
169
172
170
- state->query = std::move (query);
171
173
return 0 ;
172
174
}
173
175
@@ -201,9 +203,8 @@ namespace async_postgres::lua {
201
203
202
204
auto state = lua_connection_state ();
203
205
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 ) {
207
208
bool write =
208
209
state->reset_event ->status == PGRES_POLLING_WRITING;
209
210
bool read = state->reset_event ->status == PGRES_POLLING_READING;
@@ -220,16 +221,15 @@ namespace async_postgres::lua {
220
221
}
221
222
222
223
if (state->query ) {
223
- auto & query = state->query . value () ;
224
+ auto query = state->query ;
224
225
225
226
// if query wasn't sent, send in through process_query
226
- if (!query. sent ) {
227
+ if (!query-> sent ) {
227
228
async_postgres::process_query (lua, state);
228
229
}
229
230
230
231
// 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 ) {
233
233
async_postgres::process_result (lua, state,
234
234
pg::getResult (state->conn ));
235
235
}
@@ -253,14 +253,14 @@ namespace async_postgres::lua {
253
253
lua_protected_fn (querying) {
254
254
lua->CheckType (1 , async_postgres::connection_meta);
255
255
auto state = lua_connection_state ();
256
- lua->PushBool (state->query . has_value () );
256
+ lua->PushBool (!! state->query );
257
257
return 1 ;
258
258
}
259
259
260
260
lua_protected_fn (resetting) {
261
261
lua->CheckType (1 , async_postgres::connection_meta);
262
262
auto state = lua_connection_state ();
263
- lua->PushBool (state->reset_event . has_value () );
263
+ lua->PushBool (!! state->reset_event );
264
264
return 1 ;
265
265
}
266
266
} // namespace async_postgres::lua
0 commit comments