Proxy websocket messages to and from PostgreSQL.
Note: This dose not handle authentication and authorization, ensure you implement them at other layers.
- class pgwebsocket.Ctx(websocket: aiohttp.web_ws.WebSocketResponse, dburi: str, remote_ip: str, remote_user: str, on_connect: Callable[[...], Awaitable[bool]], on_disconnect: Callable[[...], Awaitable[bool]])¶
Context with websocket and psycopg2 connections.
- async callproc(sql: str, *args: Any) Any¶
Call a stored procedure.
- async execute(sql: str, *args: Any, **kwargs: Any) Any¶
Run an SQL query.
- fileno() int¶
Get connections fileno.
- property remote_ip: str¶
Remote IP address that created this Ctx.
- property remote_user: str¶
Remote user that created this Ctx.
- send_bytes(data: bytes) Coroutine[Any, Any, None]¶
Send bytes to websocket.
- send_str(data: str) Coroutine[Any, Any, None]¶
Send string to websocket.
- class pgwebsocket.PgWebsocket(dburl: str, bind: str = '127.0.0.1', port: int = 9000)¶
An application to handle websocket to Postgresql proxying.
- on_connect(callback: Callable[[...], Awaitable[bool]]) None¶
Register a callback after connection.
- on_disconnect(callback: Callable[[...], Awaitable[bool]]) None¶
Register a callback before disconnection.
- on_msg(route: str) Callable[[Callable[[...], Awaitable[bool]]], None]¶
Register a map of callbacks to handle diffrent messages.
Callbacks can return True to stop processing this message.
- on_transaction(callback: Callable[[...], Awaitable[bool]]) None¶
Register a callback after creating SQL transaction.
- run(url: str = '/') None¶
Start listening for connections.