Skip to main content

cratestack_sqlx/
lib.rs

1/// Compatibility shim that exposes a `sqlx`-shaped API by re-exporting from
2/// `sqlx-core` + `sqlx-postgres` directly.
3///
4/// **Why this shim exists:** depending on the `sqlx` umbrella crate transitively
5/// pulls `sqlx-sqlite` into the resolve graph (Cargo's resolver materialises the
6/// optional dep even when no feature activates it), which pins `libsqlite3-sys
7/// ^0.30.1` and conflicts with `rusqlite 0.39`'s `libsqlite3-sys ^0.37` via the
8/// `links = "sqlite3"` rule. Going direct to the split crates side-steps the
9/// leak entirely. Downstream users keep writing `cratestack::sqlx::X` paths;
10/// macro emissions stay unchanged.
11///
12/// **SemVer caveat:** `sqlx-core` documents itself as "not meant for general use"
13/// without SemVer guarantees. The surface re-exported here is the narrow subset
14/// the umbrella `sqlx` crate exposes, which is stable in practice across `0.8.x`.
15/// If `sqlx-core` breaks at a `0.8` patch, this shim adapts in one place.
16pub mod sqlx {
17    pub use sqlx_core::Either;
18    pub use sqlx_core::acquire::Acquire;
19    pub use sqlx_core::arguments::{Arguments, IntoArguments};
20    pub use sqlx_core::column::{Column, ColumnIndex};
21    pub use sqlx_core::connection::{ConnectOptions, Connection};
22    pub use sqlx_core::database::{self, Database};
23    pub use sqlx_core::describe::Describe;
24    pub use sqlx_core::executor::{Execute, Executor};
25    pub use sqlx_core::from_row::FromRow;
26    pub use sqlx_core::pool::{self, Pool};
27    pub use sqlx_core::query::{query, query_with};
28    pub use sqlx_core::query_as::{query_as, query_as_with};
29    pub use sqlx_core::query_builder::{self, QueryBuilder};
30    pub use sqlx_core::query_scalar::{query_scalar, query_scalar_with};
31    pub use sqlx_core::raw_sql::{RawSql, raw_sql};
32    pub use sqlx_core::row::Row;
33    pub use sqlx_core::statement::Statement;
34    pub use sqlx_core::transaction::{Transaction, TransactionManager};
35    pub use sqlx_core::type_info::TypeInfo;
36    pub use sqlx_core::value::{Value, ValueRef};
37
38    pub use sqlx_core::error::{self, Error, Result};
39
40    #[cfg(feature = "decimal-rust-decimal")]
41    pub use sqlx_core::migrate;
42    #[cfg(not(feature = "decimal-rust-decimal"))]
43    pub use sqlx_core::migrate;
44
45    pub use sqlx_postgres::{
46        self as postgres, PgConnection, PgExecutor, PgPool, PgTransaction, Postgres,
47    };
48
49    pub mod types {
50        pub use sqlx_core::types::*;
51    }
52
53    pub mod encode {
54        pub use sqlx_core::encode::{Encode, IsNull};
55    }
56    pub use self::encode::Encode;
57
58    pub mod decode {
59        pub use sqlx_core::decode::Decode;
60    }
61    pub use self::decode::Decode;
62
63    pub use sqlx_core::types::Type;
64}
65
66mod audit;
67mod delegate;
68mod descriptor;
69mod error;
70mod idempotency;
71mod isolation;
72mod json;
73mod migrations;
74mod partial_row;
75mod query;
76mod render;
77#[cfg(test)]
78mod tests_coalesce;
79#[cfg(test)]
80mod tests_create_defaults;
81#[cfg(test)]
82mod tests_descriptor;
83#[cfg(test)]
84mod tests_field_filter;
85#[cfg(test)]
86mod tests_filter_logic;
87#[cfg(test)]
88mod tests_geography;
89#[cfg(test)]
90mod tests_json;
91#[cfg(test)]
92mod tests_nested_relation_policy;
93#[cfg(test)]
94mod tests_optional;
95#[cfg(test)]
96mod tests_pgvector;
97#[cfg(test)]
98mod tests_policy_precedence_bug;
99#[cfg(test)]
100mod tests_read_policy_field_predicates;
101#[cfg(test)]
102mod tests_read_policy_predicates;
103#[cfg(test)]
104mod tests_relation;
105#[cfg(test)]
106mod tests_system_principal_policy;
107#[cfg(test)]
108mod tests_update;
109#[cfg(test)]
110mod tests_update_many;
111#[cfg(test)]
112mod tests_upsert_conflict_predicate;
113mod transaction;
114
115pub use partial_row::FromPartialPgRow;
116
117pub use json::Json;
118/// Re-exported so generated code (and the facade crates) can reach
119/// `::cratestack::pgvector::Vector` without depending on the
120/// `pgvector` crate directly — mirrors how `sqlx` above is re-exposed
121/// as a shim rather than depended on separately by every consumer.
122#[cfg(feature = "pgvector")]
123pub use pgvector;
124
125pub use audit::{
126    AUDIT_TABLE_DDL, RunInTxOutcome, dispatch_audit_sink, primary_key_from_snapshot, snapshot_model,
127};
128pub use error::cratestack_error_from_sqlx;
129pub use idempotency::{SqlxIdempotencyStore, expiry_from};
130pub use isolation::{run_in_isolated_tx, run_in_isolated_tx_with_retries};
131pub use migrations::{
132    MIGRATIONS_TABLE_DDL, Migration, MigrationState, MigrationStatus, apply_pending,
133    ensure_migrations_table, status,
134};
135pub use transaction::Tx;
136
137pub use cratestack_policy::{PolicyExpr, PolicyLiteral, ReadPolicy, ReadPredicate};
138pub use cratestack_sql::{
139    CoalesceExpr, CoalesceFilter, ConflictTarget, CreateDefault, CreateDefaultType,
140    CreateModelInput, FieldRef, Filter, FilterExpr, FilterOp, IntoColumnName, IntoSqlValue,
141    JsonFilter, JsonTextPath, ModelColumn, ModelDescriptor, ModelPrimaryKey, NullOrder,
142    OrderClause, Orderable, Projection, RelationFilter, RelationHop, RelationInclude,
143    RelationQuantifier, SortDirection, SpatialFilter, SpatialPoint, SqlColumnValue, SqlValue,
144    Unorderable, UpdateModelInput, UpsertModelInput, VectorDistanceExpr, VectorDistanceFilter,
145    VectorMetric, coalesce, is_orderable, order_value_sql, point, wrap_filter,
146};
147pub use delegate::{
148    ModelDelegate, ScopedAggregate, ScopedAggregateColumn, ScopedAggregateCount, ScopedBatchCreate,
149    ScopedBatchDelete, ScopedBatchGet, ScopedBatchUpdate, ScopedBatchUpsert, ScopedCreateRecord,
150    ScopedDeleteMany, ScopedDeleteRecord, ScopedFindMany, ScopedFindManyWith, ScopedFindUnique,
151    ScopedModelDelegate, ScopedProjectedFindMany, ScopedProjectedFindUnique, ScopedUpdateMany,
152    ScopedUpdateManySet, ScopedUpdateRecord, ScopedUpdateRecordSet, ScopedUpsertRecord,
153    ScopedUpsertRecordDoNothing, ViewDelegate, ViewDelegateNoUnique,
154};
155pub use descriptor::{SqlxRuntime, enqueue_event_outbox, ensure_event_outbox_table};
156pub use query::{
157    Aggregate, AggregateColumn, AggregateCount, BatchCreate, BatchDelete, BatchGet, BatchUpdate,
158    BatchUpdateItem, BatchUpsert, CreateRecord, DeleteMany, DeleteRecord, FindMany, FindManyWith,
159    FindUnique, ProjectedFindMany, ProjectedFindUnique, UpdateMany, UpdateManySet, UpdateRecord,
160    UpdateRecordSet, UpsertOutcome, UpsertRecord, UpsertRecordDoNothing,
161    create_record_with_executor, update_record_with_executor,
162};