Module postgresql

Module postgresql 

Source
Expand description

PostgreSQL storage backend implementation

This module provides a production-ready PostgreSQL storage backend for the LLM Auto-Optimizer. It implements both the Storage and RelationalStorage traits, providing full ACID compliance, connection pooling, prepared statements, and comprehensive error handling.

§Features

  • Connection pooling with sqlx::PgPool
  • Prepared statements for security and performance
  • Transaction support with full ACID guarantees
  • Optimistic locking with version checking
  • Batch operations for high throughput
  • Index management and query optimization
  • Schema migrations support
  • Comprehensive error handling and logging
  • Thread-safe operations with Arc

§Schema

The backend uses a flexible schema that supports all entity types:

CREATE TABLE storage_entries (
    table_name VARCHAR(255) NOT NULL,
    key VARCHAR(255) NOT NULL,
    value JSONB NOT NULL,
    version BIGINT NOT NULL DEFAULT 1,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    expires_at TIMESTAMPTZ,
    metadata JSONB,
    PRIMARY KEY (table_name, key)
);
CREATE INDEX idx_expires_at ON storage_entries(table_name, expires_at) WHERE expires_at IS NOT NULL;
CREATE INDEX idx_updated_at ON storage_entries(table_name, updated_at);

Structs§

PostgreSQLStorage
PostgreSQL storage backend