create LiteralAlternative with get/set in db
This commit is contained in:
parent
6099a2ba81
commit
12567a6b97
@ -112,6 +112,14 @@ pub struct Literal {
|
|||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct LiteralAlternative {
|
||||||
|
pub _id: bson::oid::ObjectId,
|
||||||
|
pub token: String,
|
||||||
|
pub variant: String,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
pub _id: bson::oid::ObjectId,
|
pub _id: bson::oid::ObjectId,
|
||||||
@ -321,6 +329,51 @@ pub trait CallDB {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_literal_alternative(
|
||||||
|
&mut self,
|
||||||
|
literal: &str,
|
||||||
|
variant: &str,
|
||||||
|
) -> DbResult<Option<LiteralAlternative>> {
|
||||||
|
let db = self.get_database().await;
|
||||||
|
let messages = db.collection::<LiteralAlternative>("literal_alternatives");
|
||||||
|
|
||||||
|
let literal = messages
|
||||||
|
.find_one(doc! { "token": literal, "variant": variant })
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(literal)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_literal_alternative_value(
|
||||||
|
&mut self,
|
||||||
|
literal: &str,
|
||||||
|
variant: &str,
|
||||||
|
) -> DbResult<Option<String>> {
|
||||||
|
let literal = self.get_literal_alternative(literal, variant).await?;
|
||||||
|
|
||||||
|
Ok(literal.map(|l| l.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_literal_alternative(
|
||||||
|
&mut self,
|
||||||
|
literal: &str,
|
||||||
|
variant: &str,
|
||||||
|
valuestr: &str,
|
||||||
|
) -> DbResult<()> {
|
||||||
|
let db = self.get_database().await;
|
||||||
|
let literals = db.collection::<LiteralAlternative>("literal_alternatives");
|
||||||
|
|
||||||
|
literals
|
||||||
|
.update_one(
|
||||||
|
doc! { "token": literal, "variant": variant },
|
||||||
|
doc! { "$set": { "value": valuestr } },
|
||||||
|
)
|
||||||
|
.upsert(true)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_all_events(&mut self) -> DbResult<Vec<Event>> {
|
async fn get_all_events(&mut self) -> DbResult<Vec<Event>> {
|
||||||
let db = self.get_database().await;
|
let db = self.get_database().await;
|
||||||
let events = db.collection::<Event>("events");
|
let events = db.collection::<Event>("events");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user