tullinge / booking

🎫 Bokningssystem för allaktivitetsdag
MIT License
0 stars 1 forks source link

Return MySQL data as dictionaries to avoid confusion #18

Open vilhelmprytz opened 4 years ago

vilhelmprytz commented 4 years ago

Queries in the current setup returns lists, which can make it confusing concerning which key is which. Using dictionaries, we can avoid confusion during coding (refactoring, doesn't necessarily change anything for the end user).

Right now, querying for the class of a student looks like this.

result = sql_query("SELECT * FROM students WHERE id=0")

print(result[0][4])

The first [0] is the element of the "search query" (which in this case should only consist of one element, as the id should always be unique) and the second [4] refers to the fourth column, which in this case is the class of the student row.

See this StackOverflow question for more information on how to do this.

vilhelmprytz commented 4 years ago

Too much of main codebase is based on using tuples. We've decided to not fix this until we're finished with a "stable" initial release.