-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys.ts
97 lines (93 loc) · 1.95 KB
/
sys.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const symbols = {
mysql_init: {
parameters: ["pointer"],
result: "pointer",
},
mysql_real_connect: {
parameters: [
"pointer",
"buffer",
"buffer",
"buffer",
"buffer",
"u32",
"buffer",
"u32",
],
result: "void",
},
mysql_real_query: {
parameters: ["pointer", "buffer", "u32"],
result: "void",
},
mysql_stmt_init: {
parameters: ["pointer"],
result: "pointer",
},
mysql_stmt_prepare: {
parameters: ["pointer", "buffer", "u32"],
result: "void",
},
mysql_stmt_execute: {
parameters: ["pointer"],
result: "void",
},
mysql_stmt_close: {
parameters: ["pointer"],
result: "void",
},
mysql_close: {
parameters: ["pointer"],
result: "void",
},
mysql_stmt_error: {
parameters: ["pointer"],
result: "pointer",
},
mysql_error: {
parameters: ["pointer"],
result: "pointer",
},
mysql_free_result: {
parameters: ["pointer"],
result: "void",
},
mysql_store_result: {
parameters: ["pointer"],
result: "pointer",
},
mysql_num_rows: {
parameters: ["pointer"],
result: "u32",
},
mysql_num_fields: {
parameters: ["pointer"],
result: "u32",
},
mysql_fetch_row: {
parameters: ["pointer"],
result: "pointer",
},
} as const;
let lib: Deno.DynamicLibrary<typeof symbols>["symbols"];
const filename = Deno.env.get("DENO_MYSQL_PATH") || {
windows: "mysqlclient",
darwin: "libmysqlclient.dylib",
linux: "libmysqlclient.so",
}[Deno.build.os];
if (!filename) {
throw new Error(`Unsupported platform: ${Deno.build.os}`);
}
try {
lib = Deno.dlopen(filename, symbols).symbols;
} catch (e) {
if (e instanceof Deno.errors.PermissionDenied) {
throw e;
}
console.log(
"%clibmysqlclient not found. Please install libmysqlclient and try again or set the DENO_MYSQL_PATH environment variable to the path of the library.",
"color: green;",
);
throw e;
}
export default lib;