Skip to content

Commit 3e10e31

Browse files
committed
feat: implement client-side SQLite with WASM, add demo database, and finalize deployment config
1 parent eaa4770 commit 3e10e31

27 files changed

Lines changed: 32576 additions & 2451 deletions

package-lock.json

Lines changed: 9 additions & 329 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
"ip-rate-limit": "^1.1.0",
2626
"jspdf": "^4.0.0",
2727
"lucide-react": "^0.562.0",
28-
"mongoose": "^9.1.4",
29-
"mysql2": "^3.16.1",
3028
"next": "16.1.4",
3129
"next-intl": "^4.8.0",
3230
"next-sitemap": "^4.2.3",
@@ -36,6 +34,7 @@
3634
"react-google-recaptcha": "^3.1.0",
3735
"react-icons": "^5.5.0",
3836
"sanitize-html": "^2.17.0",
37+
"sql.js": "^1.8.0",
3938
"tailwind-merge": "^3.4.0",
4039
"uuid": "^13.0.0",
4140
"xss": "^1.0.15"
@@ -62,4 +61,4 @@
6261
"@types/react": "19.2.9",
6362
"@types/react-dom": "19.2.3"
6463
}
65-
}
64+
}

prisma_demo.db

24 KB
Binary file not shown.

public/lighthouse-report-prod.report.html

Lines changed: 2897 additions & 0 deletions
Large diffs are not rendered by default.

public/lighthouse-report-prod.report.json

Lines changed: 12189 additions & 0 deletions
Large diffs are not rendered by default.

public/lighthouse-report.html

Lines changed: 2897 additions & 0 deletions
Large diffs are not rendered by default.

public/lighthouse-report.json

Lines changed: 13675 additions & 0 deletions
Large diffs are not rendered by default.

public/sql-wasm.js

Lines changed: 194 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/sql-wasm.wasm

599 KB
Binary file not shown.

scripts/generate_db.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
const fs = require('fs');
3+
const initSqlJs = require('sql.js');
4+
const path = require('path');
5+
6+
async function main() {
7+
const SQL = await initSqlJs();
8+
const db = new SQL.Database();
9+
10+
console.log("Creating tables...");
11+
db.run(`
12+
CREATE TABLE IF NOT EXISTS warga (
13+
id INTEGER PRIMARY KEY AUTOINCREMENT,
14+
nama TEXT NOT NULL,
15+
alamat TEXT,
16+
status TEXT,
17+
telepon TEXT
18+
);
19+
20+
CREATE TABLE IF NOT EXISTS security_reports (
21+
id INTEGER PRIMARY KEY AUTOINCREMENT,
22+
jenis_kejadian TEXT,
23+
lokasi TEXT,
24+
tanggal_kejadian TEXT,
25+
status TEXT,
26+
priority TEXT,
27+
nama_pelapor TEXT,
28+
telepon_pelapor TEXT,
29+
kronologi TEXT
30+
);
31+
32+
CREATE TABLE IF NOT EXISTS users (
33+
id INTEGER PRIMARY KEY AUTOINCREMENT,
34+
email TEXT UNIQUE,
35+
password TEXT,
36+
nama TEXT,
37+
role TEXT,
38+
no_telepon TEXT
39+
);
40+
`);
41+
42+
console.log("Seeding demo users...");
43+
// Demo data based on previous context
44+
const users = [
45+
{ email: 'admin@rt0409.local', password: 'password123', nama: 'Admin RT', role: 'admin', phone: '081234567890' },
46+
{ email: 'warga@rt0409.local', password: 'password123', nama: 'Budi Warga', role: 'warga', phone: '081234567891' },
47+
{ email: 'pengurus@rt0409.local', password: 'password123', nama: 'Siti Pengurus', role: 'pengurus', phone: '081234567892' }
48+
];
49+
50+
const stmt = db.prepare("INSERT INTO users (email, password, nama, role, no_telepon) VALUES (?, ?, ?, ?, ?)");
51+
users.forEach(u => stmt.run([u.email, u.password, u.nama, u.role, u.phone]));
52+
stmt.free();
53+
54+
console.log("Seeding 50 random warga...");
55+
db.run("BEGIN TRANSACTION");
56+
const stmtWarga = db.prepare("INSERT INTO warga (nama, alamat, status, telepon) VALUES (?, ?, ?, ?)");
57+
58+
const names = ["Andi", "Budi", "Citra", "Dedi", "Eka", "Fani", "Gita", "Hadi", "Indah", "Joko"];
59+
const lastNames = ["Santoso", "Wijaya", "Putri", "Kusuma", "Lestari", "Pratama", "Saputra", "Hidayat", "Sari", "Utami"];
60+
const streets = ["Mawar", "Melati", "Anggrek", "Kenanga", "Flamboyan", "Dahlia", "Tulip"];
61+
62+
for (let i = 0; i < 50; i++) {
63+
const name = `${names[Math.floor(Math.random() * names.length)]} ${lastNames[Math.floor(Math.random() * lastNames.length)]}`;
64+
const address = `Jl. ${streets[Math.floor(Math.random() * streets.length)]} No. ${Math.floor(Math.random() * 100)}`;
65+
const status = Math.random() > 0.3 ? "Tetap" : "Kontrak";
66+
const phone = `0812${Math.floor(Math.random() * 100000000)}`;
67+
68+
stmtWarga.run([name, address, status, phone]);
69+
}
70+
stmtWarga.free();
71+
db.run("COMMIT");
72+
73+
console.log("Saving to prisma_demo.db...");
74+
const data = db.export();
75+
const buffer = Buffer.from(data);
76+
fs.writeFileSync(path.join(__dirname, '../prisma_demo.db'), buffer);
77+
console.log("Done!");
78+
}
79+
80+
main().catch(console.error);

0 commit comments

Comments
 (0)