Record classes should have hooks for verification before saving
- Verify the record data is valid for insertion into the database
- Convert data from and to database-safe values, different from Python runtime use
Updated the uWeb database model to provide hooks before and after creation and saving, and upon loading from the database. This resolves #851.
#2 Updated by Elmer de Looff over 7 years ago
- Status changed from Resolved to Closed
- % Done changed from 70 to 100
This has been implemented and confirmed to work.
VersionedRecord now also do not write to the database when no changes have occurred. This reduces the potential number of database actions.
#3 Updated by Elmer de Looff over 7 years ago
The provided hooks are:
_PreCreatewill run before a record is inserted into the database using the
_PostCreatewill run after a record is inserted into the database using the
_PreSavewill run when the
Savemethod is used, right before the database is updated. This method will only trigger if changes have been made.
_PostSavewill run after the database has been updated (through the
Savemethod. This method will only trigger if changes have been made.
N.B.: For subclasses of
Record, the above methods will be called inside the database transaction. The currently open cursor will be provided for the methods to query the database with, as opening new transactions is not possible.
MongoRecord will not be provided a cursor instance (but will not have the transaction limitation).
Additionally, there is the
_PostInit method, which will run after an object is initialized. This means that objects loaded from the database can be transformed by
_PostInit. This method will not run for Record instantiated through
_PreCreate for those). This method is not part of a transaction, and will therefor not get a
cursor instance provided.