Skip to main content

sqlx/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("lib.md")]
3
4#[cfg(all(
5    feature = "sqlite-preupdate-hook",
6    not(any(feature = "sqlite", feature = "sqlite-unbundled"))
7))]
8compile_error!(
9    "sqlite-preupdate-hook requires either 'sqlite' or 'sqlite-unbundled' to be enabled"
10);
11
12pub use sqlx_core::acquire::Acquire;
13pub use sqlx_core::arguments::{Arguments, IntoArguments};
14pub use sqlx_core::column::Column;
15pub use sqlx_core::column::ColumnIndex;
16pub use sqlx_core::column::ColumnOrigin;
17pub use sqlx_core::connection::{ConnectOptions, Connection};
18pub use sqlx_core::database::{self, Database};
19pub use sqlx_core::describe::Describe;
20pub use sqlx_core::executor::{Execute, Executor};
21pub use sqlx_core::from_row::FromRow;
22pub use sqlx_core::pool::{self, Pool};
23#[doc(hidden)]
24pub use sqlx_core::query::query_with_result as __query_with_result;
25pub use sqlx_core::query::{query, query_with};
26pub use sqlx_core::query_as::{query_as, query_as_with};
27pub use sqlx_core::query_builder::{self, QueryBuilder};
28#[doc(hidden)]
29pub use sqlx_core::query_scalar::query_scalar_with_result as __query_scalar_with_result;
30pub use sqlx_core::query_scalar::{query_scalar, query_scalar_with};
31pub use sqlx_core::raw_sql::{raw_sql, RawSql};
32pub use sqlx_core::row::Row;
33pub use sqlx_core::sql_str::{AssertSqlSafe, SqlSafeStr, SqlStr};
34pub use sqlx_core::statement::Statement;
35pub use sqlx_core::transaction::Transaction;
36pub use sqlx_core::type_info::TypeInfo;
37pub use sqlx_core::types::Type;
38pub use sqlx_core::value::{Value, ValueRef};
39pub use sqlx_core::Either;
40
41#[doc(inline)]
42pub use sqlx_core::error::{self, Error, Result};
43
44#[cfg(feature = "migrate")]
45pub use sqlx_core::migrate;
46
47#[cfg(feature = "mysql")]
48#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
49#[doc(inline)]
50pub use sqlx_mysql::{
51    self as mysql, MySql, MySqlConnection, MySqlExecutor, MySqlPool, MySqlTransaction,
52};
53
54#[cfg(feature = "postgres")]
55#[cfg_attr(docsrs, doc(cfg(feature = "postgres")))]
56#[doc(inline)]
57pub use sqlx_postgres::{
58    self as postgres, PgConnection, PgExecutor, PgPool, PgTransaction, Postgres,
59};
60
61#[cfg(feature = "_sqlite")]
62#[cfg_attr(docsrs, doc(cfg(feature = "_sqlite")))]
63#[doc(inline)]
64pub use sqlx_sqlite::{
65    self as sqlite, Sqlite, SqliteConnection, SqliteExecutor, SqlitePool, SqliteTransaction,
66};
67
68#[cfg(feature = "any")]
69#[cfg_attr(docsrs, doc(cfg(feature = "any")))]
70pub use crate::any::{reexports::*, Any, AnyExecutor};
71
72#[cfg(any(feature = "derive", feature = "macros"))]
73#[doc(hidden)]
74pub extern crate sqlx_macros;
75
76// derives
77#[cfg(feature = "derive")]
78#[doc(hidden)]
79pub use sqlx_macros::{FromRow, Type};
80
81// We can't do our normal facade approach with an attribute, but thankfully we can now
82// have docs out-of-line quite easily.
83#[doc = include_str!("macros/test.md")]
84#[cfg(feature = "macros")]
85pub use sqlx_macros::test;
86
87#[doc(hidden)]
88#[cfg(feature = "migrate")]
89pub use sqlx_core::testing;
90
91#[doc(hidden)]
92pub use sqlx_core::rt::test_block_on;
93
94#[cfg(feature = "any")]
95pub mod any;
96
97#[cfg(feature = "macros")]
98mod macros;
99
100// macro support
101#[cfg(feature = "macros")]
102#[doc(hidden)]
103pub mod ty_match;
104
105#[cfg(any(feature = "derive", feature = "macros"))]
106#[doc(hidden)]
107pub mod spec_error;
108
109#[doc(hidden)]
110pub use sqlx_core::rt as __rt;
111
112/// Conversions between Rust and SQL types.
113///
114/// To see how each SQL type maps to a Rust type, see the corresponding `types` module for each
115/// database:
116///
117///  * Postgres: [postgres::types]
118///  * MySQL: [mysql::types]
119///  * SQLite: [sqlite::types]
120///
121/// Any external types that have had [`Type`] implemented for, are re-exported in this module
122/// for convenience as downstream users need to use a compatible version of the external crate
123/// to take advantage of the implementation.
124///
125/// [`Type`]: types::Type
126pub mod types {
127    pub use sqlx_core::types::*;
128
129    #[cfg(feature = "derive")]
130    #[doc(hidden)]
131    pub use sqlx_macros::Type;
132}
133
134/// Provides [`Encode`] for encoding values for the database.
135pub mod encode {
136    pub use sqlx_core::encode::{Encode, IsNull};
137
138    #[cfg(feature = "derive")]
139    #[doc(hidden)]
140    pub use sqlx_macros::Encode;
141}
142
143pub use self::encode::Encode;
144
145/// Provides [`Decode`] for decoding values from the database.
146pub mod decode {
147    pub use sqlx_core::decode::Decode;
148
149    #[cfg(feature = "derive")]
150    #[doc(hidden)]
151    pub use sqlx_macros::Decode;
152}
153
154pub use self::decode::Decode;
155
156/// Types and traits for the `query` family of functions and macros.
157pub mod query {
158    pub use sqlx_core::query::{Map, Query};
159    pub use sqlx_core::query_as::QueryAs;
160    pub use sqlx_core::query_scalar::QueryScalar;
161}
162
163/// Convenience re-export of common traits.
164pub mod prelude {
165    pub use super::Acquire;
166    pub use super::ConnectOptions;
167    pub use super::Connection;
168    pub use super::Decode;
169    pub use super::Encode;
170    pub use super::Executor;
171    pub use super::FromRow;
172    pub use super::IntoArguments;
173    pub use super::Row;
174    pub use super::Statement;
175    pub use super::Type;
176}
177
178#[cfg(feature = "_unstable-docs")]
179pub use sqlx_core::config as _config;
180
181// NOTE: APIs exported in this module are SemVer-exempt.
182#[doc(hidden)]
183pub mod _unstable {
184    pub use sqlx_core::config;
185}
186
187#[doc(hidden)]
188#[cfg_attr(
189    all(feature = "chrono", feature = "time"),
190    deprecated = "SQLx has both `chrono` and `time` features enabled, \
191        which presents an ambiguity when the `query!()` macros are mapping date/time types. \
192        The `query!()` macros prefer types from `time` by default, \
193        but this behavior should not be relied upon; \
194        to resolve the ambiguity, we recommend specifying the preferred crate in a `sqlx.toml` file: \
195        https://docs.rs/sqlx/latest/sqlx/config/macros/PreferredCrates.html#field.date_time"
196)]
197pub fn warn_on_ambiguous_inferred_date_time_crate() {}
198
199#[doc(hidden)]
200#[cfg_attr(
201    all(feature = "bigdecimal", feature = "rust_decimal"),
202    deprecated = "SQLx has both `bigdecimal` and `rust_decimal` features enabled, \
203        which presents an ambiguity when the `query!()` macros are mapping `NUMERIC`. \
204        The `query!()` macros prefer `bigdecimal::BigDecimal` by default, \
205        but this behavior should not be relied upon; \
206        to resolve the ambiguity, we recommend specifying the preferred crate in a `sqlx.toml` file: \
207        https://docs.rs/sqlx/latest/sqlx/config/macros/PreferredCrates.html#field.numeric"
208)]
209pub fn warn_on_ambiguous_inferred_numeric_crate() {}