Skip to content

Commit

Permalink
Close connection on invalidate/destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Dec 14, 2024
1 parent b904ff2 commit 31044c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions cpp/DBHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void DBHostObject::flush_pending_reactive_queries(
std::shared_ptr<std::vector<SmartHostObject>> metadata =
std::make_shared<std::vector<SmartHostObject>>();

auto status = opsqlite_execute_prepared_statement(db, query->stmt,
&results, metadata);
auto status = opsqlite_execute_prepared_statement(db, query->stmt, &results,
metadata);

if (status.type == SQLiteError) {
invoker->invokeAsync(
Expand Down Expand Up @@ -892,8 +892,14 @@ void DBHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
throw std::runtime_error("You cannot write to this object!");
}

void DBHostObject::invalidate() { invalidated = true; }
void DBHostObject::invalidate() {
invalidated = true;
opsqlite_close(db);
}

DBHostObject::~DBHostObject() { invalidated = true; }
DBHostObject::~DBHostObject() {
invalidated = true;
opsqlite_close(db);
}

} // namespace opsqlite
10 changes: 5 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export default function App() {
useEffect(() => {
runTests(
queriesTests,
// dbSetupTests,
// blobTests,
dbSetupTests,
blobTests,
// registerHooksTests,
// preparedStatementsTests,
// constantsTests,
preparedStatementsTests,
constantsTests,
// reactiveTests,
// tokenizerTests,
tokenizerTests,
)
.then(results => {
setServerResults(results as any);
Expand Down

0 comments on commit 31044c6

Please sign in to comment.