PG Query Context

Secure Session Context Management

A small utility for executing PostgreSQL queries within a session context. Set session-level variables for RLS and other scoped operations with automatic transaction management.

Session Context

Set role, user ID, and custom variables

Auto Transactions

Automatic BEGIN/COMMIT with rollback on error

RLS Support

Perfect for Row-Level Security operations

PG Query Context Features

Secure and reliable session context management

Session-Level Context Setting

Set PostgreSQL session variables like role and user ID using set_config for secure, scoped operations.

Automatic Transaction Management

Automatically wraps execution in transactions with BEGIN/COMMIT and automatic rollback on errors.

Row-Level Security Support

Perfect for implementing Row-Level Security policies with proper user context and role switching.

Pool and Client Support

Works seamlessly with both pg.Pool and pg.Client instances for maximum flexibility.

Lightweight and Fast

Minimal overhead utility that focuses on doing one thing well - session context injection.

Simple API

Clean, straightforward API that makes complex session management simple and reliable.

Basic Session Context Usage

Execute PostgreSQL queries with session context variables set automatically. Perfect for implementing secure, role-based database operations.

Express.js Authentication Integration

Integrate with Express.js applications to handle authentication tokens and user context in a secure, transaction-safe manner.

Row-Level Security Implementation

Implement Row-Level Security policies by setting user roles and context variables that PostgreSQL RLS policies can use for access control.