Skip to content

Commit e88d36c

Browse files
committed
add database.get_version()
1 parent 4cb66f2 commit e88d36c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tests/test_things.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ def test_areas(self):
9898
test_areas = things.areas(**FILEPATH)
9999
self.assertEqual(1, len(test_areas))
100100

101+
def test_database_version(self):
102+
"""Test database version."""
103+
version = things.Database(**FILEPATH).get_version()
104+
self.assertEqual(18, version)
105+
101106

102107
if __name__ == "__main__":
103108
unittest.main()

things/database.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Database:
6464
TABLE_TASKTAG = "TMTaskTag"
6565
TABLE_AREATAG = "TMAreaTag"
6666
TABLE_CHECKLIST_ITEM = "TMChecklistItem"
67+
TABLE_META = "Meta"
6768
DATE_CREATE = "creationDate"
6869
DATE_MOD = "userModificationDate"
6970
DATE_DUE = "dueDate"
@@ -378,10 +379,20 @@ def get_tags_of_area(self, area_uuid):
378379
AREA_TAG.areas = ?
379380
ORDER BY AREA."index"
380381
"""
382+
381383
return self.execute_query(
382384
query, parameters=(area_uuid,), row_factory=list_factory
383385
)
384386

387+
def get_version(self):
388+
"""Get Things Database version."""
389+
import plistlib
390+
391+
query = f"SELECT value FROM {self.TABLE_META} WHERE key = 'databaseVersion'"
392+
result = self.execute_query(query, row_factory=list_factory)
393+
plist_bytes = result[0].encode()
394+
return plistlib.loads(plist_bytes)
395+
385396
def get_count(self, sql):
386397
sql = f"""SELECT COUNT(uuid) FROM ({sql})"""
387398
return self.execute_query(sql, row_factory=list_factory)[0]

0 commit comments

Comments
 (0)