-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_schema_test.html
More file actions
62 lines (54 loc) · 2.13 KB
/
db_schema_test.html
File metadata and controls
62 lines (54 loc) · 2.13 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>DB Schema Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/sql-wasm.js"></script>
<script src="temp_db.js"></script>
</head>
<body>
<h1>DB Schema Tester</h1>
<script>
// Convert base64 to Uint8Array
function b64ToUint8Array(b64) {
const binString = atob(b64);
const size = binString.length;
const bytes = new Uint8Array(size);
for (let i = 0; i < size; i++) {
bytes[i] = binString.charCodeAt(i);
}
return bytes;
}
async function loadDB() {
try {
const SQL = await initSqlJs({
locateFile: file => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/${file}`
});
const buf = b64ToUint8Array(dbBase64);
const db = new SQL.Database(buf);
// Get all tables
const res = db.exec("SELECT name FROM sqlite_master WHERE type='table';");
if (res.length > 0) {
const tables = res[0].values.map(r => r[0]);
console.log("TABLES:", JSON.stringify(tables));
for (let t of tables) {
const cols = db.exec(`PRAGMA table_info('${t}');`);
console.log(`SCHEMA FOR ${t}:`, JSON.stringify(cols[0].values.map(c => c[1])));
// Get first row to see sample data
const row = db.exec(`SELECT * FROM '${t}' LIMIT 1;`);
if (row && row.length > 0) {
console.log(`SAMPLE FOR ${t}:`, JSON.stringify(row[0].values[0]));
}
}
} else {
console.log("NO_TABLES_FOUND");
}
console.log("DONE_READING_SCHEMA");
} catch (err) {
console.error("ERROR:", err.message);
}
}
loadDB();
</script>
</body>
</html>