feat: encapsulate rusqlite::Error into sqlite::FailedTo (OpenConnection)
This commit is contained in:
@@ -71,9 +71,7 @@ fn from_condition(
|
||||
}
|
||||
(_, Condition::Real(_)) => return Err(FailedTo::ComposeFilter),
|
||||
// TEXT
|
||||
(Comparison::IsExactly, Condition::Text(_)) => {
|
||||
compose_fragment(name, "value_text", "=", i)
|
||||
}
|
||||
(Comparison::IsExactly, Condition::Text(_)) => compose_fragment(name, "value_text", "=", i),
|
||||
(
|
||||
Comparison::StartsWith | Comparison::EndsWith | Comparison::Contains,
|
||||
Condition::Text(_),
|
||||
|
||||
@@ -25,7 +25,8 @@ pub fn run(path: &path::Path) -> result::Result<(), FailedTo> {
|
||||
CREATE INDEX IF NOT EXISTS attribute_id ON attribute (id);
|
||||
CREATE INDEX IF NOT EXISTS attribute_entity_id ON attribute (entity_id);
|
||||
"#;
|
||||
let connection = Connection::open(path).map_err(|_| sqlite::FailedTo::OpenConnection)?;
|
||||
let connection = Connection::open(path)
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::OpenConnection(sqlite_error))?;
|
||||
connection
|
||||
.execute_batch(init_statement)
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::ExecuteBatch(sqlite_error))?;
|
||||
|
||||
@@ -8,7 +8,8 @@ const SELECT_ENTITY_BY_CLASS: &str = r#"
|
||||
|
||||
pub fn run(path: &path::Path, entity_class: &str) -> Result<Vec<Entity>, FailedTo> {
|
||||
let mut entities = Vec::<Entity>::new();
|
||||
let mut connection = Connection::open(path).map_err(|_| sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::OpenConnection(sqlite_error))?;
|
||||
let mut transaction = connection
|
||||
.transaction()
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
||||
|
||||
@@ -3,7 +3,8 @@ use rusqlite::*;
|
||||
|
||||
pub fn run(path: &path::Path, filter: &Filter) -> Result<Vec<Entity>, FailedTo> {
|
||||
let mut entities = Vec::<Entity>::new();
|
||||
let mut connection = Connection::open(path).map_err(|_| sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::OpenConnection(sqlite_error))?;
|
||||
let mut transaction = connection
|
||||
.transaction()
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
||||
|
||||
@@ -7,7 +7,8 @@ const SELECT_ENTITY_BY_ID: &str = r#"
|
||||
"#;
|
||||
|
||||
pub fn run(path: &path::Path, entity_id: &str) -> Result<Option<Entity>, FailedTo> {
|
||||
let mut connection = Connection::open(path).map_err(|_| sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::OpenConnection(sqlite_error))?;
|
||||
let mut transaction = connection
|
||||
.transaction()
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
||||
|
||||
@@ -66,7 +66,8 @@ fn write_entity(entity: &Entity, transaction: &rusqlite::Transaction) -> Result<
|
||||
}
|
||||
|
||||
pub fn run(path: &path::Path, items: &HashMap<String, Entity>) -> result::Result<(), FailedTo> {
|
||||
let mut connection = Connection::open(path).map_err(|_| sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::OpenConnection(sqlite_error))?;
|
||||
let transaction = connection
|
||||
.transaction()
|
||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
||||
|
||||
@@ -14,7 +14,7 @@ pub enum FailedTo {
|
||||
/// Failed to execute a prepared SQL statement.
|
||||
ExecuteStatement(rusqlite::Error),
|
||||
/// Failed to open a connection to the SQLite database.
|
||||
OpenConnection,
|
||||
OpenConnection(rusqlite::Error),
|
||||
/// Failed to prepare a SQL statement for execution.
|
||||
PrepareStatement,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user