-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnode_prepared_statement.h
More file actions
53 lines (41 loc) · 1.65 KB
/
node_prepared_statement.h
File metadata and controls
53 lines (41 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "main/lbug.h"
#include "node_connection.h"
#include <napi.h>
using namespace lbug::main;
class NodePreparedStatement : public Napi::ObjectWrap<NodePreparedStatement> {
friend class NodeConnection;
friend class PreparedStatementInitAsyncWorker;
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);
explicit NodePreparedStatement(const Napi::CallbackInfo& info);
~NodePreparedStatement() override = default;
private:
Napi::Value InitAsync(const Napi::CallbackInfo& info);
Napi::Value InitSync(const Napi::CallbackInfo& info);
void InitCppPreparedStatement();
Napi::Value IsSuccess(const Napi::CallbackInfo& info);
Napi::Value GetErrorMessage(const Napi::CallbackInfo& info);
private:
std::shared_ptr<PreparedStatement> preparedStatement;
std::shared_ptr<Connection> connection;
std::string queryString;
};
class PreparedStatementInitAsyncWorker : public Napi::AsyncWorker {
public:
PreparedStatementInitAsyncWorker(Napi::Function& callback,
NodePreparedStatement* nodePreparedStatement)
: AsyncWorker(callback), nodePreparedStatement(nodePreparedStatement) {}
~PreparedStatementInitAsyncWorker() override = default;
inline void Execute() override {
try {
nodePreparedStatement->InitCppPreparedStatement();
} catch (const std::exception& exc) {
SetError(std::string(exc.what()));
}
}
inline void OnOK() override { Callback().Call({Env().Null()}); }
inline void OnError(Napi::Error const& error) override { Callback().Call({error.Value()}); }
private:
NodePreparedStatement* nodePreparedStatement;
};