Skip to content

Commit 8233d2f

Browse files
committed
add other statement structures
1 parent 5900f5d commit 8233d2f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/node_sqlite.cc

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,8 @@ void StatementSync::All(const FunctionCallbackInfo<Value>& args) {
20792079
args.GetReturnValue().Set(Array::New(isolate, rows.data(), rows.size()));
20802080
}
20812081

2082+
void Statement::Iterate(const FunctionCallbackInfo<Value>& args) {}
2083+
20822084
void StatementSync::Iterate(const FunctionCallbackInfo<Value>& args) {
20832085
StatementSync* stmt;
20842086
ASSIGN_OR_RETURN_UNWRAP(&stmt, args.This());
@@ -2120,6 +2122,39 @@ void StatementSync::Iterate(const FunctionCallbackInfo<Value>& args) {
21202122
args.GetReturnValue().Set(iter->object());
21212123
}
21222124

2125+
void Statement::Get(const FunctionCallbackInfo<Value>& args) {
2126+
StatementSync* stmt;
2127+
ASSIGN_OR_RETURN_UNWRAP(&stmt, args.This());
2128+
Environment* env = Environment::GetCurrent(args);
2129+
THROW_AND_RETURN_ON_BAD_STATE(
2130+
env, stmt->IsFinalized(), "statement has been finalized");
2131+
Isolate* isolate = env->isolate();
2132+
int r = sqlite3_reset(stmt->statement_);
2133+
CHECK_ERROR_OR_THROW(isolate, stmt->db_.get(), r, SQLITE_OK, void());
2134+
2135+
if (!stmt->BindParams(args)) {
2136+
return;
2137+
}
2138+
2139+
Local<Promise::Resolver> resolver;
2140+
if (!Promise::Resolver::New(env->context()).ToLocal(&resolver)) {
2141+
return;
2142+
}
2143+
2144+
auto task = [stmt]() -> int {
2145+
2146+
};
2147+
2148+
auto after = [env, isolate, stmt](int result, Local<Promise::Resolver> resolver) {
2149+
2150+
};
2151+
2152+
auto* work = new SQLiteAsyncWork<std::vector<Row>>(
2153+
env, stmt->db_.get(), resolver, task, after);
2154+
work->ScheduleWork();
2155+
args.GetReturnValue().Set(resolver->GetPromise());
2156+
}
2157+
21232158
void StatementSync::Get(const FunctionCallbackInfo<Value>& args) {
21242159
StatementSync* stmt;
21252160
ASSIGN_OR_RETURN_UNWRAP(&stmt, args.This());
@@ -2353,8 +2388,6 @@ using RowArray = std::vector<sqlite3_value*>;
23532388
using RowObject = std::vector<std::pair<std::string, sqlite3_value*>>;
23542389
using Row = std::variant<RowArray, RowObject>;
23552390

2356-
void Statement::Get(const FunctionCallbackInfo<Value>& args) {}
2357-
23582391
void Statement::All(const FunctionCallbackInfo<Value>& args) {
23592392
Statement* stmt;
23602393
ASSIGN_OR_RETURN_UNWRAP(&stmt, args.This());

src/node_sqlite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Statement : public BaseObject {
7777
static void All(const v8::FunctionCallbackInfo<v8::Value>& args);
7878
static void Get(const v8::FunctionCallbackInfo<v8::Value>& args);
7979
static void Run(const v8::FunctionCallbackInfo<v8::Value>& args);
80+
static void Iterate(const v8::FunctionCallbackInfo<v8::Value>& args);
8081
static void SetReturnArrays(const v8::FunctionCallbackInfo<v8::Value>& args);
8182
bool BindValue(const v8::Local<v8::Value>& value, const int index);
8283
bool BindParams(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
 (0)