diff --git a/cpp/DBHostObject.cpp b/cpp/DBHostObject.cpp index ab33c7d..cc32a83 100644 --- a/cpp/DBHostObject.cpp +++ b/cpp/DBHostObject.cpp @@ -738,19 +738,22 @@ void DBHostObject::create_jsi_functions() { function_map["getDbPath"] = HOSTFN("getDbPath") { std::string path = std::string(base_path); - if (count == 1 && !args[0].isString()) { - throw std::runtime_error( - "[op-sqlite][open] database location must be a string"); - } - - std::string last_path = args[0].asString(rt).utf8(rt); - - if (last_path == ":memory:") { - path = ":memory:"; - } else if (last_path.rfind('/', 0) == 0) { - path = last_path; - } else { - path = path + "/" + last_path; + + if (count == 1) { + if(!args[0].isString()) { + throw std::runtime_error( + "[op-sqlite][open] database location must be a string"); + } + + std::string last_path = args[0].asString(rt).utf8(rt); + + if (last_path == ":memory:") { + path = ":memory:"; + } else if (last_path.rfind('/', 0) == 0) { + path = last_path; + } else { + path = path + "/" + last_path; + } } auto result = opsqlite_get_db_path(db_name, path); diff --git a/example/src/tests/blob.spec.ts b/example/src/tests/blob.spec.ts index ceecf9e..c64c1b0 100644 --- a/example/src/tests/blob.spec.ts +++ b/example/src/tests/blob.spec.ts @@ -10,10 +10,6 @@ export function blobTests() { describe('Blobs', () => { beforeEach(async () => { try { - if (db) { - db.delete(); - } - db = open({ name: 'blobs', encryptionKey: 'test', @@ -29,9 +25,7 @@ export function blobTests() { }); afterAll(() => { - if (db) { - db.delete(); - } + db.delete(); }); it('ArrayBuffer', async () => { @@ -86,7 +80,7 @@ export function blobTests() { const statement = db.prepareStatement( 'INSERT OR REPLACE INTO BlobTable VALUES (?, ?);', ); - statement.bind([1, uint8]); + await statement.bind([1, uint8]); await statement.execute(); @@ -103,7 +97,8 @@ export function blobTests() { const statement = db.prepareStatement( 'INSERT OR REPLACE INTO BlobTable VALUES (?, ?);', ); - statement.bind([1, uint8.buffer]); + + await statement.bind([1, uint8.buffer]); await statement.execute(); diff --git a/example/src/tests/dbsetup.spec.ts b/example/src/tests/dbsetup.spec.ts index 09fa6ee..2f98c52 100644 --- a/example/src/tests/dbsetup.spec.ts +++ b/example/src/tests/dbsetup.spec.ts @@ -208,4 +208,15 @@ export function dbSetupTests() { }); db2.delete(); }); + + it('Can get db path', () => { + let db = open({ + name: 'pathTest.sqlite', + encryptionKey: 'test', + }); + + let path = db.getDbPath(); + expect(path).to.exist; + db.close(); + }); }