Conversation
instead of manually specifying schemata in init-db.sql, we can describe the fields and their properties as members of classes within a hierarchy of classes inheriting from peewee orm's base model. Obviously peewee orm can do a lot more than generate schemata, but this is a nice (and fully backwards compatible) start on the work towards fully embracing peewee for all database operations. The existing queries continue to work because the schemata generated are fully compatible with the existing ones (albeit not identical, so the binary blob needed updating). This means that the existing db code can be slowly phased out in the next commits and orbit will remain fully functional throughout.
theyoyojo
requested changes
Apr 26, 2024
All calls to the `db.ses_*` functions are replaced by corresponding code that performs equivalent queries using peewee orm functionality. The resulting code is both clearer: no need for random [0] on the result, able to use field names instead of [0], [1], [2] etc; and more expressive: the logic used is spelled out using normal python syntax like `field == value` instead of hidden away in a helper function while not being longer.
All calls to the `db.ses_*` functions are replaced by corresponding code that performs equivalent queries using peewee orm functionality. Also includes a minor cleanup on the code that prints the list of sessions. Printing a header and then no values is as clear or clearer than printing `(no sessions)` imo, and the code is substantially more simple as a result.
Now that hyperspace and radius are using peewee orm exclusively for accessing the sessions table, these functions are unused and can be removed.
All calls to the `db.reg_*` functions are replaced by corresponding code that performs equivalent queries using peewee orm functionality.
All calls to the `db.reg_*` functions are replaced by corresponding code that performs equivalent queries using peewee orm functionality.
Now that hyperspace and radius are using peewee orm exclusively for accessing the registration table, these functions and their associated queries are unused and can be removed.
The credentials were being checked very similarly in two places in the code. Moving the check to a helper means that the code can be more expressive (early return in function instead of short circuit that is too long to fit on one line, and self documenting at call sites) and it means there is one source of truth about how to perform this critical operation.
All calls to the `db.usr_*` functions are replaced by corresponding code that performs equivalent queries using peewee orm functionality.
All calls to the `db.usr_*` functions are replaced by corresponding code that performs equivalent queries using peewee orm functionality.
Now that hyperspace and radius are using peewee orm exclusively for accessing the user table, these functions and their associated queries are unused and can be removed.
Now that all db queries are executed using peewee, there is no need for the old functions for accessing the database or for the imports that they required.
Now that there are no legacy queries to be backwards compatible with we do not need to specify the table names explicitly and can let peewee generate them automatically. This required updating the binary blob to reflect the new names.
Merged
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Complete overhaul of the database code to replace manually created SQL queries with expressive code using peewee orm.