| 294 | } |
| 295 | |
| 296 | void DB::queryAsync(String sql, std::vector<Own<Value>>&& args, bool withColumns, const std::function<void(std::optional<Rows>&)>& callback) { |
| 297 | std::string sqlStr(sql.toString()); |
| 298 | auto argsPtr = std::make_shared<std::vector<Own<Value>>>(std::move(args)); |
| 299 | _thread->run( |
| 300 | [sqlStr, argsPtr = std::move(argsPtr), withColumns, db = _database.get()]() { |
| 301 | try { |
| 302 | auto result = SharedDB.queryUnsafe(db, sqlStr, *argsPtr, withColumns); |
| 303 | return Values::alloc(std::move(result)); |
| 304 | } catch (std::exception& e) { |
| 305 | Warn("failed to execute DB query: {}", e.what()); |
| 306 | return Own<Values>{}; |
| 307 | } |
| 308 | }, |
| 309 | [callback](Own<Values> values) { |
| 310 | std::optional<Rows> opt; |
| 311 | if (values) { |
| 312 | Rows result; |
| 313 | values->get(result); |
| 314 | opt = std::move(result); |
| 315 | } |
| 316 | callback(opt); |
| 317 | }); |
| 318 | } |
| 319 | |
| 320 | void DB::insertAsync(String tableName, std::deque<std::vector<Own<Value>>>&& rows, const std::function<void(bool)>& callback) { |
| 321 | std::string tableStr(tableName.toString()); |