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 TABLE IF NOT EXISTS tags (
|
||||
id SERIAL PRIMARY KEY,
|
||||
label TEXT NOT NULL
|
||||
label TEXT UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
-- 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> {
|
||||
let insert_values: Vec<String> = tag_labels
|
||||
.iter()
|
||||
.map(|label| format!("({}),", label))
|
||||
.collect();
|
||||
|
||||
let result = sqlx::query("INSERT INTO tags (label) VALUES $1 RETURNING id, label")
|
||||
let query = "INSERT INTO tags (label) VALUES $1 ON CONFLICT (label) DO NOTHING RETURNING *"
|
||||
let result = sqlx::query(query)
|
||||
.bind(insert_values)
|
||||
.fetch_all(&self.connection)
|
||||
.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>) {
|
||||
todo!()
|
||||
}
|
||||
|
Reference in New Issue
Block a user