python - What's a good general way to look SQLAlchemy transactions, complete with authenticated user, etc? -


I am using the declarative expansion of SQLAlchemy. I want to make all the changes in logs of tables, which contain changes in many-to-many relationships (mapping tables). Each table should have a separate "log" table with a similar schema, Additional columns, who have made changes, etc.

My programming model will be something like this:

  row.foo = 1 row.log_version (user name, change_details, ...)  

Ideally, the system does not allow transactions to be transacted without logging .log_version.

Thoughts?

There are too many questions in one, so they will not fit into the full answer stack overflow answer format. . I will try to describe the signs briefly, so ask different questions for them if this is not enough.

User assignment and transaction details

The most popular way to do this is to specify the user (and other information) some global objects ( threading.local () in the threaded application). It is very bad, which makes it difficult to find bugs.

A better method is assigning to the user in session. This is fine when the session is created for each web request (in fact, it is by no means the best design for application with authentication), because this user is the only user to use this session. But passing such details is not as good.

And my favorite solution is to the extent of sessions. Commit () method to accept alternate users (and perhaps other information) and assign it to the present transaction, it is the most flexible, and also the suit to pass the details is also note that The information is bound for a single transaction and the transaction is clearly passed when the transaction is closed.

Search for changes

is a sqlalchemy.org.attributes.instance_state (obj)) All information is required in . Perhaps the most useful for you is probably the original position for the converted region (including many-to-many relationships!) In the state.committed_state dictionary. state.get_history () method (or sqlalchemy.org.attributes.get_history () function) has_changes () method and added and deleted value for new and old prices respectively. In the latter case, use state.manager.keys () (or state.manager.attributes ) to get a list of all fields.

Automatically change storage

Supports SQLLEM Mapper Extensions which can provide hooks before and after the update, insert and delete. Before the hook you need to provide your extension (you can not use it after changing the position of the object on the flush) It is easy to write the subdivision of declarative matte for declarative detail Adds Mapper Expansion to all your models Note that two times the changes have to be flushed using the mapped object to log in, because the unit of work hooks Does not account for objects created in


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

jquery - SimpleModal Confirm fails to submit form -