pub struct Command<'a> { /* private fields */ }Expand description
A remote command (stored procedure or user-defined function) with bound parameters, executed by name via an RPC request.
Implementations§
Source§impl<'a> Command<'a>
impl<'a> Command<'a>
Sourcepub fn new(proc_name: impl Into<Cow<'a, str>>) -> Self
pub fn new(proc_name: impl Into<Cow<'a, str>>) -> Self
Constructs a new command with the given procedure or function name.
Sourcepub fn bind_param(
&mut self,
name: impl Into<Cow<'a, str>>,
data: impl IntoSql<'a> + 'a,
)
pub fn bind_param( &mut self, name: impl Into<Cow<'a, str>>, data: impl IntoSql<'a> + 'a, )
Binds a scalar input parameter with the given name.
Sourcepub fn bind_out_param(
&mut self,
name: impl Into<Cow<'a, str>>,
data: impl IntoSql<'a> + 'a,
)
pub fn bind_out_param( &mut self, name: impl Into<Cow<'a, str>>, data: impl IntoSql<'a> + 'a, )
Binds a by-ref (OUT) scalar parameter. The returned value can be found by
the same name in the CommandResult returned values.
Sourcepub fn bind_table(
&mut self,
name: impl Into<Cow<'a, str>>,
data: impl TableValue<'a> + 'a,
)
pub fn bind_table( &mut self, name: impl Into<Cow<'a, str>>, data: impl TableValue<'a> + 'a, )
Binds a table-valued parameter. The provided argument must implement
TableValue.
§Example
#[derive(TableValueRow)]
struct SomeGeoList {
eid: i32,
lat: Numeric,
lon: Numeric,
}
let r1 = SomeGeoList {
eid: 1,
lat: Numeric::new_with_scale(10, 6),
lon: Numeric::new_with_scale(14, 6),
};
let r2 = SomeGeoList {
eid: 4,
lat: Numeric::new_with_scale(101, 6),
lon: Numeric::new_with_scale(142, 6),
};
let tbl = vec![r1, r2];
let mut cmd = Command::new("dbo.usp_TheGeoProcedure");
cmd.bind_table("@table", tbl);Sourcepub fn bind_table_with_dbtype(
&mut self,
name: impl Into<Cow<'a, str>>,
db_type: &'a str,
data: impl TableValue<'a> + 'a,
)
pub fn bind_table_with_dbtype( &mut self, name: impl Into<Cow<'a, str>>, db_type: &'a str, data: impl TableValue<'a> + 'a, )
The same as bind_table, but overrides the database
type name used for the TVP.
Sourcepub async fn exec<'b, S>(
self,
client: &'b mut Client<S>,
) -> Result<CommandStream<'b>>
pub async fn exec<'b, S>( self, client: &'b mut Client<S>, ) -> Result<CommandStream<'b>>
Executes the command on the server, returning a CommandStream that
can be collected into a CommandResult for convenience.
§Example
let mut cmd = Command::new("dbo.usp_SomeStoredProc");
cmd.bind_param("@foo", 34i32);
cmd.bind_out_param("@bar", "bar");
let res = cmd.exec(&mut client).await?.into_command_result().await?;
let rv: Option<&str> = res.try_return_value("@bar")?;
let rc = res.return_code();Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Command<'a>
impl<'a> RefUnwindSafe for Command<'a>
impl<'a> Send for Command<'a>
impl<'a> Sync for Command<'a>
impl<'a> Unpin for Command<'a>
impl<'a> UnsafeUnpin for Command<'a>
impl<'a> UnwindSafe for Command<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more