Skip to content
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
193 changes: 121 additions & 72 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,6 @@ jobs:
- name: Typecheck files
run: yarn typecheck

test-android:
runs-on: ubuntu-latest
env:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Turn off addons
run: |
node ./scripts/turnOffEverything.js

- name: Setup
uses: ./.github/actions/setup

- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'

- name: Finalize Android SDK
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"

- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Give execute permissions to script
run: chmod +x ./scripts/test-android.sh

- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
emulator-options: -no-window -no-boot-anim -no-audio -no-snapshot-load
script: |
./scripts/test-android.sh

test-ios:
runs-on: macos-latest
steps:
Expand Down Expand Up @@ -234,55 +182,156 @@ jobs:
run: |
./scripts/test-ios.sh

test-android-sqlcipher:
test-android:
runs-on: ubuntu-latest
env:
TURBO_CACHE_DIR: .turbo/android
timeout-minutes: 20
steps:
- name: Free Disk Space (Ubuntu)
uses: insightsengineering/disk-space-reclaimer@v1
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tools-cache: false

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: false
dotnet: true
haskell: true
large-packages: true
swap-storage: true
docker-images: true

- name: Checkout
uses: actions/checkout@v4

- name: Turn on SQLCipher
- name: Turn off addons
run: |
node ./scripts/turnOnSQLCipher.js
node ./scripts/turnOffEverything.js

- name: Setup
uses: ./.github/actions/setup

- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
distribution: "temurin"
java-version: "17"

- name: Finalize Android SDK
- name: Enable KVM
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Cache Gradle
uses: actions/cache@v4
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

# - name: AVD cache
# uses: actions/cache@v4
# id: avd-cache
# with:
# path: |
# ~/.android/avd/*
# ~/.android/adb*
# key: avd-29

- name: create AVD and generate snapshot for caching
# if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
api-level: 29
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Give execute permissions to script
run: chmod +x ./scripts/test-android.sh

- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: |
./scripts/test-android.sh

test-android-sqlcipher:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Free Disk Space (Ubuntu)
uses: insightsengineering/disk-space-reclaimer@v1
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tools-cache: false

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: false
dotnet: true
haskell: true
large-packages: true
swap-storage: true
docker-images: true
- name: Checkout
uses: actions/checkout@v4

- name: Turn on SQLCipher
run: |
node ./scripts/turnOnSQLCipher.js

- name: Setup
uses: ./.github/actions/setup

- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

# - name: AVD cache
# uses: actions/cache@v4
# id: avd-cache
# with:
# path: |
# ~/.android/avd/*
# ~/.android/adb*
# key: avd-29

- name: create AVD and generate snapshot for caching
# if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Give execute permissions to script
run: chmod +x ./scripts/test-android.sh

- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
emulator-options: -no-window -no-boot-anim -no-audio -no-snapshot-load
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: |
adb wait-for-device
adb shell input keyevent 82
Expand All @@ -303,8 +352,8 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
distribution: "zulu"
java-version: "17"

- name: Finalize Android SDK
run: |
Expand Down
Binary file modified android/src/main/libsqlitevec/arm64-v8a/libsqlite_vec.so
100644 → 100755
Binary file not shown.
Binary file modified android/src/main/libsqlitevec/armeabi-v7a/libsqlite_vec.so
100644 → 100755
Binary file not shown.
Binary file modified android/src/main/libsqlitevec/x86/libsqlite_vec.so
100644 → 100755
Binary file not shown.
Binary file modified android/src/main/libsqlitevec/x86_64/libsqlite_vec.so
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion cpp/PreparedStatementHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class PreparedStatementHostObject : public jsi::HostObject {
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;

private:
std::shared_ptr<ThreadPool> _thread_pool;
#ifdef OP_SQLITE_USE_LIBSQL
DB _db;
libsql_stmt_t _stmt;
Expand All @@ -49,6 +48,7 @@ class PreparedStatementHostObject : public jsi::HostObject {
// This shouldn't be de-allocated until sqlite3_finalize is called on it
sqlite3_stmt *_stmt;
#endif
std::shared_ptr<ThreadPool> _thread_pool;
};

} // namespace opsqlite
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
FBLazyVector: 2e5b5553df729e080483373db6f045201ff4e6db
hermes-engine: 273e30e7fb618279934b0b95ffab60ecedb7acf5
op-sqlite: 137a619945c21df76fda2744680061b8f3251839
op-sqlite: a0d8cbee3fc5f8c8b67272c3b07c3b4f07b5b17f
OpServer: 9b3ebdeeb095950e760e3c39853cd06849421b35
RCTDeprecation: c6b36da89aa26090c8684d29c2868dcca2cd4554
RCTRequired: 1413a0844770d00fa1f1bb2da4680adfa8698065
Expand Down
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
"node": ">=18"
},
"op-sqlite": {
"libsql": true,
"libsql": false,
"sqlcipher": false,
"iosSqlite": false,
"fts5": true,
"rtree": true,
"crsqlite": false,
"sqliteVec": false,
"sqliteVec": true,
"performanceMode": true,
"tokenizers": [
"wordtokenizer",
Expand Down
3 changes: 3 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function App() {
const [openTime, setOpenTime] = useState(0);

useEffect(() => {
console.log("App has started 🟢")
const work = async () => {
let start = performance.now();
open({
Expand All @@ -26,9 +27,11 @@ export default function App() {

try {
const results = await runTests();
console.log("TESTS FINISHED 🟢")
setServerResults(allTestsPassed(results));
setResults(results);
} catch (e) {
console.log(`TEST FAILED 🟥 ${e}`)
setServerResults(false);
}

Expand Down
4 changes: 2 additions & 2 deletions example/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ server.get('/ping', async (_req, res) => {

server.get('/results', async (_req, res) => {
res.statusCode = 200;
res.contentType = 'application/json';
res.content = JSON.stringify({passed});
// res.json({passed}, 200);
});

server.listen(9000);
// console.log('Server listening on port 9000');
console.log('🟢 HTTP Server listening on port 9000');

export function stopServer() {
server.stop();
Expand Down
47 changes: 47 additions & 0 deletions example/src/tests/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
describe,
it,
} from '@op-engineering/op-test';
// import pkg from '../../package.json'

describe('Queries tests', () => {
let db: DB;
Expand Down Expand Up @@ -775,4 +776,50 @@ describe('Queries tests', () => {
const res = db.executeSync('PRAGMA user_version');
expect(res.rows).toDeepEqual([{user_version: 0}]);
});


// const sqliteVecEnabled = pkg?.['op-sqlite']?.sqliteVec === true;
// if (sqliteVecEnabled) {
// it('sqlite-vec extension: vector similarity search', async () => {
// // Create a virtual table for storing vectors
// await db.execute(`
// CREATE VIRTUAL TABLE vec_items USING vec0(
// embedding FLOAT[8]
// )
// `);

// // Insert some sample vectors
// await db.execute(`
// INSERT INTO vec_items(rowid, embedding)
// VALUES
// (1, '[-0.200, 0.250, 0.341, -0.211, 0.645, 0.935, -0.316, -0.924]'),
// (2, '[0.443, -0.501, 0.355, -0.771, 0.707, -0.708, -0.185, 0.362]'),
// (3, '[0.716, -0.927, 0.134, 0.052, -0.669, 0.793, -0.634, -0.162]'),
// (4, '[-0.710, 0.330, 0.656, 0.041, -0.990, 0.726, 0.385, -0.958]')
// `);

// // Perform KNN query to find the 2 nearest neighbors
// const queryVector = '[0.890, 0.544, 0.825, 0.961, 0.358, 0.0196, 0.521, 0.175]';
// const result = await db.execute(`
// SELECT rowid, distance
// FROM vec_items
// WHERE embedding MATCH ?
// ORDER BY distance
// LIMIT 2
// `, [queryVector]);

// // Verify results
// expect(result.rows.length).toEqual(2);
// expect(result.rows[0]!.rowid).toEqual(2);
// expect(result.rows[1]!.rowid).toEqual(1);

// // Verify distances are positive numbers
// const distance0 = result.rows[0]!.distance as number;
// const distance1 = result.rows[1]!.distance as number;
// expect(typeof distance0).toEqual('number');
// expect(distance0 > 0).toBeTruthy();
// expect(distance1 > 0).toBeTruthy();
// });
// }

});
Binary file modified ios/sqlitevec.xcframework/ios-arm64/sqlitevec.framework/sqlitevec
100644 → 100755
Binary file not shown.
Binary file modified ios/sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/sqlitevec
100644 → 100755
Binary file not shown.
Loading
Loading