python - How can I combine the awesomness of SQLAlchemy and EAV DB schemas? -
I have recently been doing something with Pylons and there is enough for SQLAlchemy models for database interaction. My website is a part, although I think it can benefit from the EAV Schema.
Use this as my table example:
id | User ID Type | Value --- + -------- + -------- | ------------ 1 | 1 | Phone | 111 111 111 --- + -------- + -------- | ------------ 2 | 1 | Age 40
To remove and update data, I can run the same questions as the following:
Selection selection of table where userid = 1 more Type = 'phone' update table SET value = 41 where user id = 1 and type = 'age'
It is easy and works ... but manually preparing queries I do not have a favorite attitude to use SQLAlchemy to make my table model and make it all leg Should the.
If I was using a standard schema, where each type
had its own column, I could do the following people:
Class people (base): __tablename__ = 'people' id = column (integer, primary_key = true) userid = column (integer, foreign key ('users.id')) Phone = column (Unicode (40)) age = column (Integer)
Then I could drag data using:
data = session query (people) .filter_b (id = 1) .first () Print Data.ege
I want to be able to do this for my EAV schema. So basically, I have a need to expand to SQLite and tell me that when I call data.age
, then in fact it means, I want to call it from the SELECT value table. WHERE id = 1 and type = 'age'
.
Is this possible? Or will I have to compel my code to mess with my manually released questions?
For an example, see. I think it's more or less that is after you. Examples offer a special type of interface rather than attributes as your example (probably better for arbitrarily metadata keys, rather than some specific attributes).
If you map each attribute separately: luggage documents that may be of interest:
- : You get an arbitrary SQL expression (read-only) How to create a feature for
- , using esp descriptors and custom comparisons: It provokes your properties to use normal dragon properties, and whatever you get / set + Alternatively determines that other values There is a need to work with (for questions).
- : Basically provides a simple view on a relationship. For example, in your case, you are using a custom job presence (not only using the user but also "age" typing) Using
_age
) and using theuselist = False
(because every user only wants to use the value of your key value (or whatever you want to call it) Is an age, you want a single value, not a list). You can then useage = association_proxy ('_ age', 'value')
to show only "value" instead of the entire keyview object.
I think I want to go with vertical specialty mapping example or associationproxy /
Comments
Post a Comment