From 8e17891fa47bae15467381babe55e2368fa0ee0b Mon Sep 17 00:00:00 2001 From: Michael Cuffaro Date: Fri, 3 Nov 2023 10:34:00 -0400 Subject: [PATCH] change 'user_view' to 'text_view'; change get_last_undo() to get_record_to_redo() and get_last_change() to get_record_to_undo() --- scripts/export.py | 2 +- src/lib.rs | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/scripts/export.py b/scripts/export.py index 4a5b0b91..bc61c259 100755 --- a/scripts/export.py +++ b/scripts/export.py @@ -137,7 +137,7 @@ def export_data(cursor, is_sqlite, args): # Fetch the rows from the table and write them to a corresponding TSV file in the # output directory: - cursor.execute(f'SELECT {select} FROM "{table}_user_view" ORDER BY "row_number"') + cursor.execute(f'SELECT {select} FROM "{table}_text_view" ORDER BY "row_number"') colnames = [d[0] for d in cursor.description] rows = map(lambda r: dict(zip(colnames, r)), cursor) fieldnames = [c for c in colnames if c != "row_number"] diff --git a/src/lib.rs b/src/lib.rs index 6c666c88..981bdf83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -838,15 +838,14 @@ fn get_sql_for_standard_view(table: &str, pool: &AnyPool) -> (String, String) { } /// Given the tables configuration map, the name of a table and a database connection pool, -/// generate SQL for creating a more user-friendly version of the view that is generated by +/// generate SQL for creating a more user-friendly version of the view than the one generated by /// [get_sql_for_standard_view()]. Unlike the standard view generated by that function, the view -/// generated by this function (called my_table_user_view) always shows all of the values of every -/// column in the table, even when those values contain errors. Also unlike the standard view, the -/// datatypes of all columns in the user view are TEXT (this is what makes it possible to always -/// display error values). Like the function for generating a standard view, the SQL generated by -/// this function is in the form of a tuple of Strings, with the first string being a SQL statement +/// generated by this function (called my_table_text_view) always shows all of the values (which are +/// all rendered as text) of every column in the table, even when those values contain SQL datatype +/// errors. Like the function for generating a standard view, the SQL generated by this function is +/// returned in the form of a tuple of Strings, with the first string being a SQL statement /// for dropping the view, and the second string being a SQL statement for creating it. -fn get_sql_for_user_view( +fn get_sql_for_text_view( tables_config: &mut SerdeMap, table: &str, pool: &AnyPool, @@ -867,10 +866,10 @@ fn get_sql_for_user_view( .and_then(|t| Some(t.collect::>())) .unwrap(); - // Add a second "user view" such that the datatypes of all values are TEXT and appear + // Add a second "text view" such that the datatypes of all values are TEXT and appear // directly in their corresponsing columns (rather than as NULLs) even when they have - // errors. - let mut drop_view_sql = format!(r#"DROP VIEW IF EXISTS "{}_user_view""#, table); + // SQL datatype errors. + let mut drop_view_sql = format!(r#"DROP VIEW IF EXISTS "{}_text_view""#, table); if pool.any_kind() == AnyKind::Postgres { drop_view_sql.push_str(" CASCADE"); } @@ -928,7 +927,7 @@ fn get_sql_for_user_view( }; let create_view_sql = format!( - r#"CREATE VIEW "{table}_user_view" AS + r#"CREATE VIEW "{table}_text_view" AS SELECT {outer_columns} FROM ( SELECT {inner_columns} @@ -1087,12 +1086,12 @@ pub async fn configure_db( } let (drop_view_sql, create_view_sql) = get_sql_for_standard_view(&table_name, pool); - let (drop_user_view_sql, create_user_view_sql) = - get_sql_for_user_view(tables_config, &table_name, pool); - table_statements.push(drop_user_view_sql); + let (drop_text_view_sql, create_text_view_sql) = + get_sql_for_text_view(tables_config, &table_name, pool); + table_statements.push(drop_text_view_sql); table_statements.push(drop_view_sql); table_statements.push(create_view_sql); - table_statements.push(create_user_view_sql); + table_statements.push(create_text_view_sql); setup_statements.insert(table_name.to_string(), table_statements); } @@ -2047,9 +2046,8 @@ async fn switch_undone_state( Ok(()) } -/// Given a database pool fetch the last database change represented by the last row inserted to the -/// history table that has not been undone. -pub async fn get_last_change(pool: &AnyPool) -> Result, sqlx::Error> { +/// Given a database pool fetch the last row inserted to the history table that has not been undone. +pub async fn get_record_to_undo(pool: &AnyPool) -> Result, sqlx::Error> { // Look in the history table, get the row with the greatest ID, get the row number, // from, and to, and determine whether the last operation was a delete, insert, or update. let is_clause = if pool.any_kind() == AnyKind::Sqlite { @@ -2070,7 +2068,7 @@ pub async fn get_last_change(pool: &AnyPool) -> Result, sqlx::Err /// Given a database pool fetch the row in the history table that has been most recently marked as /// undone. -pub async fn get_last_undo(pool: &AnyPool) -> Result, sqlx::Error> { +pub async fn get_record_to_redo(pool: &AnyPool) -> Result, sqlx::Error> { // Look in the history table, get the row with the greatest ID, get the row number, // from, and to, and determine whether the last operation was a delete, insert, or update. let is_not_clause = if pool.any_kind() == AnyKind::Sqlite { @@ -2100,7 +2098,7 @@ pub async fn undo( pool: &AnyPool, undo_user: &str, ) -> Result<(), sqlx::Error> { - let last_change = match get_last_change(pool).await? { + let last_change = match get_record_to_undo(pool).await? { None => { eprintln!("WARN: Nothing to undo."); return Ok(()); @@ -2196,7 +2194,7 @@ pub async fn redo( pool: &AnyPool, redo_user: &str, ) -> Result<(), sqlx::Error> { - let last_undo = match get_last_undo(pool).await? { + let last_undo = match get_record_to_redo(pool).await? { None => { eprintln!("WARN: Nothing to redo."); return Ok(());