diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-02-12 22:58:08 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-03-04 21:05:06 +0100 |
commit | 325ca444d1c75aa353b5855423aa35ee75ed9f19 (patch) | |
tree | f9b57450ae3f7d1a1e7d97cabf1708022217b04d /mediagoblin/db/sql/util.py | |
parent | 82cd968347988f61ac52c2100d1dc47750decead (diff) | |
download | mediagoblin-325ca444d1c75aa353b5855423aa35ee75ed9f19.tar.lz mediagoblin-325ca444d1c75aa353b5855423aa35ee75ed9f19.tar.xz mediagoblin-325ca444d1c75aa353b5855423aa35ee75ed9f19.zip |
Implement atomic_update for SQL.
On sqlalchemy most updates are atomic enough for most use
cases. Anyway, here is an atomic_update that is compatible
to the mongo version.
Diffstat (limited to 'mediagoblin/db/sql/util.py')
-rw-r--r-- | mediagoblin/db/sql/util.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mediagoblin/db/sql/util.py b/mediagoblin/db/sql/util.py index 08602414..13bc97e1 100644 --- a/mediagoblin/db/sql/util.py +++ b/mediagoblin/db/sql/util.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -16,6 +16,8 @@ import sys +from mediagoblin.db.sql.base import Session + def _simple_printer(string): """ @@ -269,3 +271,14 @@ def assure_migrations_table_setup(db): if not MigrationData.__table__.exists(db.bind): MigrationData.metadata.create_all( db.bind, tables=[MigrationData.__table__]) + + +########################## +# Random utility functions +########################## + + +def atomic_update(table, query_dict, update_values): + table.find(query_dict).update(update_values, + synchronize_session=False) + Session.commit() |