Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tests and fix getDbPath function #208

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions cpp/DBHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions example/src/tests/blob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ export function blobTests() {
describe('Blobs', () => {
beforeEach(async () => {
try {
if (db) {
db.delete();
}

db = open({
name: 'blobs',
encryptionKey: 'test',
Expand All @@ -29,9 +25,7 @@ export function blobTests() {
});

afterAll(() => {
if (db) {
db.delete();
}
db.delete();
});

it('ArrayBuffer', async () => {
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down
11 changes: 11 additions & 0 deletions example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Loading