Files
Baradb/docs/bg/api-websocket.md
dimgigov c55d3080cf
CI / test (push) Has been cancelled
CI / verify (push) Has been cancelled
Clients CI / build-server (push) Has been cancelled
Clients CI / test-python (push) Has been cancelled
Clients CI / test-javascript (push) Has been cancelled
Clients CI / test-nim (push) Has been cancelled
Clients CI / test-rust (push) Has been cancelled
Update documentation and clients for v1.1.0
Documentation updates:
- Fix v0.1.0 → v1.1.0 version numbers in en, ru, fa, zh docs
- Add missing Window Functions, Multi-Tenant ERP, Supported Keywords sections
  to ru, fa, zh baraql.md (~105 lines each)
- Expand Turkish and Arabic baraql.md (110 → 268 lines)
- Expand Turkish and Arabic installation.md (62 → 307 lines)
- Add new Bulgarian documentation files (18 new files)

Client updates:
- Python: Full async/await rewrite with asyncio, request queueing
- Rust: Full async/await rewrite with tokio, async examples
- Nim: Update README to v1.1.0
- All clients now support async patterns consistently
2026-05-14 23:05:47 +03:00

2.0 KiB

WebSocket API

Full-duplex стрийминг за данни в реално време и push известия.

Свързване

ws://localhost:9471

Клиентски Пример

const ws = new WebSocket('ws://localhost:9471');

ws.onopen = () => {
  console.log('Свързан');
  ws.send(JSON.stringify({
    type: 'query',
    query: 'SELECT * FROM users'
  }));
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Получено:', data);
};

Формат на Съобщенията

{
  "type": "query",
  "id": "1",
  "query": "SELECT * FROM users"
}

Типове Съобщения

Заявка (query)

{
  "type": "query",
  "id": "1",
  "query": "SELECT * FROM users"
}

Резултат (result)

{
  "type": "result",
  "id": "1",
  "columns": ["id", "name"],
  "rows": [["1", "Alice"], ["2", "Bob"]]
}

Грешка (error)

{
  "type": "error",
  "id": "1",
  "code": "INVALID_QUERY",
  "message": "Синтактична грешка"
}

Абониране (subscribe)

Абониране за промени в таблица:

{
  "type": "subscribe",
  "id": "sub1",
  "table": "users"
}

Известие (notification)

Push известие от сървъра:

{
  "type": "notification",
  "table": "users",
  "operation": "insert",
  "data": {"id": 3, "name": "Charlie"}
}

Ping/Pong (keepalive)

{"type": "ping", "id": "ping1"}

Отговор:

{"type": "pong", "id": "ping1"}

JavaScript Клиент

class BaraDBClient {
  constructor(url) {
    this.ws = new WebSocket(url);
    this.pending = new Map();
  }

  query(sql) {
    return new Promise((resolve, reject) => {
      const id = crypto.randomUUID();
      this.pending.set(id, { resolve, reject });
      this.ws.send(JSON.stringify({ type: 'query', id, query: sql }));
    });
  }
}