datamarket 0.9.23__py3-none-any.whl → 0.9.24__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of datamarket might be problematic. Click here for more details.

@@ -6,11 +6,12 @@ from collections.abc import MutableMapping
6
6
  from typing import Any, Iterator, List, Optional, Type, TypeVar
7
7
  from urllib.parse import quote_plus
8
8
 
9
- from sqlalchemy import DDL, FrozenResult, Result, Select, SQLColumnExpression, create_engine, func, select, text
9
+ from sqlalchemy import DDL, FrozenResult, Result, Select, SQLColumnExpression, create_engine, text
10
10
  from sqlalchemy.dialects.postgresql import insert
11
11
  from sqlalchemy.exc import IntegrityError
12
12
  from sqlalchemy.ext.declarative import DeclarativeMeta
13
13
  from sqlalchemy.orm import Session, sessionmaker
14
+ from enum import Enum
14
15
 
15
16
  ########################################################################################################################
16
17
  # CLASSES
@@ -20,6 +21,11 @@ logger = logging.getLogger(__name__)
20
21
  ModelType = TypeVar("ModelType", bound=DeclarativeMeta)
21
22
 
22
23
 
24
+ class CommitStrategy(Enum):
25
+ COMMIT_ON_SUCCESS = "commit_on_success"
26
+ FORCE_COMMIT = "force_commit"
27
+
28
+
23
29
  class MockContext:
24
30
  def __init__(self, column: SQLColumnExpression) -> None:
25
31
  self.current_parameters = {}
@@ -245,6 +251,7 @@ class AlchemyInterface:
245
251
  stmt: Select[Any],
246
252
  order_by: List[SQLColumnExpression[Any]],
247
253
  windowsize: int,
254
+ commit_strategy: CommitStrategy = CommitStrategy.COMMIT_ON_SUCCESS,
248
255
  ) -> Iterator[Result[Any]]:
249
256
  """
250
257
  Executes a windowed query, fetching each window in a separate, short-lived session.
@@ -253,6 +260,8 @@ class AlchemyInterface:
253
260
  stmt: The SQL select statement to execute.
254
261
  order_by: The columns to use for ordering.
255
262
  windowsize: The number of rows to fetch in each window.
263
+ commit_strategy: The strategy to use for committing the session after each window.
264
+ Defaults to CommitStrategy.COMMIT_ON_SUCCESS.
256
265
 
257
266
  Returns:
258
267
  An iterator of Result objects, each containing a window of data.
@@ -296,4 +305,15 @@ class AlchemyInterface:
296
305
 
297
306
  finally:
298
307
  if session_active and self.session:
299
- self.stop(commit=commit_needed)
308
+ if commit_strategy == CommitStrategy.FORCE_COMMIT:
309
+ # For forced commit, always attempt to commit.
310
+ # The self.stop() method already handles potential exceptions during commit/rollback.
311
+ self.stop(commit=True)
312
+ elif commit_strategy == CommitStrategy.COMMIT_ON_SUCCESS:
313
+ # Commit only if no exception occurred before yielding the result.
314
+ self.stop(commit=commit_needed)
315
+ else:
316
+ # Fallback or error for unknown strategy, though type hinting should prevent this.
317
+ # For safety, default to rollback.
318
+ logger.warning(f"Unknown commit strategy: {commit_strategy}. Defaulting to rollback.")
319
+ self.stop(commit=False)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: datamarket
3
- Version: 0.9.23
3
+ Version: 0.9.24
4
4
  Summary: Utilities that integrate advanced scraping knowledge into just one library.
5
5
  License: GPL-3.0-or-later
6
6
  Author: DataMarket
@@ -1,6 +1,6 @@
1
1
  datamarket/__init__.py,sha256=FHS77P9qNewKMoN-p0FLEUEC60oWIYup1QkbJZP4ays,12
2
2
  datamarket/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- datamarket/interfaces/alchemy.py,sha256=-oO-ZBQcv6ixn-N4rEbJcfRjT_54YkMr37hRqc8QKfA,11993
3
+ datamarket/interfaces/alchemy.py,sha256=pL71oG0ld2gx6uGSdgBzSv6RnQPJ3Ps2yTVPCCTXGLU,13178
4
4
  datamarket/interfaces/aws.py,sha256=7KLUeBxmPN7avEMPsu5HC_KHB1N7W6Anp2X8fo43mlw,2383
5
5
  datamarket/interfaces/drive.py,sha256=shbV5jpQVe_KPE-8Idx6Z9te5Zu1SmVfrvSAyd9ZIgE,2915
6
6
  datamarket/interfaces/ftp.py,sha256=o0KlJxtksbop9OjCiQRzyAa2IeG_ExVXagS6apwrAQo,1881
@@ -18,7 +18,7 @@ datamarket/utils/selenium.py,sha256=IMKlbLzXABFhACnWzhHmB0l2hhVzNwHGZwbo14nEewQ,
18
18
  datamarket/utils/soda.py,sha256=eZTXFbI1P3WoMd1MM-YjoVTpdjTcDSWuvBb7ViBMhSQ,941
19
19
  datamarket/utils/typer.py,sha256=FDF3l6gh3UlAFPsHCtesnekvct2rKz0oFn3uKARBQvE,814
20
20
  datamarket/utils/types.py,sha256=vxdQZdwdXrfPR4Es52gBgol-tMRIOD6oK9cBo3rB0JQ,74
21
- datamarket-0.9.23.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
- datamarket-0.9.23.dist-info/METADATA,sha256=iHO101fsdYc5iuQJbhEeVe8x6LBIl_mkofNpRP4Vjew,6459
23
- datamarket-0.9.23.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
24
- datamarket-0.9.23.dist-info/RECORD,,
21
+ datamarket-0.9.24.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
+ datamarket-0.9.24.dist-info/METADATA,sha256=18l6aTHI7ejx_26UJ6QtDhPdMbIGMtiToq-qFrx2EVw,6459
23
+ datamarket-0.9.24.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
24
+ datamarket-0.9.24.dist-info/RECORD,,