surrealdb/api/method/
use_db.rs

1use crate::api::conn::Method;
2use crate::api::conn::Param;
3use crate::api::conn::Router;
4use crate::api::Connection;
5use crate::api::Result;
6use crate::sql::Value;
7use std::future::Future;
8use std::future::IntoFuture;
9use std::pin::Pin;
10
11#[derive(Debug)]
12#[must_use = "futures do nothing unless you `.await` or poll them"]
13pub struct UseDb<'r, C: Connection> {
14	pub(super) router: Result<&'r Router<C>>,
15	pub(super) ns: Value,
16	pub(super) db: String,
17}
18
19impl<'r, Client> IntoFuture for UseDb<'r, Client>
20where
21	Client: Connection,
22{
23	type Output = Result<()>;
24	type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send + Sync + 'r>>;
25
26	fn into_future(self) -> Self::IntoFuture {
27		Box::pin(async move {
28			let mut conn = Client::new(Method::Use);
29			conn.execute_unit(self.router?, Param::new(vec![self.ns, self.db.into()])).await
30		})
31	}
32}