postrust_core/lib.rs
1//! Postrust Core - PostgREST-compatible REST API for PostgreSQL in Rust.
2//!
3//! This crate provides the core functionality for Postrust, a serverless
4//! alternative to PostgREST written in Rust.
5//!
6//! # Architecture
7//!
8//! The request processing pipeline:
9//!
10//! 1. **API Request Parsing** (`api_request`) - Parse HTTP request into domain types
11//! 2. **Schema Cache** (`schema_cache`) - PostgreSQL metadata for validation
12//! 3. **Query Planning** (`plan`) - Convert request to execution plan
13//! 4. **SQL Generation** (`query`) - Generate parameterized SQL
14//! 5. **Response Formatting** - Format results for HTTP response
15//!
16//! # Example
17//!
18//! ```text
19//! use postrust_core::{ApiRequest, SchemaCache, create_action_plan};
20//!
21//! // Parse HTTP request
22//! let request = parse_request(&http_request, "public", &schemas)?;
23//!
24//! // Create execution plan
25//! let plan = create_action_plan(&request, &schema_cache)?;
26//!
27//! // Generate SQL
28//! let (sql, params) = build_query(&plan)?;
29//! ```
30
31#![warn(missing_docs)]
32// The `Error` enum carries a rich `DatabaseError` payload (PostgREST-style error
33// bodies), which makes it larger than clippy's `Result`/enum size thresholds.
34// Boxing it would ripple through every construction site for little benefit, so
35// the size lints are allowed crate-wide instead.
36#![allow(clippy::result_large_err)]
37#![allow(clippy::large_enum_variant)]
38
39pub mod api_request;
40pub mod config;
41pub mod db;
42pub mod embed;
43pub mod error;
44pub mod plan;
45pub mod query;
46#[cfg(feature = "sqlx")]
47pub mod row_json;
48pub mod schema_cache;
49
50// Re-export main types
51pub use api_request::{
52 parse_request, Action, ApiRequest, DbAction, Filter, LogicTree, MediaType, Mutation, Operation,
53 Payload, PreferRepresentation, Preferences, QualifiedIdentifier, QueryParams, Range, Resource,
54 SelectItem,
55};
56pub use config::{AppConfig, ConfigError, IsolationLevel, LogLevel, OpenApiMode};
57pub use embed::EmbedRendering;
58pub use error::{Error, Result};
59pub use plan::{create_action_plan, ActionPlan, CallPlan, DbActionPlan, MutatePlan, ReadPlan};
60pub use schema_cache::{Column, Relationship, Routine, SchemaCache, SchemaCacheRef, Table};
61
62/// This crate's version. A schema cache serialized by one version may not
63/// read back, or may not mean the same, in another, so a copy kept outside
64/// the process -- the Cloudflare Worker's, in KV -- is keyed by it.
65pub const VERSION: &str = env!("CARGO_PKG_VERSION");
66
67/// Prelude for common imports.
68pub mod prelude {
69 pub use super::api_request::{
70 parse_request, Action, ApiRequest, Filter, MediaType, Preferences, QualifiedIdentifier,
71 QueryParams, Range, SelectItem,
72 };
73 pub use super::config::AppConfig;
74 pub use super::error::{Error, Result};
75 pub use super::plan::{create_action_plan, ActionPlan};
76 pub use super::schema_cache::{SchemaCache, SchemaCacheRef, Table};
77}