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// DB adapter modules (from the old db/ directory)
48pub mod collation;
49pub mod identifier;
50pub mod path_escape;
51pub mod projection_generator;
52pub mod traits;
53pub mod where_clause;
54pub mod where_sql_generator;
55
56#[cfg(feature = "postgres")]
57pub mod postgres;
58
59#[cfg(feature = "mysql")]
60pub mod mysql;
61
62#[cfg(feature = "sqlite")]
63pub mod sqlite;
64
65#[cfg(feature = "sqlserver")]
66pub mod sqlserver;
67
68#[cfg(feature = "wire-backend")]
69pub mod wire_pool;
70
71#[cfg(feature = "wire-backend")]
72pub mod fraiseql_wire_adapter;
73
74// Re-export commonly used types
75pub use collation::{CollationCapabilities, CollationMapper};
76pub use collation_config::{
77    CollationConfig, DatabaseCollationOverrides, InvalidLocaleStrategy, MySqlCollationConfig,
78    PostgresCollationConfig, SqlServerCollationConfig, SqliteCollationConfig,
79};
80pub use dialect::{
81    DialectCapabilityGuard, Feature, MySqlDialect, PostgresDialect, SqlDialect, SqlServerDialect,
82    SqliteDialect, UnsupportedOperator,
83};
84#[cfg(feature = "wire-backend")]
85pub use fraiseql_wire_adapter::FraiseWireAdapter;
86pub use identifier::{
87    quote_mysql_identifier, quote_postgres_identifier, quote_sqlite_identifier,
88    quote_sqlserver_identifier,
89};
90pub use introspector::{DatabaseIntrospector, RelationInfo, RelationKind};
91#[cfg(feature = "mysql")]
92pub use mysql::MySqlAdapter;
93#[cfg(feature = "postgres")]
94pub use postgres::{PostgresAdapter, PostgresIntrospector};
95pub use projection_generator::{
96    MySqlProjectionGenerator, PostgresProjectionGenerator, ProjectionField,
97    SqliteProjectionGenerator,
98};
99#[cfg(feature = "sqlite")]
100pub use sqlite::SqliteAdapter;
101#[cfg(feature = "sqlserver")]
102pub use sqlserver::SqlServerAdapter;
103pub use traits::{
104    ArcDatabaseAdapter, BoxDatabaseAdapter, CursorValue, DatabaseAdapter, DatabaseCapabilities,
105    DirectMutationContext, DirectMutationOp, MutationStrategy, RelayDatabaseAdapter,
106    RelayPageResult, SupportsMutations,
107};
108pub use types::{
109    DatabaseType, JsonbValue, PoolMetrics,
110    sql_hints::{OrderByClause, OrderDirection, SqlProjectionHint},
111};
112pub use where_clause::{HavingClause, WhereClause, WhereOperator};
113pub use where_generator::GenericWhereGenerator;
114pub use where_sql_generator::WhereSqlGenerator;