-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
55 lines (51 loc) · 1.7 KB
/
index.html
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
<!doctype html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="JPS" />
<title>JPS</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css" />
</head>
<body>
<script src="sql-wasm/sql-wasm.js"></script>
<script defer>
const getDatabase = async () => {
const SQL = await initSqlJs({
locateFile: (file) => `sql-wasm/${file}`,
});
const gzipFile = await fetch('data/database.db.gz');
const gzipBlob = await gzipFile.blob();
const gzipStream = new DecompressionStream('gzip');
const dbBlob = await new Response(gzipBlob.stream().pipeThrough(gzipStream)).blob();
const dbBuffer = await dbBlob.arrayBuffer();
const dbArray = new Uint8Array(dbBuffer);
const db = new SQL.Database(dbArray);
return db;
};
const getDataFromDb = (db, sql) => {
const data = [];
const select = db.exec(sql);
if (select.length > 0) {
const { columns, values } = select[0];
values.forEach((row) => {
const obj = {};
row.forEach((value, index) => {
obj[columns[index]] = value;
});
data.push(obj);
});
}
return data;
};
(async () => {
const db = await getDatabase();
const data = getDataFromDb(
db,
`SELECT orden, numero, COUNT(numero) as cantidad FROM monazos GROUP BY orden, numero`,
);
console.info(data);
})();
</script>
</body>
</html>