Connect
Five ways in — Node.js, Python, HTTP, tunnel, on-server
Connect your app to the P20 database
The database itself listens on localhost only — it is never reachable from the public internet. All traffic flows encrypted through the portal's bridge, so no server IP is ever exposed. In the portal's Manage panel you get these exact snippets pre-filled with your credentials.
1. Node.js pg over WebSocket
// npm install pg ws — then (credentials pre-filled in the portal):
const WebSocket = require('ws');
const { Client } = require('pg');
const stream = require('stream');
const WS_URL = 'wss://p20kng.digamber.in/dbp/ws';
const DB = 'my-bot-db', USER = 'dbp_xxxx_ro', PASS = 'YOUR_PASSWORD';
const KEY = 'YOUR_API_KEY';
async function connect() {
const ws = new WebSocket(WS_URL + '?db=' + DB + '&key=' + KEY + '&silent=1');
await new Promise((res, rej) => { ws.once('open', res); ws.once('error', rej); });
const s = new stream.Duplex({
write(chunk, enc, cb) { ws.send(chunk, { binary: true }, cb); },
final(cb) { ws.close(); cb(); }
});
ws.on('message', (data, isBinary) => { if (isBinary) s.push(data); });
ws.on('close', () => s.push(null));
ws.on('error', (e) => s.destroy(e));
const client = new Client({ stream: s, database: DB, user: USER, password: PASS });
await client.connect();
return client;
}
2. Python HTTP SQL API
# pip install requests
import requests
API = 'https://p20kng.digamber.in/api/dbp/sql'
KEY = 'YOUR_API_KEY'
DB = 'my-bot-db'
def sql(query):
r = requests.post(API, json={'db': DB, 'key': KEY, 'sql': query}, timeout=30)
return r.json()
print(sql('SELECT version();'))
3. Any language raw HTTP / curl
curl -X POST https://p20kng.digamber.in/api/dbp/sql \
-H "Content-Type: application/json" \
-d '{"db":"my-bot-db","key":"YOUR_API_KEY","sql":"SELECT version();"}'
4. Desktop tools Tunnel — psql / DBeaver / pgAdmin / TablePlus
// Local TCP tunnel — the portal gives you a ready dbp-tunnel.js file. // npm install ws, run it, then connect ANY postgres tool to: postgresql://dbp_xxxx_ro:YOUR_PASSWORD@localhost:15432/my-bot-db
A full-screen SQL console with a one-tap command library
Click Open Terminal on the database page and a full-screen console opens. Every automation the system runs (create, rotate, export, delete) streams here live — and you can type your own SQL and helper commands. A cmds button opens a library of one-tap templates.
$ use my-bot-db ✓ attached to my-bot-db $ CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE); ✓ CREATE TABLE $ INSERT INTO users (name, email) VALUES ('Aarav', '[email protected]'); ✓ INSERT 0 1 $ SELECT * FROM users; id | name | email ----+-------+------------------- 1 | Aarav | [email protected] $ tables — list tables cols users — show columns size — db size
Helper commandshelp · status · dbs · use <name> · tables · cols <table> · size · examples · export [sql|dump] · clear
One-tap templates (cmds)create tables (basic / foreign key / JSONB) · add, rename, drop columns · insert / update / delete rows · indexes · truncate · drop table · vacuum
Terminal buttonsCopy copies the console text · Cut closes the terminal (Esc works too) · ↑↓ history · Ctrl+L clear