Skip to content

~3KB Lightweight server that exposes your database over HTTP API. Supports SQLite, PostgreSQL, and MySQL.

License

Notifications You must be signed in to change notification settings

unproducts/db-studio

Repository files navigation

DB Studio

npm version npm downloads

Lightweight server that exposes your database over HTTP API. Ships with a minimal UI and CLI. Supports SQLite, PostgreSQL, and MySQL.

Think of it as light weight Drizzle studio.

DB Studio Screenshot

Installation

npm install @unproducts/db-studio

CLI

# SQLite
npx db-studio --db sqlite --path ./mydb.sqlite

# PostgreSQL
npx db-studio --db postgresql --url "postgres://user:pass@localhost:5432/mydb"

# MySQL
npx db-studio --db mysql --dbHost localhost --dbUser root --dbName mydb

Server starts on http://localhost:3000 by default. Use --port and --host to customize.

Programmatic Usage

High-level: createServer

Use createServer to quickly spin up a standalone HTTP server:

import { createServer } from "@unproducts/db-studio";

const server = await createServer({
  db: "sqlite",
  connectionOptions: { path: "./mydb.sqlite" },
  host: "localhost",
  port: 3000,
  serveUI: true, // Enable built-in UI
});

server.serve();

Set serveUI: true to serve the built-in web UI alongside the API endpoints. The UI will be available at the root path (/).

Low-level: createHandler

Use createHandler to get a fetch-compatible request handler that you can integrate with any server framework:

import { createHandler } from "@unproducts/db-studio";

const handler = await createHandler({
  db: "sqlite",
  connectionOptions: { path: "./mydb.sqlite" },
  serveUI: true, // Enable built-in UI
});

// Use with Bun
Bun.serve({ fetch: handler, port: 3000 });

// Use with Deno
Deno.serve({ port: 3000 }, handler);

// Use with Node.js (via adapters like @hono/node-server)

Connection Options

SQLite

connectionOptions: { path: "./mydb.sqlite" }

PostgreSQL

// Using URL
connectionOptions: { url: "postgres://user:pass@localhost:5432/mydb" }

// Using individual options
connectionOptions: {
  host: "localhost",
  port: 5432,
  user: "user",
  password: "pass",
  database: "mydb",
}

MySQL

connectionOptions: {
  host: "localhost",
  port: 3306,
  user: "root",
  password: "pass",
  database: "mydb",
}

Endpoints

POST /actions

High-level database operations.

# List tables
curl -X POST http://localhost:3000/actions \
  -H "Content-Type: application/json" \
  -d '{"action": "getTables"}'

# Get table columns
curl -X POST http://localhost:3000/actions \
  -H "Content-Type: application/json" \
  -d '{"action": "getTableInfo", "table": "users"}'

GET|POST /raw

Execute raw SQL queries.

# SELECT (GET)
curl "http://localhost:3000/raw?sql=SELECT%20*%20FROM%20users"

# INSERT/UPDATE/DELETE (POST)
curl -X POST http://localhost:3000/raw \
  -H "Content-Type: application/json" \
  -d '{"sql": "INSERT INTO users (name) VALUES (?)", "params": ["Alice"]}'

License

Published under the MIT license. Made by community 💛

About

~3KB Lightweight server that exposes your database over HTTP API. Supports SQLite, PostgreSQL, and MySQL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published