Newer
Older
TelosDB / scripts / test_dll.js
import Database from 'better-sqlite3';
import { join } from 'path';

const db = new Database(':memory:');
const dllPath = join(process.cwd(), 'vector.dll');

console.log(`Testing DLL at: ${dllPath}`);

try {
    // Load extension
    db.loadExtension(dllPath);
    console.log('✅ Success: loadExtension(path)');

    const version = db.prepare('SELECT vector_version()').get();
    console.log(`Vector Version: ${Object.values(version)[0]}`);

    db.prepare('CREATE TABLE test_items (id INTEGER PRIMARY KEY, embedding BLOB)').run();
    db.prepare("SELECT vector_init('test_items', 'embedding', 'type=FLOAT32,dimension=4')").get();
    console.log('✅ Success: vector_init');
} catch (err) {
    console.error('❌ Failed: loadExtension(path)');
    console.error(err.message);

    try {
        // Try without extension
        const pathNoExt = dllPath.replace(/\.dll$/, '');
        console.log(`Trying without .dll: ${pathNoExt}`);
        db.loadExtension(pathNoExt);
        console.log('✅ Success: loadExtension(pathWithoutExt)');
    } catch (err2) {
        console.error('❌ Failed: loadExtension(pathWithoutExt)');
        console.error(err2.message);

        try {
            // Try with explicit entry point
            console.log('Trying with explicit entry point: sqlite3_vector_init');
            db.loadExtension(dllPath, 'sqlite3_vector_init');
            console.log('✅ Success: loadExtension(path, "sqlite3_vector_init")');
        } catch (err3) {
            console.error('❌ Failed: loadExtension(path, "sqlite3_vector_init")');
            console.error(err3.message);
        }
    }
}

db.close();