import Database from 'better-sqlite3'; import { statSync } from 'node:fs'; const path = process.argv[2] ?? process.env.DB_PATH ?? './data/cherry.db'; const db = new Database(path, { readonly: true, fileMustExist: true }); try { console.table( ['', '-wal', '-shm'].map((suffix) => { try { return { file: path + suffix, bytes: statSync(path + suffix).size }; } catch (error) { if (error.code !== 'ENOENT') throw error; return { file: path + suffix, bytes: 0 }; } }) ); console.table( db .prepare( `SELECT name, ROUND(SUM(pgsize)/1048576.0, 2) AS mib FROM dbstat GROUP BY name ORDER BY SUM(pgsize) DESC LIMIT 20` ) .all() ); console.table( ['page_size', 'page_count', 'freelist_count', 'auto_vacuum'].map((pragma) => ({ pragma, value: db.pragma(pragma, { simple: true }) })) ); } finally { db.close(); }