Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["any", "macros", "migrate", "json"]

derive = ["sqlx-macros/derive"]
macros = ["derive", "sqlx-macros/macros"]
macros = ["derive", "sqlx-macros/macros", "sqlx-core/offline", "sqlx-mysql?/offline", "sqlx-postgres?/offline", "sqlx-sqlite?/offline"]
migrate = ["sqlx-core/migrate", "sqlx-macros?/migrate", "sqlx-mysql?/migrate", "sqlx-postgres?/migrate", "sqlx-sqlite?/migrate"]

# Enable parsing of `sqlx.toml` for configuring macros and migrations.
Expand Down Expand Up @@ -211,7 +211,7 @@ features = ["time", "net", "sync", "fs", "io-util", "rt"]
default-features = false

[dependencies]
sqlx-core = { workspace = true, features = ["offline", "migrate"] }
sqlx-core = { workspace = true, features = ["migrate"] }
sqlx-macros = { workspace = true, optional = true }

sqlx-mysql = { workspace = true, optional = true }
Expand Down
6 changes: 5 additions & 1 deletion sqlx-core/src/any/connection/backend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::any::{Any, AnyArguments, AnyQueryResult, AnyRow, AnyStatement, AnyTypeInfo};
#[cfg(feature = "offline")]
use crate::any::Any;
use crate::any::{AnyArguments, AnyQueryResult, AnyRow, AnyStatement, AnyTypeInfo};
#[cfg(feature = "offline")]
use crate::describe::Describe;
use crate::sql_str::SqlStr;
use either::Either;
Expand Down Expand Up @@ -114,5 +117,6 @@ pub trait AnyConnectionBackend: std::any::Any + Debug + Send + 'static {
parameters: &[AnyTypeInfo],
) -> BoxFuture<'c, crate::Result<AnyStatement>>;

#[cfg(feature = "offline")]
fn describe(&mut self, sql: SqlStr) -> BoxFuture<'_, crate::Result<Describe<Any>>>;
}
2 changes: 2 additions & 0 deletions sqlx-core/src/any/connection/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::any::{Any, AnyConnection, AnyQueryResult, AnyRow, AnyStatement, AnyTypeInfo};
#[cfg(feature = "offline")]
use crate::describe::Describe;
use crate::error::Error;
use crate::executor::{Execute, Executor};
Expand Down Expand Up @@ -56,6 +57,7 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
self.backend.prepare_with(sql, parameters)
}

#[cfg(feature = "offline")]
fn describe<'e>(self, sql: SqlStr) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>>
where
'c: 'e,
Expand Down
2 changes: 2 additions & 0 deletions sqlx-core/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::database::Database;
#[cfg(feature = "offline")]
use crate::describe::Describe;
use crate::error::{BoxDynError, Error};
use crate::sql_str::{SqlSafeStr, SqlStr};
Expand Down Expand Up @@ -178,6 +179,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
/// This is used by compile-time verification in the query macros to
/// power their type inference.
#[doc(hidden)]
#[cfg(feature = "offline")]
fn describe<'e>(self, sql: SqlStr) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>>
where
'c: 'e;
Expand Down
3 changes: 3 additions & 0 deletions sqlx-core/src/pool/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use futures_core::stream::BoxStream;
use futures_util::TryStreamExt;

use crate::database::Database;
#[cfg(feature = "offline")]
use crate::describe::Describe;
use crate::error::Error;
use crate::executor::{Execute, Executor};
Expand Down Expand Up @@ -63,6 +64,7 @@ where
}

#[doc(hidden)]
#[cfg(feature = "offline")]
fn describe<'e>(self, sql: SqlStr) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>> {
let pool = self.clone();

Expand Down Expand Up @@ -127,6 +129,7 @@ where
// }
//
// #[doc(hidden)]
// #[cfg(feature = "offline")]
// #[inline]
// fn describe<'e, 'q: 'e>(
// self,
Expand Down
1 change: 1 addition & 0 deletions sqlx-core/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ where
// }
//
// #[doc(hidden)]
// #[cfg(feature = "offline")]
// fn describe<'e, 'q: 'e>(
// self,
// query: &'q str,
Expand Down
4 changes: 2 additions & 2 deletions sqlx-mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rust-version.workspace = true
[features]
json = ["sqlx-core/json", "serde"]
any = ["sqlx-core/any"]
offline = ["sqlx-core/offline", "serde/derive"]
offline = ["sqlx-core/offline", "serde/derive", "bitflags/serde"]
migrate = ["sqlx-core/migrate"]

# Type Integration features
Expand Down Expand Up @@ -52,7 +52,7 @@ uuid = { workspace = true, optional = true }
# Misc
atoi = "2.0"
base64 = { version = "0.22.0", default-features = false, features = ["std"] }
bitflags = { version = "2", default-features = false, features = ["serde"] }
bitflags = { version = "2", default-features = false }
byteorder = { version = "1.4.3", default-features = false, features = ["std"] }
bytes = "1.1.0"
either = "1.6.1"
Expand Down
6 changes: 5 additions & 1 deletion sqlx-mysql/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ use either::Either;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use futures_util::{stream, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
#[cfg(feature = "offline")]
use sqlx_core::any::Any;
use sqlx_core::any::{
Any, AnyArguments, AnyColumn, AnyConnectOptions, AnyConnectionBackend, AnyQueryResult, AnyRow,
AnyArguments, AnyColumn, AnyConnectOptions, AnyConnectionBackend, AnyQueryResult, AnyRow,
AnyStatement, AnyTypeInfo, AnyTypeInfoKind,
};
use sqlx_core::connection::Connection;
use sqlx_core::database::Database;
#[cfg(feature = "offline")]
use sqlx_core::describe::Describe;
use sqlx_core::executor::Executor;
use sqlx_core::sql_str::SqlStr;
Expand Down Expand Up @@ -141,6 +144,7 @@ impl AnyConnectionBackend for MySqlConnection {
})
}

#[cfg(feature = "offline")]
fn describe(&mut self, sql: SqlStr) -> BoxFuture<'_, sqlx_core::Result<Describe<Any>>> {
Box::pin(async move {
let describe = Executor::describe(self, sql).await?;
Expand Down
1 change: 1 addition & 0 deletions sqlx-mysql/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct MySqlColumn {
#[cfg_attr(feature = "offline", serde(default))]
pub(crate) origin: ColumnOrigin,

#[allow(dead_code)]
#[cfg_attr(feature = "offline", serde(skip))]
pub(crate) flags: Option<ColumnFlags>,
}
Expand Down
6 changes: 5 additions & 1 deletion sqlx-mysql/src/connection/executor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::MySqlStream;
use crate::connection::stream::Waiting;
#[cfg(feature = "offline")]
use crate::describe::Describe;
use crate::error::Error;
use crate::executor::{Execute, Executor};
Expand All @@ -10,7 +11,9 @@ use crate::protocol::response::Status;
use crate::protocol::statement::{
BinaryRow, Execute as StatementExecute, Prepare, PrepareOk, StmtClose,
};
use crate::protocol::text::{ColumnDefinition, ColumnFlags, Query, TextRow};
#[cfg(feature = "offline")]
use crate::protocol::text::ColumnFlags;
use crate::protocol::text::{ColumnDefinition, Query, TextRow};
use crate::statement::{MySqlStatement, MySqlStatementMetadata};
use crate::HashMap;
use crate::{
Expand Down Expand Up @@ -359,6 +362,7 @@ impl<'c> Executor<'c> for &'c mut MySqlConnection {
}

#[doc(hidden)]
#[cfg(feature = "offline")]
fn describe<'e>(self, sql: SqlStr) -> BoxFuture<'e, Result<Describe<MySql>, Error>>
where
'c: 'e,
Expand Down
12 changes: 5 additions & 7 deletions sqlx-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ rust-version.workspace = true

[features]
any = ["sqlx-core/any"]
json = ["sqlx-core/json"]
json = ["dep:serde", "dep:serde_json", "sqlx-core/json"]
migrate = ["sqlx-core/migrate"]
offline = ["sqlx-core/offline"]
offline = ["json", "sqlx-core/offline", "smallvec/serde"]

# Type Integration features
bigdecimal = ["dep:bigdecimal", "dep:num-bigint", "sqlx-core/bigdecimal"]
Expand Down Expand Up @@ -62,21 +62,19 @@ itoa = "1.0.1"
log = "0.4.18"
memchr = { version = "2.4.1", default-features = false }
num-bigint = { version = "0.4.3", optional = true }
smallvec = { version = "1.7.0", features = ["serde"] }
smallvec = { version = "1.7.0" }
stringprep = "0.1.2"
tracing = { version = "0.1.37", features = ["log"] }
whoami = { version = "1.2.1", default-features = false }

dotenvy.workspace = true
thiserror.workspace = true

serde = { version = "1.0.144", features = ["derive"] }
serde_json = { version = "1.0.85", features = ["raw_value"] }
serde = { version = "1.0.144", optional = true, features = ["derive"] }
serde_json = { version = "1.0.85", optional = true, features = ["raw_value"] }

[dependencies.sqlx-core]
workspace = true
# We use JSON in the driver implementation itself so there's no reason not to enable it here.
features = ["json"]

[dev-dependencies.sqlx]
# FIXME: https://github.com/rust-lang/cargo/issues/15622
Expand Down
6 changes: 5 additions & 1 deletion sqlx-postgres/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ use futures_util::{stream, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
use sqlx_core::sql_str::SqlStr;
use std::{future, pin::pin};

#[cfg(feature = "offline")]
use sqlx_core::any::Any;
use sqlx_core::any::{
Any, AnyArguments, AnyColumn, AnyConnectOptions, AnyConnectionBackend, AnyQueryResult, AnyRow,
AnyArguments, AnyColumn, AnyConnectOptions, AnyConnectionBackend, AnyQueryResult, AnyRow,
AnyStatement, AnyTypeInfo, AnyTypeInfoKind,
};

use crate::type_info::PgType;
use sqlx_core::connection::Connection;
use sqlx_core::database::Database;
#[cfg(feature = "offline")]
use sqlx_core::describe::Describe;
use sqlx_core::executor::Executor;
use sqlx_core::ext::ustr::UStr;
Expand Down Expand Up @@ -141,6 +144,7 @@ impl AnyConnectionBackend for PgConnection {
})
}

#[cfg(feature = "offline")]
fn describe<'c>(&mut self, sql: SqlStr) -> BoxFuture<'_, sqlx_core::Result<Describe<Any>>> {
Box::pin(async move {
let describe = Executor::describe(self, sql).await?;
Expand Down
13 changes: 13 additions & 0 deletions sqlx-postgres/src/connection/describe.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use crate::connection::TableColumns;
use crate::error::Error;
use crate::ext::ustr::UStr;
#[cfg(feature = "offline")]
use crate::io::StatementId;
use crate::message::{ParameterDescription, RowDescription};
use crate::query_as::query_as;
use crate::query_scalar::query_scalar;
#[cfg(feature = "offline")]
use crate::statement::PgStatementMetadata;
use crate::type_info::{PgArrayOf, PgCustomType, PgType, PgTypeKind};
#[cfg(feature = "offline")]
use crate::types::Json;
use crate::types::Oid;
use crate::HashMap;
use crate::{PgColumn, PgConnection, PgTypeInfo};
#[cfg(feature = "offline")]
use smallvec::SmallVec;
use sqlx_core::column::{ColumnOrigin, TableColumn};
#[cfg(feature = "offline")]
use sqlx_core::query_builder::QueryBuilder;
#[cfg(feature = "offline")]
use sqlx_core::sql_str::AssertSqlSafe;
use std::sync::Arc;

Expand Down Expand Up @@ -490,6 +496,7 @@ WHERE rngtypid = $1
}

/// Check whether EXPLAIN statements are supported by the current connection
#[cfg(feature = "offline")]
fn is_explain_available(&self) -> bool {
let parameter_statuses = &self.inner.stream.parameter_statuses;
let is_cockroachdb = parameter_statuses.contains_key("crdb_version");
Expand All @@ -498,6 +505,7 @@ WHERE rngtypid = $1
!is_cockroachdb && !is_materialize && !is_questdb
}

#[cfg(feature = "offline")]
pub(crate) async fn get_nullable_for_columns(
&mut self,
stmt_id: StatementId,
Expand Down Expand Up @@ -591,6 +599,7 @@ WHERE rngtypid = $1
///
/// This currently only marks columns that are on the inner half of an outer join
/// and returns `None` for all others.
#[cfg(feature = "offline")]
async fn nullables_from_explain(
&mut self,
stmt_id: StatementId,
Expand Down Expand Up @@ -640,6 +649,7 @@ WHERE rngtypid = $1
}
}

#[cfg(feature = "offline")]
fn visit_plan(plan: &Plan, outputs: &[String], nullables: &mut Vec<Option<bool>>) {
if let Some(plan_outputs) = &plan.output {
// all outputs of a Full Join must be marked nullable
Expand All @@ -665,6 +675,7 @@ fn visit_plan(plan: &Plan, outputs: &[String], nullables: &mut Vec<Option<bool>>
}
}

#[cfg(feature = "offline")]
#[derive(serde::Deserialize, Debug)]
#[serde(untagged)]
enum Explain {
Expand All @@ -688,6 +699,7 @@ enum Explain {
Other(serde::de::IgnoredAny),
}

#[cfg(feature = "offline")]
#[derive(serde::Deserialize, Debug)]
struct Plan {
#[serde(rename = "Join Type")]
Expand All @@ -701,6 +713,7 @@ struct Plan {
}

#[test]
#[cfg(feature = "offline")]
fn explain_parsing() {
let normal_plan = r#"[
{
Expand Down
2 changes: 2 additions & 0 deletions sqlx-postgres/src/connection/executor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "offline")]
use crate::describe::Describe;
use crate::error::Error;
use crate::executor::{Execute, Executor};
Expand Down Expand Up @@ -475,6 +476,7 @@ impl<'c> Executor<'c> for &'c mut PgConnection {
})
}

#[cfg(feature = "offline")]
fn describe<'e>(self, sql: SqlStr) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>>
where
'c: 'e,
Expand Down
2 changes: 2 additions & 0 deletions sqlx-postgres/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) struct PortalId(IdInner);
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
struct IdInner(Option<NonZeroU32>);

#[allow(dead_code)]
pub(crate) struct DisplayId {
prefix: &'static str,
id: NonZeroU32,
Expand Down Expand Up @@ -43,6 +44,7 @@ impl StatementId {
/// Get a type to format this statement ID with [`Display`].
///
/// Returns `None` if this is the unnamed statement.
#[allow(dead_code)]
#[inline(always)]
pub fn display(&self) -> Option<DisplayId> {
self.0.display(Self::NAME_PREFIX)
Expand Down
2 changes: 2 additions & 0 deletions sqlx-postgres/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use sqlx_core::transaction::Transaction;
use sqlx_core::Either;
use tracing::Instrument;

#[cfg(feature = "offline")]
use crate::describe::Describe;
use crate::error::Error;
use crate::executor::{Execute, Executor};
Expand Down Expand Up @@ -439,6 +440,7 @@ impl<'c> Executor<'c> for &'c mut PgListener {
}

#[doc(hidden)]
#[cfg(feature = "offline")]
fn describe<'e>(self, query: SqlStr) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>>
where
'c: 'e,
Expand Down
4 changes: 2 additions & 2 deletions sqlx-postgres/src/types/hstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
types::Type,
PgArgumentBuffer, PgHasArrayType, PgTypeInfo, PgValueRef, Postgres,
};
use serde::{Deserialize, Serialize};
use sqlx_core::bytes::Buf;

/// Key-value support (`hstore`) for Postgres.
Expand Down Expand Up @@ -88,7 +87,8 @@ use sqlx_core::bytes::Buf;
/// }
/// ```
///
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
pub struct PgHstore(pub BTreeMap<String, Option<String>>);

impl Deref for PgHstore {
Expand Down
Loading
Loading