Skip to main content

Crate pgorm_check

Crate pgorm_check 

Source
Expand description

pgorm-check

Runtime helpers for checking whether SQL references match a live database schema.

This crate can cache schema metadata into a local directory (default: ./.pgorm/) so subsequent runs can skip a full refresh when nothing has changed.

§Features

  • Schema validation: Check if SQL queries reference valid tables and columns
  • SQL linting: Detect common issues like DELETE without WHERE, SELECT without LIMIT
  • Syntax validation: Verify SQL syntax is correct
  • Statement analysis: One-pass parse into SqlAnalysis (tables/aliases/columns/CTEs/etc)
  • Parse cache: Optional LRU SqlParseCache to reuse analysis across calls

§Example

use pgorm_check::{is_valid_sql, lint_sql, lint_select_many, delete_has_where};

// Check SQL syntax
assert!(is_valid_sql("SELECT * FROM users").valid);

// Lint for dangerous operations
let result = lint_sql("DELETE FROM users");
assert!(result.has_errors()); // Missing WHERE clause

// Check select_many patterns
let result = lint_select_many("SELECT * FROM users");
assert!(result.has_warnings()); // Missing LIMIT

// Individual checks
assert_eq!(delete_has_where("DELETE FROM users WHERE id = 1"), Some(true));

Re-exports§

pub use client::CheckClient;
pub use client::RowExt;
pub use error::CheckError;
pub use error::CheckResult;
pub use schema_cache::SchemaCache;
pub use schema_cache::SchemaCacheConfig;
pub use schema_cache::SchemaCacheLoad;
pub use schema_introspect::ColumnInfo;
pub use schema_introspect::DbSchema;
pub use schema_introspect::RelationKind;
pub use schema_introspect::TableInfo;

Modules§

client
Database client trait for pgorm-check
error
Error types for pgorm-check
schema_cache
schema_introspect