Feat: import and export csv (#2617)

* feat: import csv

* feat: export

* chore: implement import export csv in the backend

* chore: patch
This commit is contained in:
Nathan.fooo
2023-05-25 23:22:23 +08:00
committed by GitHub
parent 2746666123
commit 70bb7f2ad6
30 changed files with 555 additions and 150 deletions

View File

@ -0,0 +1,36 @@
use crate::database::database_editor::DatabaseEditorTest;
use flowy_database2::services::share::csv::ExportStyle;
#[tokio::test]
async fn export_and_then_import_test() {
let test = DatabaseEditorTest::new_grid().await;
let database = test.editor.clone();
let csv_1 = database.export_csv(ExportStyle::SIMPLE).await.unwrap();
let imported_database_id = test.import(csv_1.clone()).await;
let csv_2 = test
.get_database(&imported_database_id)
.await
.unwrap()
.export_csv(ExportStyle::SIMPLE)
.await
.unwrap();
let mut reader = csv::Reader::from_reader(csv_1.as_bytes());
let export_csv_records_1 = reader.records();
let mut reader = csv::Reader::from_reader(csv_2.as_bytes());
let export_csv_records_2 = reader.records();
let mut a = export_csv_records_1
.map(|v| v.unwrap())
.flat_map(|v| v.iter().map(|v| v.to_string()).collect::<Vec<_>>())
.collect::<Vec<String>>();
let mut b = export_csv_records_2
.map(|v| v.unwrap())
.flat_map(|v| v.iter().map(|v| v.to_string()).collect::<Vec<_>>())
.collect::<Vec<String>>();
a.sort();
b.sort();
assert_eq!(a, b);
}

View File

@ -0,0 +1 @@
mod export_test;