Skip to main content

fraiseql_db/
lib.rs

1//! # fraiseql-db
2//!
3//! Database abstraction layer for FraiseQL v2.
4//!
5//! This crate provides database-agnostic access to multiple database backends:
6//! - PostgreSQL (primary, full feature set)
7//! - SQL Server (enterprise)
8//!
9//! It also provides the shared DB-level types used by the compilation and
10//! execution layers: SQL hint types and extended filter operators.
11
12#![forbid(unsafe_code)]
13#![deny(missing_docs)]
14// Reason: SQL identifiers in doc comments (e.g. `SELECT`, `WHERE`) are not Rust
15//         items and should not be linked; forcing backtick wrapping on every SQL
16//         keyword is noisier than the lint prevents.
17#![allow(clippy::doc_markdown)]
18// Reason: Multiple `match` arms return identical values in dialect dispatch
19//         blocks because dialects share a default behaviour; merging with `|`
20//         would lose the explicit per-dialect annotation.
21#![allow(clippy::match_same_arms)]
22// Reason: `DatabaseAdapter` implementations take many configuration parameters
23//         (view name, WHERE clause, projection, limit, offset, params…).
24//         Breaking them into per-call builder structs would add wrapper
25//         complexity without clarity gains on the hot path.
26#![allow(clippy::too_many_arguments)]
27// Reason: `match` arms that match a single enum variant and a wildcard `_`
28//         appear in dialect dispatch where the wildcard carries an explicit
29//         comment explaining the fallthrough intent (forward-compat guard on
30//         `DatabaseType`).
31#![allow(clippy::match_wildcard_for_single_variants)]
32
33/// A type alias for `Result<T, fraiseql_error::FraiseQLError>`, used throughout this crate.
34pub type Result<T> = std::result::Result<T, fraiseql_error::FraiseQLError>;
35
36// New modules (types extracted from fraiseql-core)
37pub mod changelog;
38pub mod dialect;
39pub mod introspector;
40pub mod types;
41pub mod where_generator;
42
43// Shared utilities. `utils::to_snake_case` is the canonical field-name → JSONB
44// key rule, re-used by `fraiseql-core`'s entity projector so SQL and Rust
45// projection can never disagree on a source key.
46pub mod utils;
47
48// DB adapter modules (from the old db/ directory)
49pub mod identifier;
50pub mod order_by;
51pub mod path_escape;
52pub mod projection_generator;
53pub mod traits;
54pub mod view_name;
55pub mod where_clause;
56pub mod where_sql_generator;
57
58#[cfg(feature = "postgres")]
59pub mod postgres;
60
61#[cfg(feature = "wire-backend")]
62pub mod wire_pool;
63
64#[cfg(feature = "wire-backend")]
65pub mod fraiseql_wire_adapter;
66
67// Re-export commonly used types
68pub use changelog::{
69    CDC_MEDIATED_ON, CDC_MEDIATED_VAR, CLOCK_TIMESTAMP_DIRECTIVE, DURATION_CALC_VERSION,
70    STARTED_AT_VAR, duration_ms_sql,
71};
72pub use dialect::{PostgresDialect, SqlDialect, UnsupportedOperator};
73#[cfg(feature = "wire-backend")]
74pub use fraiseql_wire_adapter::FraiseWireAdapter;
75pub use identifier::quote_postgres_identifier;
76pub use introspector::{DatabaseIntrospector, RelationInfo, RelationKind};
77#[cfg(feature = "postgres")]
78pub use postgres::{PostgresAdapter, PostgresIntrospector};
79pub use projection_generator::{FieldKind, PostgresProjectionGenerator, ProjectionField};
80/// The `serde_json` this crate's public API is built against (#1198).
81pub use serde_json;
82/// The `tokio_postgres` this crate's public API is built against (#1198).
83#[cfg(feature = "postgres")]
84pub use tokio_postgres;
85pub use traits::{
86    AdminSqlOutcome, AdminSqlRequest, ArcDatabaseAdapter, BoxDatabaseAdapter,
87    COMPOSED_DOCUMENT_KEY, COMPOSED_EMBEDS_KEY, ChangeLogWrite, ColumnRowStream, ComposedEmbed,
88    ComposedKeyset, ComposedLevel, CursorValue, DatabaseAdapter, EmbedShape, EmbedSource,
89    JsonbRowStream, LevelKeys, MutationRowGate, ProjectionRequest, RelayDatabaseAdapter,
90    RelayPageResult, ResultCacheStats, WriteMode, WriteRequest, Writer, composed_read_unsupported,
91};
92pub use types::{
93    DatabaseType, JsonbValue, PoolMetrics, QueryStatEntry,
94    sql_hints::{
95        OrderByClause, OrderDirection, RelevanceOrder, ScalarFieldType, SqlProjectionHint,
96        VectorDistanceOrder, VectorOperandKind,
97    },
98};
99/// The `uuid` this crate's public API is built against (#1198).
100pub use uuid;
101pub use view_name::ViewName;
102pub use where_clause::{HavingClause, WhereClause, WhereOperator};
103pub use where_generator::GenericWhereGenerator;
104pub use where_sql_generator::WhereSqlGenerator;