[DRAFT PR] ORMTables -- DatabaseTables with less boilerplate #416
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.
Overview
ORM tables are a new variant on DatabaseTables:
initial_create,initial_migrate,get_by,delete, andupdate_or_add(upsert) are handled for youfrom_recordDifferences from DatabaseTable:
__uniques__MUST be a tuple of primary key column names! Do not set it to a string! Runtime will check for this and yell at you!__version__is None. This means that versions/migrations will be computed from arguments given to Column (see next section)initial_create/initial_migratewill create the latest version of the table, rather than version 0.Versioning:
channel_id, name the thingchannel_id: int = db.Column("bigint NOT NULL")db.Column.versionto see when the first version a column is introduced.It will then either just add the column using ALTER TABLE ADD COLUMN or run a custom script via whatever script is in
Column.alter_tbl.You can also override cls.initial_create and cls.initial_migrate to have tables created at version 0 and upgraded all the way up,
like DatabaseTable.
Worked example:
TODO