forked from tmotagam/sqlite-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
101 lines (98 loc) · 4.04 KB
/
preload.js
File metadata and controls
101 lines (98 loc) · 4.04 KB
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
98
99
100
101
const { contextBridge, ipcRenderer } = require('electron')
window.addEventListener('DOMContentLoaded', async () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
contextBridge.exposeInMainWorld('api', {
path: async () => {
const path = document.getElementById('dbpath').value
const isuri = document.getElementById('isuri').checked
try {
const res = await ipcRenderer.invoke('potd', path, isuri);
document.getElementById('pout').innerText = 'Output: ' + res;
} catch (error) {
document.getElementById('pout').innerText = 'Output: ' + error;
}
},
equery: async () => {
const query = document.getElementById('singlequery').value
const values = document.getElementById('value').value
try {
const arr = JSON.parse("[" + values + "]");
const res = await ipcRenderer.invoke('executeQuery', query, arr[0]);
document.getElementById('pout1').innerText = 'Output: ' + res;
} catch (error) {
document.getElementById('pout1').innerText = 'Output: ' + error;
}
},
fetchall: async () => {
const query = document.getElementById('fetchallquery').value
const values = document.getElementById('fetchallvalue').value
try {
const arr = JSON.parse("[" + values + "]");
const res = await ipcRenderer.invoke('fetchall', query, arr[0]);
document.getElementById('poutfa').innerText = 'Output: ' + JSON.stringify(res);
} catch (error) {
document.getElementById('poutfa').innerText = 'Output: ' + error;
}
},
fetchone: async () => {
const query = document.getElementById('fetchonequery').value
const values = document.getElementById('fetchonevalue').value
try {
const arr = JSON.parse("[" + values + "]");
const res = await ipcRenderer.invoke('fetchone', query, arr[0]);
document.getElementById('poutfo').innerText = 'Output: ' + JSON.stringify(res);
} catch (error) {
document.getElementById('poutfo').innerText = 'Output: ' + error;
}
},
fetchmany: async () => {
const query = document.getElementById('fetchmanyquery').value
const values = document.getElementById('fetchmanyvalue').value
const size = Number(document.getElementById('fetchmanysize').value)
try {
const arr = JSON.parse("[" + values + "]");
const res = await ipcRenderer.invoke('fetchmany', query, size, arr[0]);
document.getElementById('poutfm').innerText = 'Output: ' + JSON.stringify(res);
} catch (error) {
document.getElementById('poutfm').innerText = 'Output: ' + error;
}
},
mquery: async () => {
const query = document.getElementById('query').value
const values = document.getElementById('values').value
try {
const arr = JSON.parse("[" + values + "]");
const res = await ipcRenderer.invoke('executeMany', query, arr[0]);
document.getElementById('pout2').innerText = 'Output: ' + res;
} catch (error) {
document.getElementById('pout2').innerText = 'Output: ' + error;
}
},
escript: async () => {
const spath = document.getElementById('scriptPath').value
const res = await ipcRenderer.invoke('executeScript', spath);
document.getElementById('pout3').innerText = 'Output: ' + res;
},
load_extension: async () => {
const path = document.getElementById('extensionPath').value
const res = await ipcRenderer.invoke('load_extension', path);
console.log(res);
document.getElementById('pout4').innerText = 'Output: ' + res;
},
backup: async () => {
const target = document.getElementById('backupPath').value
const pages = document.getElementById('pages').value
const name = document.getElementById('name').value
const sleep = document.getElementById('sleep').value
const res = await ipcRenderer.invoke('backup', target, pages, name, sleep);
console.log(res);
document.getElementById('pout5').innerText = 'Output: ' + res;
}
})