From e2bcfb8d269e39b3bdd005a70028e90f057ab58d Mon Sep 17 00:00:00 2001 From: David Johnson Date: Thu, 20 May 2021 09:50:18 -0700 Subject: [PATCH] feat(core): Added name() and id() functions to Argument that both return optional and Arguments::named() to get an iterator over named arguments --- sqlx-core/src/arguments.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sqlx-core/src/arguments.rs b/sqlx-core/src/arguments.rs index 0a3d69a9..daf4fd23 100644 --- a/sqlx-core/src/arguments.rs +++ b/sqlx-core/src/arguments.rs @@ -149,6 +149,11 @@ impl<'a, Db: Database> Arguments<'a, Db> { self.positional.iter() } + /// Returns an iterator of the named parameters. + pub fn named(&self) -> impl Iterator> { + self.named.iter() + } + /// Returns a reference to the argument at the location, if present. pub fn get<'x, I: ArgumentIndex<'a, Db>>(&'x self, index: &I) -> Option<&'x Argument<'a, Db>> { index.get(self) @@ -156,6 +161,24 @@ impl<'a, Db: Database> Arguments<'a, Db> { } impl<'a, Db: Database> Argument<'a, Db> { + /// Gets the name of this argument, if it is a named argument, None otherwise + pub fn name<'b>(&'b self) -> Option<&'a str>{ + if let Either::Right(name) = self.parameter{ + Some(name) + }else{ + None + } + } + + /// Gets the name of this argument, if it is a named argument, None otherwise + pub fn id(&self) -> Option{ + if let Either::Left(id) = self.parameter{ + Some(id) + }else{ + None + } + } + /// Returns the SQL type identifier of the argument. #[must_use] pub fn type_id(&self) -> Db::TypeId {