Support account IDs

This commit is contained in:
2024-10-15 21:35:55 +01:00
parent e3ed72c9b0
commit 5c3f734bbc
10 changed files with 132 additions and 29 deletions
+7 -2
View File
@@ -44,6 +44,10 @@ enum Commands {
Csv {
/// The path of the CSV file to ingest.
csv_file: PathBuf,
/// The name of the account to ingest the CSV for.
#[clap(long, short)]
account: String,
},
}
@@ -94,7 +98,7 @@ async fn main() -> anyhow::Result<()> {
serve_web(addr, connection).await?;
}
Commands::Csv { csv_file } => {
Commands::Csv { csv_file, account: account_name } => {
let mut csv = csv::Reader::from_reader(File::open(csv_file)?);
let data = csv.records();
let data = data
@@ -102,7 +106,8 @@ async fn main() -> anyhow::Result<()> {
.map(from_csv_row)
.collect::<Result<_, _>>()?;
db::insert(&connection, data).await?;
let account_id = db::get_account_id(&connection, Some(account_name)).await?;
db::insert(&connection, data, account_id).await?;
}
}