forked from bitfoundation/bitplatform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbit-besql.js
More file actions
51 lines (37 loc) · 1.42 KB
/
bit-besql.js
File metadata and controls
51 lines (37 loc) · 1.42 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
var BitBesql = window.BitBesql || {};
BitBesql.version = window['bit-besql version'] = '10.4.3-pre-01';
BitBesql.persist = async function besqlPersist(fileName) {
if (BitBesql.dbCache == null) {
BitBesql.dbCache = await caches.open('bit-Besql');
}
const dbCache = BitBesql.dbCache;
const sqliteFilePath = `/${fileName}`;
const cacheStorageFilePath = `/data/cache/${fileName}`;
if (!window.Blazor.runtime.Module.FS.analyzePath(sqliteFilePath).exists)
throw new Error(`Database ${fileName} not found.`);
const data = window.Blazor.runtime.Module.FS.readFile(sqliteFilePath);
const blob = new Blob([data], {
type: 'application/octet-stream',
status: 200
});
const headers = new Headers({
'content-length': blob.size
});
const response = new Response(blob, {
headers
});
await dbCache.put(cacheStorageFilePath, response);
}
BitBesql.load = async function besqlLoad(fileName) {
const sqliteFilePath = `/${fileName}`;
const cacheStorageFilePath = `/data/cache/${fileName}`;
BitBesql.dbCache = await caches.open('bit-Besql');
const dbCache = BitBesql.dbCache;
const resp = await dbCache.match(cacheStorageFilePath);
if (resp && resp.ok) {
const res = await resp.arrayBuffer();
if (res) {
window.Blazor.runtime.Module.FS.writeFile(sqliteFilePath, new Uint8Array(res));
}
}
}