cur.close()
con.commit()
+
+ if verbose:
+ print_stats(con)
+
con.close()
if verbose:
print("\nDone!")
return True
+def print_stats(con: sqlite3.Connection) -> None:
+ """Prints database statistics"""
+ cur = con.cursor()
+ print("-" * 40)
+ print(f"Database: {NT_DB_NAME}")
+
+ if os.path.exists(NT_DB_NAME):
+ size_bytes = os.path.getsize(NT_DB_NAME)
+ print(f"Size: {size_bytes / 1024:.2f} KB")
+
+ cur.execute("PRAGMA user_version")
+ version = cur.fetchone()[0]
+ print(f"Version: {version}")
+ print("-" * 40)
+ print("Table Statistics:")
+ print("-" * 40)
+ print(f"{'Table':<20} | {'Rows':>10}")
+ print("-" * 40)
+
+ cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")
+ tables = cur.fetchall()
+
+ total_rows = 0
+ for (table,) in tables:
+ if table == "sqlite_sequence":
+ continue
+ cur.execute(f"SELECT COUNT(*) FROM {table}")
+ count = cur.fetchone()[0]
+ total_rows += count
+ print(f"{table:<20} | {count:>10,}")
+
+ print("-" * 40)
+ print(f"{'TOTAL':<20} | {total_rows:>10,}")
+ print("-" * 40)
+ cur.close()
+
+
if __name__ == "__main__":
build_ntsqlite(verbose=True) # pragma: no cover
+++ /dev/null
-id,version,created,notes
-1,0.0.0,2020-09-22,initial release
-2,0.0.1,2021-05-21,bump version
-3,0.0.2,2021-05-24,remove guids
-4,0.0.3,2021-05-24,general cleanup
-5,0.0.4,2021-06-17,"add custom foods tables (custom_foods, cf_dat)"
-6,0.0.5,2022-07-11,remove biometrics
-7,0.0.6,2022-07-14,"rename tables, start to organize for plugins"
-8,0.0.7,2024-02-25,"add bug table"
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-CREATE TABLE `version` (
- id integer PRIMARY KEY AUTOINCREMENT,
- `version` text NOT NULL UNIQUE,
- created date NOT NULL,
- notes text
-);
+PRAGMA user_version = 9;
-- NOTE: INSERT INTO statements for version, bmr_eq, bf_eq? Don't maintain as CSV?
-- TODO: enforce FK constraint across two DBs?
gender text,
dob date,
act_lvl int DEFAULT 2, -- [1, 2, 3, 4, 5]
+ height real, -- cm
+ weight real, -- kg
goal_wt real,
goal_bf real DEFAULT 18,
bmr_eq_id int DEFAULT 1,