Rust CLI tool to push CSV data (water and car readings) into SQLite database. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
1.6 KiB
Markdown
54 lines
1.6 KiB
Markdown
this project is a tool CLI that can take CSV file and push its content into a sqlite database.
|
|
|
|
the CSV files have the following columns:
|
|
|
|
- Date
|
|
- Eau
|
|
- Scénic
|
|
- Zoé
|
|
|
|
the sqlite databases has been created with the following command:
|
|
|
|
CREATE TABLE "eau"
|
|
(
|
|
date TEXT not null
|
|
primary key
|
|
unique,
|
|
releve REAL not null,
|
|
comment TEXT
|
|
)
|
|
|
|
CREATE TABLE "voiture1" (
|
|
"date" TEXT NOT NULL UNIQUE,
|
|
"releve" INTEGER NOT NULL,
|
|
"comment" TEXT,
|
|
PRIMARY KEY("date")
|
|
)
|
|
|
|
CREATE TABLE "voiture2"
|
|
(
|
|
date TEXT not null,
|
|
releve INTEGER not null,
|
|
comment TEXT
|
|
)
|
|
|
|
CSV columns "Date" and "Eau" has to be pushed to database table "eau" on columns "date" and "releve". no push if "Eau" is empty
|
|
CSV columns "Date" and "Scénic" has to be pushed to database table "voiture1" on columns "date" and "releve". no push if "Scénic" is empty
|
|
CSV columns "Date" and "Zoé" has to be pushed to database table "voiture2" on columns "date" and "releve". no push if "Zoé" is empty
|
|
|
|
the CLI takes 2 parameters:
|
|
|
|
- first is the name of the CSV file
|
|
- second is the JDBC URL (for example, "jdbc:sqlite:/Users/kriss/NextCloud/Kriss/Dev/Perso/conso/db/conso.db")
|
|
|
|
when launched, the tool checks that:
|
|
|
|
- CSV file exists on the disk
|
|
- CSV file contains exactly the described columns
|
|
- Sqlite database is accessible through the JDBC URL
|
|
- Ensure there won't be any duplicates inserted in the database (which means if the tool is launched twice in a row, no new lines will be inserted)
|
|
- Tell the user how many new lines are going to be inserted in the database, and ask his agreement before proceeding
|
|
- Performs the insert in the database
|
|
|
|
this project is written in Rust.
|