PostgreSQL Storage
Robust, ACID-compliant storage for production workloads.
The PostgresStore uses PostgreSQL to persist rate limit data. It supports connection pooling and automatic table creation.
Installation
Pythonbash
pip install halt[postgres]TypeScriptbash
npm install pgUsage
Python
from halt.stores.postgres import PostgresStore
store = PostgresStore(
connection_string="postgresql://user:pass@localhost/db",
table_name="rate_limits", # optional
min_size=1, # pool min size
max_size=10 # pool max size
)TypeScript
import { PostgresStore } from 'halt/stores/postgres';
const store = new PostgresStore({
connectionString: 'postgresql://user:pass@localhost/db',
tableName: 'rate_limits', // optional
});Schema
Halt automatically creates a table with the following structure (if it doesn't exist):
CREATE TABLE rate_limits (
key VARCHAR(255) PRIMARY KEY,
value JSONB NOT NULL,
expires_at BIGINT NOT NULL
);
CREATE INDEX idx_rate_limits_expires ON rate_limits(expires_at);