Skip to content

Commit

Permalink
WIP [next]: implement generalized query placeholders
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Bonander <austin@launchbadge.com>
  • Loading branch information
abonander committed May 5, 2021
1 parent e7664d8 commit b0ebc88
Show file tree
Hide file tree
Showing 8 changed files with 624 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ memchr = "2.3"
conquer-once = { version = "0.3.2", optional = true }
parking_lot = { version = "0.11.1", optional = true }
crossbeam = { version = "0.8.0", optional = true }
combine = "4.5.2"
9 changes: 9 additions & 0 deletions sqlx-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ pub trait Database:

/// The concrete [`TypeId`] implementation for this database.
type TypeId: 'static + PartialEq + Hash + Clone + Copy + Send + Sync;

/// The character used to prefix bind parameter placeholders, e.g. `$` for Postgres, `?` for MySQL, etc.
const PLACEHOLDER_CHAR: char;

/// The indexing type for bind parameters.
///
/// E.g. `Implicit` for MySQL which just does `SELECT 1 FROM foo WHERE bar = ? AND baz = ?`
/// or `OneIndexed` for Postgres which does `SELECT 1 FROM foo WHERE bar = $1 AND baz = $2`
const PARAM_INDEXING: crate::placeholders::ParamIndexing;
}

/// Associates [`Database`] with an `Output` of a generic lifetime.
Expand Down
7 changes: 6 additions & 1 deletion sqlx-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ pub enum Error {
/// An error occurred encoding a value for a specific parameter to
/// be sent to the database.
ParameterEncode { parameter: Either<usize, Box<str>>, source: EncodeError },

/// An error occurred while parsing or expanding the generic placeholder syntax in a query.
Placeholders(crate::placeholders::Error),
}

impl Error {
Expand Down Expand Up @@ -179,6 +182,8 @@ impl Display for Error {
Self::ParameterEncode { parameter: Either::Right(name), source } => {
write!(f, "Encode parameter `{}`: {}", name, source)
}

Self::Placeholders(e) => e.fmt(f),
}
}
}
Expand All @@ -188,7 +193,7 @@ impl StdError for Error {
match self {
Self::ConnectOptions { source: Some(source), .. } => Some(&**source),
Self::Network(source) => Some(source),

Self::Placeholders(source) => Some(source),
_ => None,
}
}
Expand Down
3 changes: 3 additions & 0 deletions sqlx-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub mod io;
#[doc(hidden)]
pub mod net;

#[doc(hidden)]
pub mod placeholders;

#[doc(hidden)]
#[cfg(feature = "_mock")]
pub mod mock;
Expand Down

0 comments on commit b0ebc88

Please sign in to comment.