postgres

command
v0.0.0-...-fba9b4b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Example: Loading blocklist rules from PostgreSQL using sqlx

This example demonstrates how to implement a custom RuleLoader that fetches blocking rules from a PostgreSQL database using sqlx.

Required table schema:

CREATE TABLE blocklist (
    id SERIAL PRIMARY KEY,
    rule_type VARCHAR(10) NOT NULL CHECK (rule_type IN ('domain', 'url', 'regex')),
    pattern VARCHAR(500) NOT NULL,
    reason VARCHAR(255) DEFAULT 'blocked by policy',
    category VARCHAR(100),
    enabled BOOLEAN DEFAULT true,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX idx_blocklist_enabled ON blocklist(enabled) WHERE enabled = true;

To run this example:

go get github.com/jmoiron/sqlx
go get github.com/lib/pq
DATABASE_URL="postgres://user:pass@localhost/dbname?sslmode=disable" go run main.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL