bitwarden_test/play/query.rs
1//! Query trait for parameterized database queries
2
3use serde::{Serialize, de::DeserializeOwned};
4
5/// Trait for defining parameterized queries
6///
7/// Queries allow executing specific operations against the test database.
8pub trait Query: Sized + Send + Sync {
9 /// The type of arguments passed to the query
10 type Args: Serialize + Clone + Send + Sync;
11
12 /// The type of result returned by the query
13 type Result: DeserializeOwned + Send + Sync;
14
15 /// The name of this query template
16 fn template_name() -> &'static str;
17
18 /// Get the arguments for this query
19 fn args(&self) -> &Self::Args;
20
21 /// Create an instance from the query result
22 fn from_result(result: Self::Result) -> Self;
23}
24
25/// Request body for executing a query
26#[derive(Serialize)]
27pub(crate) struct QueryRequest<'a, A: Serialize> {
28 pub template: &'a str,
29 pub arguments: &'a A,
30}