Skip to content

Commit

Permalink
Merge pull request #151 from OP-Engineering/oscar/refactor-api
Browse files Browse the repository at this point in the history
Refactor API into a simpler one
  • Loading branch information
ospfranco authored Sep 26, 2024
2 parents 076589d + 2d7593e commit 09b56c4
Show file tree
Hide file tree
Showing 21 changed files with 322 additions and 408 deletions.
Binary file modified android/src/main/jniLibs/arm64-v8a/libsqlite_vec.so
100755 → 100644
Binary file not shown.
Binary file modified android/src/main/jniLibs/armeabi-v7a/libsqlite_vec.so
100755 → 100644
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86/libsqlite_vec.so
100755 → 100644
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86_64/libsqlite_vec.so
100755 → 100644
Binary file not shown.
7 changes: 4 additions & 3 deletions cpp/libsql/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ void opsqlite_libsql_bind_statement(libsql_stmt_t statement,
JSVariant value = values->at(ii);
int status;

if (std::holds_alternative<bool>(value) ||
std::holds_alternative<int>(value)) {
if (std::holds_alternative<bool>(value)) {
status = libsql_bind_int(statement, index,
static_cast<int>(std::get<bool>(value)), &err);
} else if (std::holds_alternative<int>(value)) {
status = libsql_bind_int(statement, index, std::get<int>(value), &err);
} else if (std::holds_alternative<long long>(value)) {
status =
Expand Down Expand Up @@ -494,7 +496,6 @@ BridgeResult opsqlite_libsql_execute(std::string const &name,
break;

case LIBSQL_TEXT:

status = libsql_get_string(row, col, &text_value, &err);
out_row.emplace_back(text_value);
break;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ SPEC CHECKSUMS:
GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: 6eae7edb2f563ee41d7c1f91f4f2e57c26d8a5c3
op-sqlite: 92d182e19a4b923e2ae6760896dc578dbf8ef953
op-sqlite: d567632567b87bedda1f718e4ce6c081457c2f42
RCT-Folly: 045d6ecaa59d826c5736dfba0b2f4083ff8d79df
RCTDeprecation: 3ca8b6c36bfb302e1895b72cfe7db0de0c92cd47
RCTRequired: 9fc183af555fd0c89a366c34c1ae70b7e03b1dc5
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"chance": "^1.1.9",
"clsx": "^2.0.0",
"events": "^3.3.0",
"mocha": "^10.1.0",
"mocha": "^10.7.3",
"nativewind": "^2.0.11",
"react": "18.2.0",
"react-native": "0.74.0",
Expand Down
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default function App() {
const [results, setResults] = useState<any>([]);
useEffect(() => {
runTests(
dbSetupTests,
queriesTests,
dbSetupTests,
blobTests,
registerHooksTests,
preparedStatementsTests,
Expand Down
34 changes: 15 additions & 19 deletions example/src/tests/MochaRNAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import 'mocha';
import type * as MochaTypes from 'mocha';

export let rootSuite = new Mocha.Suite('') as MochaTypes.Suite;
rootSuite.timeout(10 * 1000);
// rootSuite.timeout(60 * 60 * 1000);
const TIMEOUT = 10 * 1000;

let mochaContext = rootSuite;
export const rootSuite = new Mocha.Suite('') as MochaTypes.Suite;
rootSuite.timeout(TIMEOUT);
let suite = new Mocha.Suite('') as MochaTypes.Suite;
let only = false;

export const clearTests = () => {
suite.suites = [];
suite.tests = [];
rootSuite.suites = [];
rootSuite.tests = [];
rootSuite = new Mocha.Suite('') as MochaTypes.Suite;
mochaContext = rootSuite;
only = false;
};

Expand All @@ -22,7 +22,7 @@ export const it = (
): void => {
if (!only) {
const test = new Mocha.Test(name, f);
mochaContext.addTest(test);
suite.addTest(test);
}
};

Expand All @@ -32,33 +32,29 @@ export const itOnly = (
): void => {
clearTests();
const test = new Mocha.Test(name, f);
mochaContext.addTest(test);
suite.addTest(test);
rootSuite.addSuite(suite);
only = true;
};

export const describe = (name: string, f: () => void): void => {
const prevMochaContext = mochaContext;
mochaContext = new Mocha.Suite(
name,
prevMochaContext.ctx,
) as MochaTypes.Suite;
prevMochaContext.addSuite(mochaContext);
suite = new Mocha.Suite(name) as MochaTypes.Suite;
rootSuite.addSuite(suite);
f();
mochaContext = prevMochaContext;
};

export const beforeEach = (f: () => void): void => {
mochaContext.beforeEach(f);
suite.beforeEach(f);
};

export const afterEach = (f: () => void): void => {
mochaContext.afterEach(f);
suite.afterEach(f);
};

export const beforeAll = (f: any) => {
mochaContext.beforeAll(f);
suite.beforeAll(f);
};

export const afterAll = (f: any) => {
mochaContext.afterAll(f);
suite.afterAll(f);
};
1 change: 1 addition & 0 deletions example/src/tests/MochaSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function runTests(...registrators: Array<() => void>) {
registrators.forEach(register => {
register();
});

runner.run();
});
return promise;
Expand Down
63 changes: 31 additions & 32 deletions example/src/tests/blob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,36 @@ let expect = chai.expect;
let db: DB;

export function blobTests() {
beforeEach(async () => {
try {
describe('Blobs', () => {
beforeEach(async () => {
try {
if (db) {
db.close();
db.delete();
}

db = open({
name: 'blobs',
encryptionKey: 'test',
});

await db.execute('DROP TABLE IF EXISTS BlobTable;');
await db.execute(
'CREATE TABLE BlobTable ( id INT PRIMARY KEY, content BLOB) STRICT;',
);
} catch (e) {
console.warn('error on before each', e);
}
});

afterAll(() => {
if (db) {
db.close();
db.delete();
// @ts-ignore
db = null;
}

db = open({
name: 'blobs',
encryptionKey: 'test',
});

await db.execute('DROP TABLE IF EXISTS BlobTable;');
await db.execute(
'CREATE TABLE BlobTable ( id INT PRIMARY KEY, content BLOB) STRICT;',
);
} catch (e) {
console.warn('error on before each', e);
}
});

afterAll(() => {
if (db) {
db.close();
db.delete();
// @ts-ignore
db = null;
}
});

describe('Blobs', () => {
});
it('ArrayBuffer', async () => {
const uint8 = new Uint8Array(2);
uint8[0] = 42;
Expand All @@ -49,7 +48,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows!._array[0].content);
const finalUint8 = new Uint8Array(result.rows?.[0].content);
expect(finalUint8[0]).to.equal(42);
});

Expand All @@ -64,7 +63,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows!._array[0].content);
const finalUint8 = new Uint8Array(result.rows?.[0].content);
expect(finalUint8[0]).to.equal(42);
});

Expand All @@ -79,7 +78,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows!._array[0].content);
const finalUint8 = new Uint8Array(result.rows?.[0].content);
expect(finalUint8[0]).to.equal(42);
});

Expand All @@ -96,7 +95,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows!._array[0].content);
const finalUint8 = new Uint8Array(result.rows?.[0].content);
expect(finalUint8[0]).to.equal(46);
});

Expand All @@ -113,7 +112,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows!._array[0].content);
const finalUint8 = new Uint8Array(result.rows?.[0].content);
expect(finalUint8[0]).to.equal(52);
});
});
Expand Down
2 changes: 1 addition & 1 deletion example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function dbSetupTests() {

const res = await db.execute('select sqlite_version();');

expect(res.rows?._array[0]['sqlite_version()']).to.equal(expectedVersion);
expect(res.rows?.[0]['sqlite_version()']).to.equal(expectedVersion);
db.close();
});

Expand Down
47 changes: 23 additions & 24 deletions example/src/tests/hooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@ const chance = new Chance();
let db: DB;

export function registerHooksTests() {
beforeEach(async () => {
try {
describe('Hooks', () => {
beforeEach(async () => {
try {
if (db) {
db.close();
db.delete();
}

db = open(DB_CONFIG);

await db.execute('DROP TABLE IF EXISTS User;');
await db.execute(
'CREATE TABLE User ( id INT PRIMARY KEY, name TEXT NOT NULL, age INT, networth REAL) STRICT;',
);
} catch (e) {
console.warn('error on before each', e);
}
});

afterAll(() => {
if (db) {
db.close();
db.delete();
// @ts-ignore
db = null;
}

db = open(DB_CONFIG);

await db.execute('DROP TABLE IF EXISTS User;');
await db.execute(
'CREATE TABLE User ( id INT PRIMARY KEY, name TEXT NOT NULL, age INT, networth REAL) STRICT;',
);
} catch (e) {
console.warn('error on before each', e);
}
});

afterAll(() => {
if (db) {
db.close();
db.delete();
// @ts-ignore
db = null;
}
});

describe('Hooks', () => {
});
// libsql does not support hooks
if (isLibsql()) {
return;
Expand Down
Loading

0 comments on commit 09b56c4

Please sign in to comment.