@op-engineering/op-sqlite 11.4.9 → 12.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -188,54 +188,43 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
188
188
 
189
189
  void DBHostObject::create_jsi_functions() {
190
190
  function_map["attach"] = HOSTFN("attach") {
191
- if (count < 3) {
192
- throw std::runtime_error(
193
- "[op-sqlite][attach] Incorrect number of arguments");
194
- }
195
- if (!args[0].isString() || !args[1].isString() || !args[2].isString()) {
196
- throw std::runtime_error("[op-sqlite] name, database to attach and "
197
- "alias must be strings");
198
- }
199
-
200
191
  std::string secondary_db_path = std::string(base_path);
201
- if (count > 3) {
202
- if (!args[3].isString()) {
203
- throw std::runtime_error(
204
- "[op-sqlite][attach] database location must be a string");
205
- }
206
192
 
207
- secondary_db_path += "/" + args[3].asString(rt).utf8(rt);
193
+ auto obj_params = args[0].asObject(rt);
194
+
195
+ std::string secondary_db_name =
196
+ obj_params.getProperty(rt, "secondaryDbFileName")
197
+ .asString(rt)
198
+ .utf8(rt);
199
+ std::string alias =
200
+ obj_params.getProperty(rt, "alias").asString(rt).utf8(rt);
201
+
202
+ if (obj_params.hasProperty(rt, "location")) {
203
+ std::string location =
204
+ obj_params.getProperty(rt, "location").asString(rt).utf8(rt);
205
+ secondary_db_path = secondary_db_path + location;
208
206
  }
209
207
 
210
- std::string main_db_name = args[0].asString(rt).utf8(rt);
211
- std::string secondary_db_name = args[1].asString(rt).utf8(rt);
212
- std::string alias = args[2].asString(rt).utf8(rt);
213
208
  #ifdef OP_SQLITE_USE_LIBSQL
214
209
  opsqlite_libsql_attach(db, secondary_db_path, secondary_db_name, alias);
215
210
  #else
216
- opsqlite_attach(db, main_db_name, secondary_db_path, secondary_db_name,
217
- alias);
211
+ opsqlite_attach(db, secondary_db_path, secondary_db_name, alias);
218
212
  #endif
219
213
 
220
214
  return {};
221
215
  });
222
216
 
223
217
  function_map["detach"] = HOSTFN("detach") {
224
- if (count < 2) {
225
- throw std::runtime_error(
226
- "[op-sqlite][detach] Incorrect number of arguments");
227
- }
228
- if (!args[0].isString() || !args[1].isString()) {
229
- throw std::runtime_error(
230
- "[op-sqlite] database name and alias must be a strings");
218
+
219
+ if (!args[0].isString()) {
220
+ throw std::runtime_error("[op-sqlite] alias must be a strings");
231
221
  }
232
222
 
233
- std::string dbName = args[0].asString(rt).utf8(rt);
234
- std::string alias = args[1].asString(rt).utf8(rt);
223
+ std::string alias = args[0].asString(rt).utf8(rt);
235
224
  #ifdef OP_SQLITE_USE_LIBSQL
236
225
  opsqlite_libsql_detach(db, alias);
237
226
  #else
238
- opsqlite_detach(db, dbName, alias);
227
+ opsqlite_detach(db, alias);
239
228
  #endif
240
229
 
241
230
  return {};
package/cpp/bridge.cpp CHANGED
@@ -150,8 +150,7 @@ void opsqlite_close(sqlite3 *db) {
150
150
  sqlite3_close_v2(db);
151
151
  }
152
152
 
153
- void opsqlite_attach(sqlite3 *db, std::string const &main_db_name,
154
- std::string const &doc_path,
153
+ void opsqlite_attach(sqlite3 *db, std::string const &doc_path,
155
154
  std::string const &secondary_db_name,
156
155
  std::string const &alias) {
157
156
  auto secondary_db_path = opsqlite_get_db_path(secondary_db_name, doc_path);
@@ -160,8 +159,7 @@ void opsqlite_attach(sqlite3 *db, std::string const &main_db_name,
160
159
  opsqlite_execute(db, statement, nullptr);
161
160
  }
162
161
 
163
- void opsqlite_detach(sqlite3 *db, std::string const &main_db_name,
164
- std::string const &alias) {
162
+ void opsqlite_detach(sqlite3 *db, std::string const &alias) {
165
163
  std::string statement = "DETACH DATABASE " + alias;
166
164
  opsqlite_execute(db, statement, nullptr);
167
165
  }
package/cpp/bridge.h CHANGED
@@ -37,13 +37,11 @@ void opsqlite_close(sqlite3 *db);
37
37
  void opsqlite_remove(sqlite3 *db, std::string const &name,
38
38
  std::string const &doc_path);
39
39
 
40
- void opsqlite_attach(sqlite3 *db, std::string const &main_db_name,
41
- std::string const &doc_path,
40
+ void opsqlite_attach(sqlite3 *db, std::string const &doc_path,
42
41
  std::string const &secondary_db_name,
43
42
  std::string const &alias);
44
43
 
45
- void opsqlite_detach(sqlite3 *db, std::string const &main_db_name,
46
- std::string const &alias);
44
+ void opsqlite_detach(sqlite3 *db, std::string const &alias);
47
45
 
48
46
  BridgeResult opsqlite_execute(sqlite3 *db, std::string const &query,
49
47
  const std::vector<JSVariant> *params);