@@ -188,54 +188,43 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
188188
189189void DBHostObject::create_jsi_functions () {
190190 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-
200191 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- }
206192
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;
208206 }
209207
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);
213208#ifdef OP_SQLITE_USE_LIBSQL
214209 opsqlite_libsql_attach (db, secondary_db_path, secondary_db_name, alias);
215210#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);
218212#endif
219213
220214 return {};
221215 });
222216
223217 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" );
231221 }
232222
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);
235224#ifdef OP_SQLITE_USE_LIBSQL
236225 opsqlite_libsql_detach (db, alias);
237226#else
238- opsqlite_detach (db, dbName, alias);
227+ opsqlite_detach (db, alias);
239228#endif
240229
241230 return {};
0 commit comments