partsdb

electronic parts inventory
git clone https://git.e1e0.net/partsdb.git
Log | Files | Refs

commit 530d9d1e4da899a5705aa97aa013bd85b3cbfb96
parent eee65dd7c1e7094e5b0f8f08b32538d162aa18b4
Author: Paco Esteban <paco@e1e0.net>
Date:   Sat, 13 Mar 2021 10:49:22 +0100

be able to list all parts

Diffstat:
Mdatabase.py | 8+++++++-
MmyChips.py | 10++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/database.py b/database.py @@ -8,6 +8,7 @@ from sqlite3 import Error GET_CATEGORIES_QUERY = "SELECT * FROM categories" GET_STORAGES_QUERY = "SELECT * FROM storages" +LIST_PARTS_QUERY = "SELECT * FROM parts" LIST_PARTS_CATEGORY_QUERY = """ SELECT parts.id, parts.pn FROM parts @@ -62,7 +63,12 @@ class PartsDB(): c.execute(GET_STORAGES_QUERY) return c.fetchall() - def list_parts_with_category(self, category): + def get_parts(self): + c = self.conn.cursor() + c.execute(LIST_PARTS_QUERY) + return c.fetchall() + + def get_parts_with_category(self, category): c = self.conn.cursor() c.execute(LIST_PARTS_CATEGORY_QUERY, (category,)) return c.fetchall() diff --git a/myChips.py b/myChips.py @@ -91,7 +91,10 @@ def add_part(mpn): def list_parts(category): - parts = db.list_parts_with_category(category) + if category == 'all': + parts = db.get_parts() + else: + parts = db.get_parts_with_category(category) if parts is None: print("There are no parts in this category") @@ -122,9 +125,11 @@ def delete_part(part_id): def adjust_stock(part_id, stock_mod): pass + def export_db(dest_folder): pass + def list_categories(): categories = db.get_categories() print("ID\tName") @@ -145,7 +150,8 @@ if __name__ == '__main__': # cat ap_cat = asp.add_parser("cat", help="List categories") # list - ap_list = asp.add_parser("list", help="List all parts from a category") + ap_list = asp.add_parser("list", + help="List all parts from a category (or all)") ap_list.add_argument("category", help="Category Name") # search ap_search = asp.add_parser("search", help="Search for parts")