Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlouielu/be8573026faac2d3bab71707eb574c36 to your computer and use it in GitHub Desktop.
Save mlouielu/be8573026faac2d3bab71707eb574c36 to your computer and use it in GitHub Desktop.
Restore Darktable Image Ratings from Snapshot Database
import sqlite3
def get_column(source_db_path, table_name, column_name):
sc = sqlite3.connect(source_db_path)
cursor = sc.cursor()
cursor.execute(f"SELECT id, filename, {column_name} FROM {table_name}")
rows = cursor.fetchall()
cursor.close()
return rows
def update_rating(cursor, table_name, column_name, row_id, rating):
cursor.execute(
f"""
UPDATE {table_name}
SET {column_name} = ?
WHERE id = ?
""",
(rating, row_id),
)
def main():
# Example usage
source_db = "library.db.from" # Path to source database file
target_db = "library.db.target" # Path to target database file
table = "images" # Table name
column = "flags" # Column name to be copied
a = get_column(source_db, table, column)
b = get_column(target_db, table, column)
tc = sqlite3.connect(target_db)
cursor = tc.cursor()
for pk, filename, flags in a:
rating = flags & 0b1111
update_rating(cursor, table, column, pk, rating)
tc.commit()
tc.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment