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//! - MySQL (secondary support)
8//! - SQLite (local dev, testing)
9//! - SQL Server (enterprise)
10//!
11//! It also provides the shared DB-level types used by the compilation and
12//! execution layers: collation configuration, SQL hint types, and extended
13//! filter operators.
14
15#![forbid(unsafe_code)]
16#![deny(missing_docs)]
17// Reason: SQL identifiers in doc comments (e.g. `SELECT`, `WHERE`) are not Rust
18//         items and should not be linked; forcing backtick wrapping on every SQL
19//         keyword is noisier than the lint prevents.
20#![allow(clippy::doc_markdown)]
21// Reason: Multiple `match` arms return identical values in dialect dispatch
22//         blocks because dialects share a default behaviour; merging with `|`
23//         would lose the explicit per-dialect annotation.
24#![allow(clippy::match_same_arms)]
25// Reason: `DatabaseAdapter` implementations take many configuration parameters
26//         (view name, WHERE clause, projection, limit, offset, params…).
27//         Breaking them into per-call builder structs would add wrapper
28//         complexity without clarity gains on the hot path.
29#![allow(clippy::too_many_arguments)]
30// Reason: `match` arms that match a single enum variant and a wildcard `_`
31//         appear in dialect dispatch where the wildcard carries an explicit
32//         comment explaining the fallthrough intent (forward-compat guard on
33//         `DatabaseType`).
34#![allow(clippy::match_wildcard_for_single_variants)]
35
36/// A type alias for `Result<T, fraiseql_error::FraiseQLError>`, used throughout this crate.
37pub type Result<T> = std::result::Result<T, fraiseql_error::FraiseQLError>;
38
39// New modules (types extracted from fraiseql-core)
40pub mod changelog;
41pub mod collation_config;
42pub mod dialect;
43pub mod filters;
44pub mod introspector;
45pub mod types;
46pub mod where_generator;
47
48// Shared utilities. `utils::to_snake_case` is the canonical field-name → JSONB
49// key rule, re-used by `fraiseql-core`'s entity projector so SQL and Rust
50// projection can never disagree on a source key.
51pub mod utils;
52
53// DB adapter modules (from the old db/ directory)
54pub mod collation;
55pub mod identifier;
56pub mod order_by;
57pub mod path_escape;
58pub mod projection_generator;
59pub mod traits;
60pub mod view_name;
61pub mod where_clause;
62pub mod where_sql_generator;
63
64#[cfg(feature = "postgres")]
65pub mod postgres;
66
67#[cfg(feature = "mysql")]
68pub mod mysql;
69
70#[cfg(feature = "sqlite")]
71pub mod sqlite;
72
73#[cfg(feature = "sqlserver")]
74pub mod sqlserver;
75
76#[cfg(feature = "wire-backend")]
77pub mod wire_pool;
78
79#[cfg(feature = "wire-backend")]
80pub mod fraiseql_wire_adapter;
81
82// Re-export commonly used types
83pub use changelog::{
84    CDC_MEDIATED_ON, CDC_MEDIATED_VAR, CLOCK_TIMESTAMP_DIRECTIVE, DURATION_CALC_VERSION,
85    STARTED_AT_VAR, duration_ms_sql,
86};
87pub use collation::{CollationCapabilities, CollationMapper};
88pub use collation_config::{
89    CollationConfig, DatabaseCollationOverrides, InvalidLocaleStrategy, MySqlCollationConfig,
90    PostgresCollationConfig, SqlServerCollationConfig, SqliteCollationConfig,
91};
92pub use dialect::{
93    DialectCapabilityGuard, Feature, MySqlDialect, PostgresDialect, SqlDialect, SqlServerDialect,
94    SqliteDialect, UnsupportedOperator,
95};
96#[cfg(feature = "wire-backend")]
97pub use fraiseql_wire_adapter::FraiseWireAdapter;
98pub use identifier::{
99    quote_mysql_identifier, quote_postgres_identifier, quote_sqlite_identifier,
100    quote_sqlserver_identifier,
101};
102pub use introspector::{DatabaseIntrospector, RelationInfo, RelationKind};
103#[cfg(feature = "mysql")]
104pub use mysql::{MySqlAdapter, MySqlIntrospector};
105#[cfg(feature = "postgres")]
106pub use postgres::{PostgresAdapter, PostgresIntrospector};
107pub use projection_generator::{
108    FieldKind, MySqlProjectionGenerator, PostgresProjectionGenerator, ProjectionField,
109    SqliteProjectionGenerator,
110};
111#[cfg(feature = "sqlite")]
112pub use sqlite::{SqliteAdapter, SqliteIntrospector};
113#[cfg(feature = "sqlserver")]
114pub use sqlserver::{SqlServerAdapter, SqlServerIntrospector};
115pub use traits::{
116    ArcDatabaseAdapter, BoxDatabaseAdapter, ChangeLogWrite, CursorValue, DatabaseAdapter,
117    DatabaseCapabilities, DirectMutationContext, DirectMutationOp, MutationStrategy,
118    ProjectionRequest, RelayDatabaseAdapter, RelayPageResult, SupportsMutations,
119};
120pub use types::{
121    DatabaseType, JsonbValue, PoolMetrics, QueryStatEntry,
122    sql_hints::{OrderByClause, OrderByFieldType, OrderDirection, SqlProjectionHint},
123};
124pub use view_name::ViewName;
125pub use where_clause::{HavingClause, WhereClause, WhereOperator};
126pub use where_generator::GenericWhereGenerator;
127pub use where_sql_generator::WhereSqlGenerator;