feat: encapsulate rusqlite::Error into sqlite::FailedTo (ExecuteQuery)
This commit is contained in:
@@ -20,7 +20,7 @@ pub fn run(transaction: &Transaction, entity: &mut Entity) -> Result<(), FailedT
|
|||||||
.map_err(|_| sqlite::FailedTo::PrepareStatement)?;
|
.map_err(|_| sqlite::FailedTo::PrepareStatement)?;
|
||||||
let attributes = select_attributes_statement
|
let attributes = select_attributes_statement
|
||||||
.query_map([&entity.id], sqlite::map::row_to_attribute)
|
.query_map([&entity.id], sqlite::map::row_to_attribute)
|
||||||
.map_err(|_| sqlite::FailedTo::ExecuteQuery)?;
|
.map_err(|sqlite_error| sqlite::FailedTo::ExecuteQuery(sqlite_error))?;
|
||||||
for attribute in attributes {
|
for attribute in attributes {
|
||||||
let attribute = attribute.map_err(|_| FailedTo::MapAttribute)?;
|
let attribute = attribute.map_err(|_| FailedTo::MapAttribute)?;
|
||||||
entity.attributes.insert(attribute.id.clone(), attribute);
|
entity.attributes.insert(attribute.id.clone(), attribute);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub fn run(path: &path::Path, entity_class: &str) -> Result<Vec<Entity>, FailedT
|
|||||||
.map_err(|_| sqlite::FailedTo::PrepareStatement)?;
|
.map_err(|_| sqlite::FailedTo::PrepareStatement)?;
|
||||||
let result = statement
|
let result = statement
|
||||||
.query_map([entity_class], sqlite::map::row_to_entity)
|
.query_map([entity_class], sqlite::map::row_to_entity)
|
||||||
.map_err(|_| sqlite::FailedTo::ExecuteQuery)?;
|
.map_err(|sqlite_error| sqlite::FailedTo::ExecuteQuery(sqlite_error))?;
|
||||||
for entity in result {
|
for entity in result {
|
||||||
let mut entity = entity.map_err(|_| FailedTo::MapEntity)?;
|
let mut entity = entity.map_err(|_| FailedTo::MapEntity)?;
|
||||||
sqlite::load::attributes(&transaction, &mut entity)?;
|
sqlite::load::attributes(&transaction, &mut entity)?;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub fn run(path: &path::Path, filter: &Filter) -> Result<Vec<Entity>, FailedTo>
|
|||||||
.map_err(|_| sqlite::FailedTo::PrepareStatement)?;
|
.map_err(|_| sqlite::FailedTo::PrepareStatement)?;
|
||||||
let result = statement
|
let result = statement
|
||||||
.query_map(¶ms[..], sqlite::map::row_to_entity)
|
.query_map(¶ms[..], sqlite::map::row_to_entity)
|
||||||
.map_err(|_| sqlite::FailedTo::ExecuteQuery)?;
|
.map_err(|sqlite_error| sqlite::FailedTo::ExecuteQuery(sqlite_error))?;
|
||||||
for entity in result {
|
for entity in result {
|
||||||
let mut entity = entity.map_err(|_| FailedTo::MapEntity)?;
|
let mut entity = entity.map_err(|_| FailedTo::MapEntity)?;
|
||||||
sqlite::load::attributes(&transaction, &mut entity)?;
|
sqlite::load::attributes(&transaction, &mut entity)?;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub fn run(path: &path::Path, entity_id: &str) -> Result<Option<Entity>, FailedT
|
|||||||
let mut entity = transaction
|
let mut entity = transaction
|
||||||
.query_one(SELECT_ENTITY_BY_ID, [entity_id], sqlite::map::row_to_entity)
|
.query_one(SELECT_ENTITY_BY_ID, [entity_id], sqlite::map::row_to_entity)
|
||||||
.optional()
|
.optional()
|
||||||
.map_err(|_| sqlite::FailedTo::ExecuteQuery)?;
|
.map_err(|sqlite_error| sqlite::FailedTo::ExecuteQuery(sqlite_error))?;
|
||||||
if let Some(ref mut entity) = entity {
|
if let Some(ref mut entity) = entity {
|
||||||
sqlite::load::attributes(&transaction, entity)?;
|
sqlite::load::attributes(&transaction, entity)?;
|
||||||
entity.state = EntityState::Loaded;
|
entity.state = EntityState::Loaded;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ pub enum FailedTo {
|
|||||||
/// Failed to execute a batch of SQL statements.
|
/// Failed to execute a batch of SQL statements.
|
||||||
ExecuteBatch(rusqlite::Error),
|
ExecuteBatch(rusqlite::Error),
|
||||||
/// Failed to execute a SQL query.
|
/// Failed to execute a SQL query.
|
||||||
ExecuteQuery,
|
ExecuteQuery(rusqlite::Error),
|
||||||
/// Failed to execute a prepared SQL statement.
|
/// Failed to execute a prepared SQL statement.
|
||||||
ExecuteStatement,
|
ExecuteStatement,
|
||||||
/// Failed to open a connection to the SQLite database.
|
/// Failed to open a connection to the SQLite database.
|
||||||
|
|||||||
Reference in New Issue
Block a user