diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-08-24 02:59:24 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-08-24 02:59:24 -0400 |
commit | 867ccb676ec2f575643f11f60a4b52d13ef248ed (patch) | |
tree | e7e867084c9d27258096e06b967c310dec16a9e4 | |
parent | 6008f59b54be406324694abccc205b9e2d5422d3 (diff) | |
download | ynab-export-867ccb676ec2f575643f11f60a4b52d13ef248ed.tar.gz ynab-export-867ccb676ec2f575643f11f60a4b52d13ef248ed.zip |
add month data
-rw-r--r-- | data/schema.sql | 18 | ||||
-rw-r--r-- | src/main.rs | 36 |
2 files changed, 54 insertions, 0 deletions
diff --git a/data/schema.sql b/data/schema.sql index 8a9fc3b..8628605 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -1,6 +1,8 @@ DROP TABLE IF EXISTS subtransactions; DROP TABLE IF EXISTS transactions; DROP TABLE IF EXISTS payees; +DROP TABLE IF EXISTS categories_by_month; +DROP TABLE IF EXISTS months; DROP TABLE IF EXISTS categories; DROP TABLE IF EXISTS category_groups; DROP TABLE IF EXISTS accounts; @@ -33,6 +35,22 @@ CREATE TABLE categories ( balance bigint NOT NULL ); +CREATE TABLE months ( + month text PRIMARY KEY +); + +CREATE TABLE categories_by_month ( + month text REFERENCES months(month), + id text REFERENCES categories(id), + category_group_id text REFERENCES category_groups(id) NOT NULL, + name text NOT NULL, + hidden boolean NOT NULL, + budgeted bigint NOT NULL, + activity bigint NOT NULL, + balance bigint NOT NULL, + PRIMARY KEY (month, id) +); + CREATE TABLE payees ( id text PRIMARY KEY, name text NOT NULL, diff --git a/src/main.rs b/src/main.rs index 45e2a72..85623cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,4 +219,40 @@ fn main() { file.write_all(b"\n").unwrap(); } file.sync_all().unwrap(); + + let mut file = std::fs::File::create("months.tsv").unwrap(); + let mut file2 = std::fs::File::create("categories_by_month.tsv").unwrap(); + for month in budget.months.unwrap() { + if month.deleted { + continue; + } + file.write_all([month.month.as_ref()].join("\t").as_bytes()) + .unwrap(); + file.write_all(b"\n").unwrap(); + + for category in month.categories { + if category.deleted { + continue; + } + file2 + .write_all( + [ + month.month.as_ref(), + category.id.as_ref(), + category.category_group_id.as_ref(), + category.name.as_ref(), + if category.hidden { "1" } else { "0" }, + &format!("{}", category.budgeted), + &format!("{}", category.activity), + &format!("{}", category.balance), + ] + .join("\t") + .as_bytes(), + ) + .unwrap(); + file2.write_all(b"\n").unwrap(); + } + } + file.sync_all().unwrap(); + file2.sync_all().unwrap(); } |