Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9348401
D1033.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D1033.diff
View Options
diff --git a/swh/core/db/__init__.py b/swh/core/db/__init__.py
--- a/swh/core/db/__init__.py
+++ b/swh/core/db/__init__.py
@@ -122,16 +122,19 @@
self.conn.rollback()
raise
- def copy_to(self, items, tblname, columns, cur=None, item_cb=None):
+ def copy_to(self, items, tblname, columns, default_values={},
+ cur=None, item_cb=None):
"""Copy items' entries to table tblname with columns information.
Args:
- items (dict): dictionary of data to copy over tblname
- tblname (str): Destination table's name
+ items (dict): dictionary of data to copy over tblname.
+ tblname (str): destination table's name.
columns ([str]): keys to access data in items and also the
column names in the destination table.
- item_cb (fn): optional function to apply to items's entry
-
+ default_values (dict): dictionnary of default values to use when
+ inserting entried int the tblname table.
+ cur: a db cursor; if not given, a new cursor will be created.
+ item_cb (fn): optional function to apply to items's entry.
"""
read_file, write_file = os.pipe()
@@ -150,7 +153,8 @@
for d in items:
if item_cb is not None:
item_cb(d)
- line = [escape(d.get(k)) for k in columns]
+ line = [escape(d.get(k) or default_values.get(k))
+ for k in columns]
f.write(','.join(line))
f.write('\n')
finally:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Jul 3 2025, 6:28 PM (5 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223393
Attached To
D1033: Add a 'default_columns' argument to the BaseDb.copy_to() method
Event Timeline
Log In to Comment