-
-
Save Folling/239a1c24725799752603a64d44c4ecca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn rename_blueprint( | |
&mut self, | |
ctx: &mut Context, | |
db_handle: &Transaction, | |
blueprint_id: Uuid, | |
new_name: &str, | |
) -> Result<(), DataError> { | |
ctx.debug(format!("Renaming blueprint {} to {}", blueprint_id, new_name)); | |
self.assert_blueprint_exists(ctx, db_handle, blueprint_id)?; | |
let mut stmt = db_handle.prepare("UPDATE `blueprints` SET `name` = ? WHERE `id` == ?") | |
.on_err(|_| ctx.err("Unable to prepare update statement"))?; | |
let changed_rows = stmt.execute(params![new_name.to_string(), blueprint_id]) | |
.on_err(|_| ctx.err("Unable to update name in database"))?; | |
if changed_rows != 1 { | |
ctx.err(format!("Invalid amount of rows changed: {}", changed_rows)); | |
return Err(DataError::InvalidChangeCount { changes: changed_rows, expected_changes: 1 }); | |
} | |
ctx.blueprint_renamed(blueprint_id, new_name); | |
Ok(()) | |
} | |
pub fn rename_attribute( | |
&mut self, | |
ctx: &mut Context, | |
db_handle: &Transaction, | |
attribute_id: Uuid, | |
new_name: &str, | |
) -> Result<(), DataError> { | |
ctx.debug(format!("Renaming attribute {} to {}", attribute_id, new_name)); | |
self.assert_attribute_exists(ctx, db_handle, attribute_id)?; | |
let mut stmt = db_handle.prepare("UPDATE `attributes` SET `name` = ? WHERE `id` == ?") | |
.on_err(|_| ctx.err("Unable to prepare update statement"))?; | |
let changed_rows = stmt.execute(params![new_name.to_string(), attribute_id]) | |
.on_err(|_| ctx.err("Unable to update name in database"))?; | |
if changed_rows != 1 { | |
ctx.err(format!("Invalid amount of rows changed: {}", changed_rows)); | |
return Err(DataError::InvalidChangeCount { changes: changed_rows, expected_changes: 1 }); | |
} | |
ctx.attribute_renamed(attribute_id, new_name); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment