Load Computers from Database File #11

Closed
opened 2022-09-05 03:02:20 +00:00 by engineerjoe440 · 2 comments

When we start our little application, we want all of the computers in the database file to load into the table, right?

So...

Remember how tinydb has that db.all() method that returns a list of all the different items in the database? Something like:

[
    {"-Serial Number-": "1234", "Brand": "dell", "Grade": "7", "Name": "jb"},
    {"-Serial Number-": "1", "Brand": "2", "Grade": "3", "Name": "4"}
]

And remember how the table is a list-of-lists? and how it looked something like this:

[["word", "Yes"], ["", "", "", ""]]

Well, we need to make some kind of conversion between those two. I mean, we need to take the list of dictionaries that tinydb gives us, and turn that into some kind of list of lists. Shouldn't be too hard!™ ©

In a nutshell, we'll need to do a few things.

  1. Iterate over each item in the list of dictionaries given to us by tinydb, that way we can use each one to create a new row entry. (since each entry in the database is a unique computer, right?)
  2. Take each value (by key) and arrange into a list that matches the column-headings of our table.

tip!

We can actually make a neat little "global variable" that'll help us keep these names in the same order, so if we ever decide to change the order, it'll take effect accross-the-board, and we won't have to remember it in all sorts of different places.

  1. Append each new (inner) list to the (outer) list, making a nested data-structure which will create our table.
  2. Update our table element in the window with the same logic that we're already using here
When we start our little application, we want all of the computers in the database file to load into the table, right? So... Remember how [tinydb](https://tinydb.readthedocs.io/en/latest/getting-started.html#basic-usage) has that `db.all()` method that returns a list of all the different items in the database? Something like: ```json [ {"-Serial Number-": "1234", "Brand": "dell", "Grade": "7", "Name": "jb"}, {"-Serial Number-": "1", "Brand": "2", "Grade": "3", "Name": "4"} ] ``` And remember how the table is a list-of-lists? and how it looked something like this: ```json [["word", "Yes"], ["", "", "", ""]] ``` Well, we need to make some kind of conversion between those two. I mean, we need to take the list of dictionaries that `tinydb` gives us, and turn that into some kind of list of lists. Shouldn't be too hard!™ © In a nutshell, we'll need to do a few things. 1. Iterate over each item in the list of dictionaries given to us by `tinydb`, that way we can use each one to create a new row entry. (since each entry in the database is a unique computer, right?) 2. Take each value (by key) and arrange into a list that matches the column-headings of our table. > tip! > > We can actually make a neat little "global variable" that'll help us keep these names in the same order, so if we ever decide to change the order, it'll take effect accross-the-board, and we won't have to remember it in all sorts of different places. 3. Append each new (inner) list to the (outer) list, making a nested data-structure which will create our table. 4. Update our table element in the window with the same logic that we're already using [here](https://gitea.stanleysolutionsnw.com/Potlatch-Loggers/ComputerKeeper/src/branch/main/main.py#L59)
engineerjoe440 added this to the Initial Prototype milestone 2022-09-05 03:02:20 +00:00
engineerjoe440 added the
core
enhancement
labels 2022-09-05 03:02:20 +00:00
joshb was assigned by engineerjoe440 2022-09-05 03:02:20 +00:00
Author
Owner

We were still running into some kind of issue with this. We'll need to look at what's going on with that bug preventing the app from running properly.

We were still running into some kind of issue with this. We'll need to look at what's going on with that bug preventing the app from running properly.
Author
Owner

Completed

This was fully realized in commit 801d3b4b1d, now allowing us to load from the database file, and remove computers (both from the table and the DB).

# Completed This was fully realized in commit https://gitea.stanleysolutionsnw.com/Potlatch-Loggers/ComputerKeeper/commit/801d3b4b1dcda67e4be1a2142e4f84e3588b24a5, now allowing us to load from the database file, and remove computers (both from the table and the DB).
Sign in to join this conversation.
No description provided.