Hi all,
sorry for pulling out this old thread again. I continuously run into this.
Am 08/09/2010 11:20 PM, schrieb Michael Bayer:
If I'm understanding correctly, that's not as much about merging as it
is for the "unique object" recipe, which is this:
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject which
assumes the usage of a scoped_session. Since you're looking for the
callable EmailAddress to know about a session and you don't want to
pass it in, there's not really any other option.
I like the unique object recipe. However, it goes not far enough for my
use case.
The reason is that it can take seconds for my transactions to complete
(waiting for remote data) and inbetween another database change can add
the object.
Before I resort to trial and error: Is it possible to use
session.merge() in the before_flush event to combine the in-session data
with data already in the database?
The downside is that this requires the transaction isolation level to
allow phantom reads, which I do not really like.
If it is of any interest, I would like to have this for an external BLOB
storage. I use an SQL database to organize access to mass data in a git
like manner. If a new file is imported, the goal is to reuse the content
data if any existing blob has the same hash.
In filesystem this is like
cp new_file.wmv vault/temp/tmpXYZ.dat
hash=`sha1sum vault/temp/tmpXYZ.dat | cut -f 1 -d " "`
if [ -e "vault/$hash" ]; then
# File exists, remove temporary file. Leaves old file untouched
wrt. mtime so
# rsync based backup will be fast
rm vault/temp/tmpXYZ.dat
else
# Add new file. With two concurrent imports, either can end up
being the final file.
# Assuming a good hash, they have the same content anyway.
mv vault/temp/tmpXYZ.dat vault/$hash
fi
Greetings, Torsten
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.