scdb-web
v1.0.4
Published
A secure SQLite-based database with a web panel, terminal CLI, and Node.js client. Uses **sql.js** (no native build). Features authentication, RBAC, and audit logging.
Downloads
304
Readme
Secure DB
A secure SQLite-based database with a web panel, terminal CLI, and Node.js client. Uses sql.js (no native build). Features authentication, RBAC, and audit logging.
Structure
- packages/core – sql.js DB, parameterized queries, auth, audit
- packages/api – HTTP API (exportable
createApp) + serves web panel - packages/web – One-line embed:
import { init } from 'scdb-web'; init(env); - packages/lib – Node.js client (
createClient,query,execute) - packages/web-panel – Panel assets (HTML/CSS/JS) served by API
- packages/cli – Terminal CLI (interactive + one-shot)
Setup
- Copy
.env.exampleto.envand setDATABASE_PATHandSESSION_SECRET. - Run
npm installin the project root. - Start the server:
npm start(API + panel at http://localhost:3000). - First time: open http://localhost:3000 and use First-time setup to create an admin user, then log in.
- Create an API key (for CLI/lib): as admin, call
POST /api-keyswith body{ "name": "cli", "role": "readwrite" }. Use the returnedkeyinSECURE_DB_API_KEY.
Usage
- Web panel: Open http://localhost:3000 — Tables, SQL editor, Audit log (admin).
- CLI:
SECURE_DB_API_KEY=yourkey npm run clifor interactive mode;npm run cli -- run "SELECT 1"ornpm run cli -- run -f query.sqlfor one-shot. - Node.js:
import { createClient } from 'scdb-lib'; const client = createClient({ url: 'http://localhost:3000', apiKey: '...' }); const rows = await client.query('SELECT * FROM users', []);
Integrating in other Node.js projects
Web (API + panel)
Install and start the server with one call:npm install scdb-webimport { init } from 'scdb-web'; init({ port: 3000, databasePath: './data/app.sqlite', sessionSecret: 'your-secret' });Optional
envkeys:port,host,databasePath,sessionSecret,docsDir.CLI
Install and run with env (or add to yourpackage.jsonscripts):npm install scdb-cli SECURE_DB_API_KEY=xxx SECURE_DB_API_URL=http://localhost:3000 npx secure-db SECURE_DB_API_KEY=xxx npx secure-db run "SELECT 1" SECURE_DB_API_KEY=xxx npx secure-db run -f script.sql
Security
- Auth: API keys and/or username/password; passwords hashed with bcrypt.
- RBAC: admin, readwrite, readonly.
- All queries are parameterized; audit log records who ran what and when.
- Use HTTPS in production.
Documentation
- Admin guide: operational steps, creating users and API keys, using the web panel, backups, and security notes – see
docs/ADMIN_GUIDE.md. - User/developer guide: how to use the CLI and Node.js client, and how roles affect what you can do – see
docs/USER_GUIDE.md.
