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 collation_config;
41pub mod dialect;
42pub mod filters;
43pub mod introspector;
44pub mod types;
45pub mod where_generator;
46
47// Shared utilities. `utils::to_snake_case` is the canonical field-name → JSONB
48// key rule, re-used by `fraiseql-core`'s entity projector so SQL and Rust
49// projection can never disagree on a source key.
50pub mod utils;
51
52// DB adapter modules (from the old db/ directory)
53pub mod collation;
54pub mod identifier;
55pub mod order_by;
56pub mod path_escape;
57pub mod projection_generator;
58pub mod traits;
59pub mod view_name;
60pub mod where_clause;
61pub mod where_sql_generator;
62
63#[cfg(feature = "postgres")]
64pub mod postgres;
65
66#[cfg(feature = "mysql")]
67pub mod mysql;
68
69#[cfg(feature = "sqlite")]
70pub mod sqlite;
71
72#[cfg(feature = "sqlserver")]
73pub mod sqlserver;
74
75#[cfg(feature = "wire-backend")]
76pub mod wire_pool;
77
78#[cfg(feature = "wire-backend")]
79pub mod fraiseql_wire_adapter;
80
81// Re-export commonly used types
82pub use collation::{CollationCapabilities, CollationMapper};
83pub use collation_config::{
84    CollationConfig, DatabaseCollationOverrides, InvalidLocaleStrategy, MySqlCollationConfig,
85    PostgresCollationConfig, SqlServerCollationConfig, SqliteCollationConfig,
86};
87pub use dialect::{
88    DialectCapabilityGuard, Feature, MySqlDialect, PostgresDialect, SqlDialect, SqlServerDialect,
89    SqliteDialect, UnsupportedOperator,
90};
91#[cfg(feature = "wire-backend")]
92pub use fraiseql_wire_adapter::FraiseWireAdapter;
93pub use identifier::{
94    quote_mysql_identifier, quote_postgres_identifier, quote_sqlite_identifier,
95    quote_sqlserver_identifier,
96};
97pub use introspector::{DatabaseIntrospector, RelationInfo, RelationKind};
98#[cfg(feature = "mysql")]
99pub use mysql::{MySqlAdapter, MySqlIntrospector};
100#[cfg(feature = "postgres")]
101pub use postgres::{PostgresAdapter, PostgresIntrospector};
102pub use projection_generator::{
103    FieldKind, MySqlProjectionGenerator, PostgresProjectionGenerator, ProjectionField,
104    SqliteProjectionGenerator,
105};
106#[cfg(feature = "sqlite")]
107pub use sqlite::{SqliteAdapter, SqliteIntrospector};
108#[cfg(feature = "sqlserver")]
109pub use sqlserver::{SqlServerAdapter, SqlServerIntrospector};
110pub use traits::{
111    ArcDatabaseAdapter, BoxDatabaseAdapter, CursorValue, DatabaseAdapter, DatabaseCapabilities,
112    DirectMutationContext, DirectMutationOp, MutationStrategy, ProjectionRequest,
113    RelayDatabaseAdapter, RelayPageResult, SupportsMutations,
114};
115pub use types::{
116    DatabaseType, JsonbValue, PoolMetrics, QueryStatEntry,
117    sql_hints::{OrderByClause, OrderByFieldType, OrderDirection, SqlProjectionHint},
118};
119pub use view_name::ViewName;
120pub use where_clause::{HavingClause, WhereClause, WhereOperator};
121pub use where_generator::GenericWhereGenerator;
122pub use where_sql_generator::WhereSqlGenerator;