-
Notifications
You must be signed in to change notification settings - Fork 11
/
mod.ts
73 lines (64 loc) · 1.84 KB
/
mod.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { download } from "https://deno.land/x/plug@1.0.1/mod.ts";
import meta from "./deno.json" assert { type: "json" };
const BASE = `${meta.github}/releases/download/v${meta.version}`;
// Similar to https://github.com/denodrivers/sqlite3/blob/f7529897720631c2341b713f0d78d4d668593ea9/src/ffi.ts#L561
let path: string;
try {
const customPath = Deno.env.get("DENO_SQLITE_HTTP_PATH");
if (customPath) path = customPath;
else {
path = await download({
url: {
darwin: {
x86_64: `${BASE}/deno-darwin-x86_64.http0.dylib`,
},
windows: {
x86_64: `${BASE}/deno-windows-x86_64.http0.dll`,
},
linux: {
x86_64: `${BASE}/deno-linux-x86_64.http0.so`,
},
},
suffixes: {
darwin: "",
linux: "",
windows: "",
},
});
}
} catch (e) {
if (e instanceof Deno.errors.PermissionDenied) {
throw e;
}
const error = new Error("Failed to load sqlite-http extension");
error.cause = e;
throw error;
}
/**
* Returns the full path to the compiled sqlite-http extension.
* Caution: this will not be named "http0.dylib|so|dll", since plug will
* replace the name with a hash.
*/
export function getLoadablePath(): string {
return path;
}
/**
* Entrypoint name for the sqlite-http extension.
*/
export const entrypoint = "sqlite3_http_init";
// TODO
export const entrypointNoNetwork = "sqlite3_http_no_network_init";
interface Db {
// after https://deno.land/x/sqlite3@0.8.0/mod.ts?s=Database#method_loadExtension_0
loadExtension(file: string, entrypoint?: string | undefined): void;
}
/**
* Loads the sqlite-http extension on the given sqlite3 database.
*/
export function load(db: Db): void {
db.loadExtension(path, entrypoint);
}
// TODO
export function loadNoNetwork(db: Db): void {
db.loadExtension(path, entrypointNoNetwork);
}