Skip to content

Commit

Permalink
Sheet Database #2 (#114)
Browse files Browse the repository at this point in the history
* Flexible

* Update & Delete
  • Loading branch information
KyGost authored Apr 8, 2022
1 parent 4a63f86 commit 67154a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
5 changes: 2 additions & 3 deletions src/storages/sheet_storage/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ fn schema_from_sheet(sheet: &Worksheet) -> Result<Schema> {
if coordinate.get_row_num() == &1 {
let col = coordinate.get_col_num();
let text = comment.get_text().get_text();
let column_def: Result<Column> = serde_yaml::from_str(text)
.map_err(|_| SheetStorageError::FailedColumnParse.into());
Some(column_def.map(|column_def| (col, column_def)))
let column_def: Column = serde_yaml::from_str(text).unwrap_or_default();
Some(Ok((col, column_def)))
} else {
None
}
Expand Down
42 changes: 18 additions & 24 deletions src/storages/sheet_storage/store_mut.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use umya_spreadsheet::{Comment, RichText, TextElement};

use {
crate::{Result, Row, Schema, SheetStorage, SheetStorageError, StoreMut},
crate::{Cast, Result, Row, Schema, SheetStorage, SheetStorageError, StoreMut, Value},
async_trait::async_trait,
};

Expand Down Expand Up @@ -64,30 +64,24 @@ impl StoreMut for SheetStorage {

// umya: #47 async fn delete_schema(&mut self, sheet_name: &str) -> Result<()>

// Oh! Ick! Table not specified... oops. TODO: #99
/*async fn update_data(&mut self, rows: Vec<(Value, Row)>) -> Result<()> {
async fn update_data(&mut self, sheet_name: &str, rows: Vec<(Value, Row)>) -> Result<()> {
let sheet = self.get_sheet_mut(sheet_name)?;
rows.into_iter()
.try_for_each(|(key, Row(row))| {
let row: i64 = key.cast()?;
row.into_iter().enumerate().for_each(|(col_num, cell)| {
sheet
.get_cell_by_column_and_row_mut(
col_num as u32 + 1,
row as u32,
)
.set_value(cell);
});
Ok(())
})
rows.into_iter().try_for_each(|(key, Row(row))| {
let row_num: i64 = key.cast()?;
row.into_iter().enumerate().for_each(|(col_num, cell)| {
sheet
.get_cell_by_column_and_row_mut(col_num as u32 + 1, row_num as u32)
.set_value(cell);
});
Ok(())
})
}

async fn delete_data(&mut self, rows: Vec<Value>) -> Result<()> {
rows.into_iter()
.try_for_each(|(key, Row(row))| {
let row: i64 = key.cast()?;
self.book.remove_row(sheet_name, row, 1);
Ok(())
})
}*/
async fn delete_data(&mut self, sheet_name: &str, rows: Vec<Value>) -> Result<()> {
rows.into_iter().try_for_each(|key| {
let row_num: i64 = key.cast()?;
self.book.remove_row(sheet_name, row_num as u32, 1);
Ok(())
})
}
}

0 comments on commit 67154a6

Please sign in to comment.