aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/db')
-rw-r--r--mediagoblin/db/mongo/util.py11
-rw-r--r--mediagoblin/db/sql/util.py15
-rw-r--r--mediagoblin/db/util.py4
3 files changed, 28 insertions, 2 deletions
diff --git a/mediagoblin/db/mongo/util.py b/mediagoblin/db/mongo/util.py
index 4daf616a..89348d98 100644
--- a/mediagoblin/db/mongo/util.py
+++ b/mediagoblin/db/mongo/util.py
@@ -290,3 +290,14 @@ class MigrationManager(object):
self.set_current_migration(migration_number)
if post_callback:
post_callback(migration_number, migration_func)
+
+
+##########################
+# Random utility functions
+##########################
+
+
+def atomic_update(table, query_dict, update_values):
+ table.collection.update(
+ query_dict,
+ {"$set": update_values})
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()
diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py
index 1fc949a6..73aee238 100644
--- a/mediagoblin/db/util.py
+++ b/mediagoblin/db/util.py
@@ -21,5 +21,7 @@ except ImportError:
if use_sql:
from mediagoblin.db.sql.fake import ObjectId, InvalidId, DESCENDING
+ from mediagoblin.db.sql.util import atomic_update
else:
- from mediagoblin.db.mongo.util import ObjectId, InvalidId, DESCENDING
+ from mediagoblin.db.mongo.util import \
+ ObjectId, InvalidId, DESCENDING, atomic_update