From 70c5d3013bcec17e9c76107a025c7aca5f05388e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 17:10:08 +0100 Subject: [PATCH 1/9] fix type annotation --- reladiff/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index 7028133..1336f24 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -1,4 +1,4 @@ -from typing import Sequence, Tuple, Iterable, Optional, Union +from typing import Sequence, Tuple, Optional, Union from sqeleton.abcs import DbTime, DbPath @@ -46,7 +46,7 @@ def diff_tables( table2: TableSegment, *, # Name of the key column, which uniquely identifies each row (usually id) - key_columns: Sequence[str] = None, + key_columns: Tuple[str, ...] = None, # Name of updated column, which signals that rows changed (usually updated_at or last_update) update_column: str = None, # Extra columns to compare From 1f26a072aaece9c6ac9b1ac002d5f29307922273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 17:35:18 +0100 Subject: [PATCH 2/9] allow string as well --- reladiff/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index 1336f24..89928ca 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -46,7 +46,7 @@ def diff_tables( table2: TableSegment, *, # Name of the key column, which uniquely identifies each row (usually id) - key_columns: Tuple[str, ...] = None, + key_columns: Union[Tuple[str, ...], str] = None, # Name of updated column, which signals that rows changed (usually updated_at or last_update) update_column: str = None, # Extra columns to compare @@ -89,7 +89,7 @@ def diff_tables( """Finds the diff between table1 and table2. Parameters: - key_columns (Tuple[str, ...]): Name of the key column, which uniquely identifies each row (usually id) + key_columns (Union[Tuple[str, ...], str]): Name of the key column, which uniquely identifies each row (usually id) update_column (str, optional): Name of updated column, which signals that rows changed. Usually updated_at or last_update. Used by `min_update` and `max_update`. extra_columns (Tuple[str, ...], optional): Extra columns to compare From 49b0e6855d47a1f83699e72e760239c36bb2ee12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 17:43:33 +0100 Subject: [PATCH 3/9] allow any iterable of strings or string --- reladiff/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index 89928ca..d997773 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -1,4 +1,4 @@ -from typing import Sequence, Tuple, Optional, Union +from typing import Sequence, Tuple, Optional, Union, Iterable from sqeleton.abcs import DbTime, DbPath @@ -46,7 +46,7 @@ def diff_tables( table2: TableSegment, *, # Name of the key column, which uniquely identifies each row (usually id) - key_columns: Union[Tuple[str, ...], str] = None, + key_columns: Union[Iterable[str], str] = None, # Name of updated column, which signals that rows changed (usually updated_at or last_update) update_column: str = None, # Extra columns to compare @@ -89,7 +89,7 @@ def diff_tables( """Finds the diff between table1 and table2. Parameters: - key_columns (Union[Tuple[str, ...], str]): Name of the key column, which uniquely identifies each row (usually id) + key_columns (Union[Iterable[str], str]): Name of the key column, which uniquely identifies each row (usually id) update_column (str, optional): Name of updated column, which signals that rows changed. Usually updated_at or last_update. Used by `min_update` and `max_update`. extra_columns (Tuple[str, ...], optional): Extra columns to compare @@ -145,6 +145,8 @@ def diff_tables( """ if isinstance(key_columns, str): key_columns = (key_columns,) + else: + key_columns = tuple(key_columns) tables = [table1, table2] override_attrs = { From 7453d64512d98efcb6cc763d46cd68bf4d4b168b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 17:48:59 +0100 Subject: [PATCH 4/9] allow any iterable of strings or string --- reladiff/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index d997773..540ea12 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -46,7 +46,7 @@ def diff_tables( table2: TableSegment, *, # Name of the key column, which uniquely identifies each row (usually id) - key_columns: Union[Iterable[str], str] = None, + key_columns: Union[Iterable[str], str] = None, # Name of updated column, which signals that rows changed (usually updated_at or last_update) update_column: str = None, # Extra columns to compare From 55b06351398f88aa2f0c1c385fa01923647581c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 17:50:00 +0100 Subject: [PATCH 5/9] make connect_to_table work the same way --- reladiff/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index 540ea12..e7d02ec 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -15,7 +15,7 @@ def connect_to_table( db_info: Union[str, dict], table_name: Union[DbPath, str], - key_columns: Union[str, Sequence[str]] = ("id",), + key_columns: Union[Iterable[str], str] = ("id",), thread_count: Optional[int] = 1, **kwargs, ) -> TableSegment: From a224f3c3c1da732eba1ea13acffdadd9a8289f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 17:53:11 +0100 Subject: [PATCH 6/9] optimize imports --- reladiff/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index e7d02ec..a61907f 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -1,4 +1,4 @@ -from typing import Sequence, Tuple, Optional, Union, Iterable +from typing import Tuple, Optional, Union, Iterable from sqeleton.abcs import DbTime, DbPath From ea23da566c311dd4a9f8d04271551426b23ce172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 17:54:26 +0100 Subject: [PATCH 7/9] restore import order --- reladiff/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index a61907f..4c1bbb5 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -1,4 +1,4 @@ -from typing import Tuple, Optional, Union, Iterable +from typing import Tuple, Iterable, Optional, Union from sqeleton.abcs import DbTime, DbPath From 1ae093cb7c0e6bc4938323a83927b2ceace6e492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 19:29:49 +0100 Subject: [PATCH 8/9] allow None --- reladiff/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index 4c1bbb5..9084d0d 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -146,7 +146,7 @@ def diff_tables( if isinstance(key_columns, str): key_columns = (key_columns,) else: - key_columns = tuple(key_columns) + key_columns = tuple(key_columns or ()) tables = [table1, table2] override_attrs = { From be2cd1b05feb0d873b9d1267bbae2b83946bd458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20Kov=C3=A1cs?= Date: Fri, 10 Jan 2025 19:31:51 +0100 Subject: [PATCH 9/9] improve type hint --- reladiff/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reladiff/__init__.py b/reladiff/__init__.py index 9084d0d..f5106b9 100644 --- a/reladiff/__init__.py +++ b/reladiff/__init__.py @@ -46,7 +46,7 @@ def diff_tables( table2: TableSegment, *, # Name of the key column, which uniquely identifies each row (usually id) - key_columns: Union[Iterable[str], str] = None, + key_columns: Optional[Union[Iterable[str], str]] = None, # Name of updated column, which signals that rows changed (usually updated_at or last_update) update_column: str = None, # Extra columns to compare @@ -89,7 +89,7 @@ def diff_tables( """Finds the diff between table1 and table2. Parameters: - key_columns (Union[Iterable[str], str]): Name of the key column, which uniquely identifies each row (usually id) + key_columns (Union[Iterable[str], str], optional): Name of the key column, which uniquely identifies each row (usually id) update_column (str, optional): Name of updated column, which signals that rows changed. Usually updated_at or last_update. Used by `min_update` and `max_update`. extra_columns (Tuple[str, ...], optional): Extra columns to compare