forked from asg017/sqlite-vec
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.mjs
More file actions
32 lines (25 loc) · 844 Bytes
/
index.mjs
File metadata and controls
32 lines (25 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { arch, platform } from "node:process";
import { statSync } from "node:fs";
const ENTRYPOINT_BASE_NAME = "vec0";
function extensionSuffix(platform) {
if (platform === "win32") return "dll";
if (platform === "darwin") return "dylib";
return "so";
}
function getLoadablePath() {
const loadablePath = join(
fileURLToPath(new URL(".", import.meta.url)),
"dist",
`${ENTRYPOINT_BASE_NAME}.${extensionSuffix(platform)}`
);
if (!statSync(loadablePath, { throwIfNoEntry: false })) {
throw new Error(`Loadable extension for sqlite-vec not found at ${loadablePath}. Was the extension built? Run: make loadable`);
}
return loadablePath;
}
function load(db) {
db.loadExtension(getLoadablePath());
}
export { getLoadablePath, load };