update tags add function
This commit is contained in:
parent
132906b548
commit
aad368c70c
@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS questions (
|
|||||||
-- Create tags table
|
-- Create tags table
|
||||||
CREATE TABLE IF NOT EXISTS tags (
|
CREATE TABLE IF NOT EXISTS tags (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
label TEXT NOT NULL
|
label TEXT UNIQUE NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Create question_tag table
|
-- Create question_tag table
|
||||||
|
@ -72,13 +72,14 @@ impl Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add new tags to tags table, only if tags with existing label do not exist
|
||||||
pub async fn _add_tags(&mut self, tag_labels: Vec<String>) -> Result<Vec<Tag>, String> {
|
pub async fn _add_tags(&mut self, tag_labels: Vec<String>) -> Result<Vec<Tag>, String> {
|
||||||
let insert_values: Vec<String> = tag_labels
|
let insert_values: Vec<String> = tag_labels
|
||||||
.iter()
|
.iter()
|
||||||
.map(|label| format!("({}),", label))
|
.map(|label| format!("({}),", label))
|
||||||
.collect();
|
.collect();
|
||||||
|
let query = "INSERT INTO tags (label) VALUES $1 ON CONFLICT (label) DO NOTHING RETURNING *"
|
||||||
let result = sqlx::query("INSERT INTO tags (label) VALUES $1 RETURNING id, label")
|
let result = sqlx::query(query)
|
||||||
.bind(insert_values)
|
.bind(insert_values)
|
||||||
.fetch_all(&self.connection)
|
.fetch_all(&self.connection)
|
||||||
.await;
|
.await;
|
||||||
@ -190,13 +191,6 @@ impl Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates passed in tag labels in the tags table, only if they do not already exists
|
|
||||||
/// Returns list of all tags from passed in labels, regardless of if they already existed
|
|
||||||
pub fn _add_tags_if_not_exists(&mut self, _tags_labels: Vec<String>) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
pub fn _sync_question_tags(&mut self, _tags: Vec<Tag>) {
|
pub fn _sync_question_tags(&mut self, _tags: Vec<Tag>) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user