Skip to content

Commit a57526d

Browse files
authored
Merge pull request #31 from OP-Engineering/clean-up
Clean up code to make it more C++ and use references to prevent copying strings arounds
2 parents 77ddee2 + d216965 commit a57526d

File tree

8 files changed

+127
-152
lines changed

8 files changed

+127
-152
lines changed

benchmark.png

19.1 KB
Loading

cpp/bindings.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool invalidated = false;
3535
void clearState() {
3636
invalidated = true;
3737
// Will terminate all operations and database connections
38-
sqliteCloseAll();
38+
sqlite_close_all();
3939
// We then join all the threads before the context gets invalidated
4040
pool.restartPool();
4141

@@ -81,7 +81,7 @@ void install(jsi::Runtime &rt,
8181
}
8282
}
8383

84-
BridgeResult result = sqliteOpenDb(dbName, path);
84+
BridgeResult result = sqlite_open(dbName, path);
8585

8686
if (result.type == SQLiteError) {
8787
throw std::runtime_error(result.message);
@@ -115,7 +115,7 @@ void install(jsi::Runtime &rt,
115115
std::string databaseToAttach = args[1].asString(rt).utf8(rt);
116116
std::string alias = args[2].asString(rt).utf8(rt);
117117
BridgeResult result =
118-
sqliteAttachDb(dbName, tempDocPath, databaseToAttach, alias);
118+
sqlite_attach(dbName, tempDocPath, databaseToAttach, alias);
119119

120120
if (result.type == SQLiteError) {
121121
throw std::runtime_error(result.message);
@@ -137,7 +137,7 @@ void install(jsi::Runtime &rt,
137137

138138
std::string dbName = args[0].asString(rt).utf8(rt);
139139
std::string alias = args[1].asString(rt).utf8(rt);
140-
BridgeResult result = sqliteDetachDb(dbName, alias);
140+
BridgeResult result = sqlite_detach(dbName, alias);
141141

142142
if (result.type == SQLiteError) {
143143
throw jsi::JSError(rt, result.message.c_str());
@@ -158,7 +158,7 @@ void install(jsi::Runtime &rt,
158158

159159
std::string dbName = args[0].asString(rt).utf8(rt);
160160

161-
BridgeResult result = sqliteCloseDb(dbName);
161+
BridgeResult result = sqlite_close(dbName);
162162

163163
if (result.type == SQLiteError) {
164164
throw jsi::JSError(rt, result.message.c_str());
@@ -190,7 +190,7 @@ void install(jsi::Runtime &rt,
190190
tempDocPath = tempDocPath + "/" + args[1].asString(rt).utf8(rt);
191191
}
192192

193-
BridgeResult result = sqliteRemoveDb(dbName, tempDocPath);
193+
BridgeResult result = sqlite_remove(dbName, tempDocPath);
194194

195195
if (result.type == SQLiteError) {
196196
throw std::runtime_error(result.message);
@@ -213,7 +213,7 @@ void install(jsi::Runtime &rt,
213213
std::shared_ptr<std::vector<SmartHostObject>> metadata =
214214
std::make_shared<std::vector<SmartHostObject>>();
215215

216-
auto status = sqliteExecute(dbName, query, &params, &results, metadata);
216+
auto status = sqlite_execute(dbName, query, &params, &results, metadata);
217217

218218
if (status.type == SQLiteError) {
219219
throw std::runtime_error(status.message);
@@ -249,7 +249,7 @@ void install(jsi::Runtime &rt,
249249
std::make_shared<std::vector<SmartHostObject>>();
250250

251251
auto status =
252-
sqliteExecute(dbName, query, &params, &results, metadata);
252+
sqlite_execute(dbName, query, &params, &results, metadata);
253253

254254
if (invalidated) {
255255
return;
@@ -432,7 +432,7 @@ void install(jsi::Runtime &rt,
432432
auto callback = std::make_shared<jsi::Value>(rt, args[1]);
433433

434434
if (callback->isUndefined() || callback->isNull()) {
435-
unregisterUpdateHook(dbName);
435+
sqlite_deregister_update_hook(dbName);
436436
return {};
437437
}
438438

@@ -449,7 +449,7 @@ void install(jsi::Runtime &rt,
449449
if (operation != "DELETE") {
450450
std::string query = "SELECT * FROM " + tableName +
451451
" where rowid = " + std::to_string(rowId) + ";";
452-
sqliteExecute(dbName, query, &params, &results, metadata);
452+
sqlite_execute(dbName, query, &params, &results, metadata);
453453
}
454454

455455
invoker->invokeAsync(
@@ -474,7 +474,7 @@ void install(jsi::Runtime &rt,
474474
});
475475
};
476476

477-
registerUpdateHook(dbName, std::move(hook));
477+
sqlite_register_update_hook(dbName, std::move(hook));
478478

479479
return {};
480480
});
@@ -490,7 +490,7 @@ void install(jsi::Runtime &rt,
490490
auto dbName = args[0].asString(rt).utf8(rt);
491491
auto callback = std::make_shared<jsi::Value>(rt, args[1]);
492492
if (callback->isUndefined() || callback->isNull()) {
493-
unregisterCommitHook(dbName);
493+
sqlite_deregister_commit_hook(dbName);
494494
return {};
495495
}
496496
commitHooks[dbName] = callback;
@@ -500,7 +500,7 @@ void install(jsi::Runtime &rt,
500500
[&rt, callback] { callback->asObject(rt).asFunction(rt).call(rt); });
501501
};
502502

503-
registerCommitHook(dbName, std::move(hook));
503+
sqlite_register_commit_hook(dbName, std::move(hook));
504504

505505
return {};
506506
});
@@ -517,7 +517,7 @@ void install(jsi::Runtime &rt,
517517
auto callback = std::make_shared<jsi::Value>(rt, args[1]);
518518

519519
if (callback->isUndefined() || callback->isNull()) {
520-
unregisterRollbackHook(dbName);
520+
sqlite_deregister_rollback_hook(dbName);
521521
return {};
522522
}
523523
rollbackHooks[dbName] = callback;
@@ -527,7 +527,7 @@ void install(jsi::Runtime &rt,
527527
[&rt, callback] { callback->asObject(rt).asFunction(rt).call(rt); });
528528
};
529529

530-
registerRollbackHook(dbName, std::move(hook));
530+
sqlite_register_rollback_hook(dbName, std::move(hook));
531531
return {};
532532
});
533533

0 commit comments

Comments
 (0)