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),
|
(_, Condition::Real(_)) => return Err(FailedTo::ComposeFilter),
|
||||||
// TEXT
|
// TEXT
|
||||||
(Comparison::IsExactly, Condition::Text(_)) => {
|
(Comparison::IsExactly, Condition::Text(_)) => compose_fragment(name, "value_text", "=", i),
|
||||||
compose_fragment(name, "value_text", "=", i)
|
|
||||||
}
|
|
||||||
(
|
(
|
||||||
Comparison::StartsWith | Comparison::EndsWith | Comparison::Contains,
|
Comparison::StartsWith | Comparison::EndsWith | Comparison::Contains,
|
||||||
Condition::Text(_),
|
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_id ON attribute (id);
|
||||||
CREATE INDEX IF NOT EXISTS attribute_entity_id ON attribute (entity_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
|
connection
|
||||||
.execute_batch(init_statement)
|
.execute_batch(init_statement)
|
||||||
.map_err(|sqlite_error| sqlite::FailedTo::ExecuteBatch(sqlite_error))?;
|
.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> {
|
pub fn run(path: &path::Path, entity_class: &str) -> Result<Vec<Entity>, FailedTo> {
|
||||||
let mut entities = Vec::<Entity>::new();
|
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
|
let mut transaction = connection
|
||||||
.transaction()
|
.transaction()
|
||||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
.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> {
|
pub fn run(path: &path::Path, filter: &Filter) -> Result<Vec<Entity>, FailedTo> {
|
||||||
let mut entities = Vec::<Entity>::new();
|
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
|
let mut transaction = connection
|
||||||
.transaction()
|
.transaction()
|
||||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
.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> {
|
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
|
let mut transaction = connection
|
||||||
.transaction()
|
.transaction()
|
||||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
.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> {
|
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
|
let transaction = connection
|
||||||
.transaction()
|
.transaction()
|
||||||
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
.map_err(|sqlite_error| sqlite::FailedTo::BeginTransaction(sqlite_error))?;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ pub enum FailedTo {
|
|||||||
/// Failed to execute a prepared SQL statement.
|
/// Failed to execute a prepared SQL statement.
|
||||||
ExecuteStatement(rusqlite::Error),
|
ExecuteStatement(rusqlite::Error),
|
||||||
/// Failed to open a connection to the SQLite database.
|
/// Failed to open a connection to the SQLite database.
|
||||||
OpenConnection,
|
OpenConnection(rusqlite::Error),
|
||||||
/// Failed to prepare a SQL statement for execution.
|
/// Failed to prepare a SQL statement for execution.
|
||||||
PrepareStatement,
|
PrepareStatement,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user