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.40`'s `libsqlite3-sys ^0.38` 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 was stable in practice across `0.8.x`
15/// and is now pinned at `=0.9.0`. That design paid off at the 0.8→0.9 boundary:
16/// upstream's `SqlSafeStr` bound and the `QueryBuilder` lifetime removal landed
17/// as *additions to this list* (`AssertSqlSafe`/`SqlSafeStr`/`SqlStr`) plus
18/// mechanical call-site edits, with no downstream `::cratestack::sqlx::…` path
19/// changing. Treat any future minor the same way: adapt here first.
20pub mod sqlx {
21    pub use sqlx_core::Either;
22    pub use sqlx_core::acquire::Acquire;
23    pub use sqlx_core::arguments::{Arguments, IntoArguments};
24    pub use sqlx_core::column::{Column, ColumnIndex};
25    pub use sqlx_core::connection::{ConnectOptions, Connection};
26    pub use sqlx_core::database::{self, Database};
27    pub use sqlx_core::describe::Describe;
28    pub use sqlx_core::executor::{Execute, Executor};
29    pub use sqlx_core::from_row::FromRow;
30    pub use sqlx_core::pool::{self, Pool};
31    pub use sqlx_core::query::{query, query_with};
32    pub use sqlx_core::query_as::{query_as, query_as_with};
33    pub use sqlx_core::query_builder::{self, QueryBuilder};
34    pub use sqlx_core::query_scalar::{query_scalar, query_scalar_with};
35    pub use sqlx_core::raw_sql::{RawSql, raw_sql};
36    pub use sqlx_core::row::Row;
37    // sqlx 0.9.0 (#3723) narrowed every `query*()`/`raw_sql()` entry point to
38    // `impl SqlSafeStr`, implemented only for `&'static str` and the
39    // `AssertSqlSafe` wrapper. Re-exported here rather than left to
40    // `sqlx_core::sql_str::…` paths so the shim stays the single place that
41    // knows which upstream module these live in — the same reason every other
42    // item above is re-exported by name.
43    pub use sqlx_core::sql_str::{AssertSqlSafe, SqlSafeStr, SqlStr};
44    pub use sqlx_core::statement::Statement;
45    pub use sqlx_core::transaction::{Transaction, TransactionManager};
46    pub use sqlx_core::type_info::TypeInfo;
47    pub use sqlx_core::value::{Value, ValueRef};
48
49    pub use sqlx_core::error::{self, Error, Result};
50
51    #[cfg(feature = "decimal-rust-decimal")]
52    pub use sqlx_core::migrate;
53    #[cfg(not(feature = "decimal-rust-decimal"))]
54    pub use sqlx_core::migrate;
55
56    pub use sqlx_postgres::{
57        self as postgres, PgConnection, PgExecutor, PgPool, PgTransaction, Postgres,
58    };
59
60    pub mod types {
61        pub use sqlx_core::types::*;
62    }
63
64    pub mod encode {
65        pub use sqlx_core::encode::{Encode, IsNull};
66    }
67    pub use self::encode::Encode;
68
69    pub mod decode {
70        pub use sqlx_core::decode::Decode;
71    }
72    pub use self::decode::Decode;
73
74    pub use sqlx_core::types::Type;
75}
76
77mod audit;
78mod delegate;
79mod descriptor;
80mod error;
81mod idempotency;
82mod isolation;
83mod json;
84mod migrations;
85mod partial_row;
86mod query;
87mod render;
88#[cfg(test)]
89mod tests_coalesce;
90#[cfg(test)]
91mod tests_create_defaults;
92#[cfg(test)]
93mod tests_descriptor;
94#[cfg(test)]
95mod tests_field_filter;
96#[cfg(test)]
97mod tests_filter_logic;
98#[cfg(test)]
99mod tests_geography;
100#[cfg(test)]
101mod tests_json;
102#[cfg(test)]
103mod tests_nested_relation_policy;
104#[cfg(test)]
105mod tests_optional;
106#[cfg(test)]
107mod tests_pgvector;
108#[cfg(test)]
109mod tests_policy_precedence_bug;
110#[cfg(test)]
111mod tests_read_policy_field_predicates;
112#[cfg(test)]
113mod tests_read_policy_predicates;
114#[cfg(test)]
115mod tests_relation;
116#[cfg(test)]
117mod tests_system_principal_policy;
118#[cfg(test)]
119mod tests_update;
120#[cfg(test)]
121mod tests_update_many;
122#[cfg(test)]
123mod tests_upsert_conflict_predicate;
124mod transaction;
125
126pub use partial_row::FromPartialPgRow;
127
128pub use json::Json;
129/// Re-exported so generated code (and the facade crates) can reach
130/// `::cratestack::pgvector::Vector` without depending on the
131/// `pgvector` crate directly — mirrors how `sqlx` above is re-exposed
132/// as a shim rather than depended on separately by every consumer.
133#[cfg(feature = "pgvector")]
134pub use pgvector;
135
136pub use audit::{
137    AUDIT_TABLE_DDL, RunInTxOutcome, dispatch_audit_sink, primary_key_from_snapshot, snapshot_model,
138};
139pub use error::cratestack_error_from_sqlx;
140pub use idempotency::{SqlxIdempotencyStore, expiry_from};
141pub use isolation::{run_in_isolated_tx, run_in_isolated_tx_with_retries};
142pub use migrations::{
143    MIGRATIONS_TABLE_DDL, Migration, MigrationState, MigrationStatus, apply_pending,
144    ensure_migrations_table, status,
145};
146pub use transaction::Tx;
147
148pub use cratestack_policy::{PolicyExpr, PolicyLiteral, ReadPolicy, ReadPredicate};
149pub use cratestack_sql::{
150    CoalesceExpr, CoalesceFilter, ConflictTarget, CreateDefault, CreateDefaultType,
151    CreateModelInput, FieldRef, Filter, FilterExpr, FilterOp, IntoColumnName, IntoSqlValue,
152    JsonFilter, JsonTextPath, ModelColumn, ModelDescriptor, ModelPrimaryKey, NullOrder,
153    OrderClause, Orderable, Projection, RelationFilter, RelationHop, RelationInclude,
154    RelationQuantifier, SortDirection, SpatialFilter, SpatialPoint, SqlColumnValue, SqlValue,
155    Unorderable, UpdateModelInput, UpsertModelInput, VectorDistanceExpr, VectorDistanceFilter,
156    VectorMetric, coalesce, is_orderable, order_value_sql, point, wrap_filter,
157};
158pub use delegate::{
159    ModelDelegate, ScopedAggregate, ScopedAggregateColumn, ScopedAggregateCount, ScopedBatchCreate,
160    ScopedBatchDelete, ScopedBatchGet, ScopedBatchUpdate, ScopedBatchUpsert, ScopedCreateRecord,
161    ScopedDeleteMany, ScopedDeleteRecord, ScopedFindMany, ScopedFindManyWith, ScopedFindUnique,
162    ScopedModelDelegate, ScopedProjectedFindMany, ScopedProjectedFindUnique, ScopedUpdateMany,
163    ScopedUpdateManySet, ScopedUpdateRecord, ScopedUpdateRecordSet, ScopedUpsertRecord,
164    ScopedUpsertRecordDoNothing, ViewDelegate, ViewDelegateNoUnique,
165};
166pub use descriptor::{SqlxRuntime, enqueue_event_outbox, ensure_event_outbox_table};
167pub use query::{
168    Aggregate, AggregateColumn, AggregateCount, BatchCreate, BatchDelete, BatchGet, BatchUpdate,
169    BatchUpdateItem, BatchUpsert, CreateRecord, DeleteMany, DeleteRecord, FindMany, FindManyWith,
170    FindUnique, ProjectedFindMany, ProjectedFindUnique, UpdateMany, UpdateManySet, UpdateRecord,
171    UpdateRecordSet, UpsertOutcome, UpsertRecord, UpsertRecordDoNothing,
172    create_record_with_executor, update_record_with_executor,
173};