-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Immutable columns #138
Comments
If we take the generic annotation approach, we have distinct use cases that call for immutability:
All these field types need immutability, but we get a couple extra use cases:
We're aiming for an API that looks like this, where class MyModel(db.Model):
my_field = immutable(db.Column(db.Unicode(250))) How would this API allow multiple annotations? Options:
|
SQLAlchemy's extensive use of We will instead need a global dictionary that maps objects to these attributes, which is then read back during a |
Problem with using a global dictionary: if an attribute is declared with |
SQLAlchemy allows listening to However, since we are inserting |
Implementation and additional discussion in #141. |
As discussed in #100, there is a need for immutable columns on models with the following characteristics:
This Stack Overflow answer demonstrates how to achieve immutability using SQLAlchemy events. While this doesn't validate within the database, it's not a major concern as immutability is an application data model feature: immutable fields are a signal that cache fields in other models (or in other databases) can hold their cached values indefinitely without risk.
Note that an immutable field is not necessarily a natural key and should not be used to identify the row. It may, for instance, be a type field indicating the type of data the row holds.
We can use the annotation mechanism introduced with
RoleMixin
in #109 to implement anImmutableMixin
orAnnotationMixin
.The text was updated successfully, but these errors were encountered: