Skip to content

Commit 18f0ca1

Browse files
committed
chore(upstream): sync node_sqlite from v25.x-staging
Adds iterator invalidation via reset_generation counter. Fixes Node.js version references (v25.8.0 → v25.8.1).
1 parent fe2b165 commit 18f0ca1

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![npm version](https://img.shields.io/npm/v/@photostructure/sqlite.svg)](https://www.npmjs.com/package/@photostructure/sqlite)
66
[![CI](https://github.com/photostructure/node-sqlite/actions/workflows/build.yml/badge.svg)](https://github.com/photostructure/node-sqlite/actions/workflows/build.yml)
77

8-
Native SQLite for Node.js 20+. Drop-in replacement for `node:sqlite`. Synced with Node.js v25.8.0 for the latest features including native `Symbol.dispose` resource management.
8+
Native SQLite for Node.js 20+. Drop-in replacement for `node:sqlite`. Synced with Node.js v25.8.1 for the latest features including native `Symbol.dispose` resource management.
99

1010
## Installation
1111

@@ -29,7 +29,7 @@ db.close();
2929

3030
## Features
3131

32-
- 100% compatible with Node.js v25.8.0 built-in `node:sqlite` module\*
32+
- 100% compatible with Node.js v25.8.1 built-in `node:sqlite` module\*
3333
- Zero dependencies - native SQLite implementation
3434
- Synchronous API - no async overhead
3535
- Performance comparable to better-sqlite3

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
"typescript-eslint": "^8.56.1"
158158
},
159159
"versions": {
160-
"nodejs": "v25.8.0@f91cf7f",
160+
"nodejs": "v25.x-staging@ca2d6ea",
161161
"sqlite": "3.52.0"
162162
}
163163
}

src/upstream/node_sqlite.cc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,11 @@ inline bool StatementSync::IsFinalized() {
24212421
return statement_ == nullptr;
24222422
}
24232423

2424+
inline int StatementSync::ResetStatement() {
2425+
reset_generation_++;
2426+
return sqlite3_reset(statement_);
2427+
}
2428+
24242429
bool StatementSync::BindParams(const FunctionCallbackInfo<Value>& args) {
24252430
int r = sqlite3_clear_bindings(statement_);
24262431
CHECK_ERROR_OR_THROW(env()->isolate(), db_.get(), r, SQLITE_OK, false);
@@ -2812,7 +2817,7 @@ void StatementSync::All(const FunctionCallbackInfo<Value>& args) {
28122817
THROW_AND_RETURN_ON_BAD_STATE(
28132818
env, stmt->IsFinalized(), "statement has been finalized");
28142819
Isolate* isolate = env->isolate();
2815-
int r = sqlite3_reset(stmt->statement_);
2820+
int r = stmt->ResetStatement();
28162821
CHECK_ERROR_OR_THROW(isolate, stmt->db_.get(), r, SQLITE_OK, void());
28172822

28182823
if (!stmt->BindParams(args)) {
@@ -2838,7 +2843,7 @@ void StatementSync::Iterate(const FunctionCallbackInfo<Value>& args) {
28382843
Environment* env = Environment::GetCurrent(args);
28392844
THROW_AND_RETURN_ON_BAD_STATE(
28402845
env, stmt->IsFinalized(), "statement has been finalized");
2841-
int r = sqlite3_reset(stmt->statement_);
2846+
int r = stmt->ResetStatement();
28422847
CHECK_ERROR_OR_THROW(env->isolate(), stmt->db_.get(), r, SQLITE_OK, void());
28432848

28442849
if (!stmt->BindParams(args)) {
@@ -2861,7 +2866,7 @@ void StatementSync::Get(const FunctionCallbackInfo<Value>& args) {
28612866
Environment* env = Environment::GetCurrent(args);
28622867
THROW_AND_RETURN_ON_BAD_STATE(
28632868
env, stmt->IsFinalized(), "statement has been finalized");
2864-
int r = sqlite3_reset(stmt->statement_);
2869+
int r = stmt->ResetStatement();
28652870
CHECK_ERROR_OR_THROW(env->isolate(), stmt->db_.get(), r, SQLITE_OK, void());
28662871

28672872
if (!stmt->BindParams(args)) {
@@ -2885,7 +2890,7 @@ void StatementSync::Run(const FunctionCallbackInfo<Value>& args) {
28852890
Environment* env = Environment::GetCurrent(args);
28862891
THROW_AND_RETURN_ON_BAD_STATE(
28872892
env, stmt->IsFinalized(), "statement has been finalized");
2888-
int r = sqlite3_reset(stmt->statement_);
2893+
int r = stmt->ResetStatement();
28892894
CHECK_ERROR_OR_THROW(env->isolate(), stmt->db_.get(), r, SQLITE_OK, void());
28902895

28912896
if (!stmt->BindParams(args)) {
@@ -3430,6 +3435,7 @@ StatementSyncIterator::StatementSyncIterator(Environment* env,
34303435
: BaseObject(env, object), stmt_(std::move(stmt)) {
34313436
MakeWeak();
34323437
done_ = false;
3438+
statement_reset_generation_ = stmt_->reset_generation_;
34333439
}
34343440

34353441
StatementSyncIterator::~StatementSyncIterator() {}
@@ -3444,7 +3450,7 @@ Local<FunctionTemplate> StatementSyncIterator::GetConstructorTemplate(
34443450
tmpl = NewFunctionTemplate(isolate, IllegalConstructor);
34453451
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "StatementSyncIterator"));
34463452
tmpl->InstanceTemplate()->SetInternalFieldCount(
3447-
StatementSync::kInternalFieldCount);
3453+
StatementSyncIterator::kInternalFieldCount);
34483454
SetProtoMethod(isolate, tmpl, "next", StatementSyncIterator::Next);
34493455
SetProtoMethod(isolate, tmpl, "return", StatementSyncIterator::Return);
34503456
env->set_sqlite_statement_sync_iterator_constructor_template(tmpl);
@@ -3488,6 +3494,11 @@ void StatementSyncIterator::Next(const FunctionCallbackInfo<Value>& args) {
34883494
return;
34893495
}
34903496

3497+
THROW_AND_RETURN_ON_BAD_STATE(
3498+
env,
3499+
iter->statement_reset_generation_ != iter->stmt_->reset_generation_,
3500+
"iterator was invalidated");
3501+
34913502
int r = sqlite3_step(iter->stmt_->statement_);
34923503
if (r != SQLITE_ROW) {
34933504
CHECK_ERROR_OR_THROW(

src/upstream/node_sqlite.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ class StatementSync : public BaseObject {
291291
bool use_big_ints_;
292292
bool allow_bare_named_params_;
293293
bool allow_unknown_named_params_;
294+
uint64_t reset_generation_ = 0;
294295
std::optional<std::map<std::string, std::string>> bare_named_params_;
296+
inline int ResetStatement();
295297
bool BindParams(const v8::FunctionCallbackInfo<v8::Value>& args);
296298
bool BindValue(const v8::Local<v8::Value>& value, const int index);
297299

@@ -321,6 +323,7 @@ class StatementSyncIterator : public BaseObject {
321323
~StatementSyncIterator() override;
322324
BaseObjectPtr<StatementSync> stmt_;
323325
bool done_;
326+
uint64_t statement_reset_generation_;
324327
};
325328

326329
using Sqlite3ChangesetGenFunc = int (*)(sqlite3_session*, int*, void**);

test/node-compat/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ node --test test/node-compat/test-sqlite-statement-sync-columns.test.js
1818
```
1919

2020
Source: https://github.com/nodejs/node/tree/main/test/parallel
21-
Commit: f38a739623848a2eb6e7cc9f8d323b063c7ced9b
21+
Commit: aac5b68211c0ec7fbb008094da358b39aa366519

0 commit comments

Comments
 (0)