tracktolib 0.60.0__py3-none-any.whl → 0.61.1__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.
tracktolib/pg/query.py CHANGED
@@ -270,7 +270,7 @@ class PGUpdateQuery(PGQuery):
270
270
  if self.where:
271
271
  return self.where
272
272
  elif self.where_keys is not None:
273
- start_from = self.start_from if self.start_from is not None else len(self.values) - len(self.where_keys)
273
+ start_from = self.start_from if self.start_from is not None else len(self.keys) - len(self.where_keys)
274
274
 
275
275
  return "WHERE " + " AND ".join(f"{k} = ${i + start_from + 1}" for i, k in enumerate(self.where_keys))
276
276
  return ""
@@ -310,6 +310,10 @@ def insert_pg(
310
310
  )
311
311
 
312
312
 
313
+ Q = TypeVar("Q", bound=PGInsertQuery | PGUpdateQuery)
314
+ QueryCallback = Callable[[Q], None]
315
+
316
+
313
317
  async def insert_one(
314
318
  conn: _Connection,
315
319
  table: str,
@@ -318,8 +322,11 @@ async def insert_one(
318
322
  on_conflict: OnConflict | None = None,
319
323
  fill: bool = False,
320
324
  quote_columns: bool = False,
325
+ query_callback: QueryCallback[PGInsertQuery] | None = None,
321
326
  ):
322
327
  query = insert_pg(table=table, items=[item], on_conflict=on_conflict, fill=fill, quote_columns=quote_columns)
328
+ if query_callback is not None:
329
+ query_callback(query)
323
330
  await query.run(conn)
324
331
 
325
332
 
@@ -331,14 +338,23 @@ async def insert_many(
331
338
  on_conflict: OnConflict | None = None,
332
339
  fill: bool = False,
333
340
  quote_columns: bool = False,
341
+ query_callback: QueryCallback[PGInsertQuery] | None = None,
334
342
  ):
335
343
  query = insert_pg(table=table, items=items, on_conflict=on_conflict, fill=fill, quote_columns=quote_columns)
344
+ if query_callback is not None:
345
+ query_callback(query)
336
346
  await query.run(conn)
337
347
 
338
348
 
339
349
  @overload
340
350
  async def insert_returning(
341
- conn: _Connection, table: str, item: dict, returning: str, on_conflict: OnConflict | None = None, fill: bool = False
351
+ conn: _Connection,
352
+ table: str,
353
+ item: dict,
354
+ returning: str,
355
+ on_conflict: OnConflict | None = None,
356
+ fill: bool = False,
357
+ query_callback: QueryCallback[PGInsertQuery] | None = None,
342
358
  ) -> Any | None: ...
343
359
 
344
360
 
@@ -350,6 +366,7 @@ async def insert_returning(
350
366
  returning: list[str],
351
367
  on_conflict: OnConflict | None = None,
352
368
  fill: bool = False,
369
+ query_callback: QueryCallback[PGInsertQuery] | None = None,
353
370
  ) -> asyncpg.Record | None: ...
354
371
 
355
372
 
@@ -360,9 +377,12 @@ async def insert_returning(
360
377
  returning: list[str] | str,
361
378
  on_conflict: OnConflict | None = None,
362
379
  fill: bool = False,
380
+ query_callback: QueryCallback[PGInsertQuery] | None = None,
363
381
  ) -> asyncpg.Record | Any | None:
364
382
  returning_values = [returning] if isinstance(returning, str) else returning
365
383
  query = insert_pg(table=table, items=[item], on_conflict=on_conflict, fill=fill, returning=returning_values)
384
+ if query_callback is not None:
385
+ query_callback(query)
366
386
  fn = conn.fetchval if len(returning_values) == 1 and returning != "*" else conn.fetchrow
367
387
 
368
388
  return await fn(query.query, *query.values)
@@ -389,10 +409,13 @@ async def update_one(
389
409
  start_from: int | None = None,
390
410
  where: str | None = None,
391
411
  merge_keys: list[str] | None = None,
412
+ query_callback: QueryCallback[PGUpdateQuery] | None = None,
392
413
  ):
393
414
  query = PGUpdateQuery(
394
415
  table=table, items=[item], start_from=start_from, where_keys=keys, where=where, merge_keys=merge_keys
395
416
  )
417
+ if query_callback is not None:
418
+ query_callback(query)
396
419
  await conn.execute(query.query, *args, *query.values)
397
420
 
398
421
 
@@ -408,6 +431,7 @@ async def update_returning(
408
431
  keys: list[str] | None = None,
409
432
  start_from: int | None = None,
410
433
  merge_keys: list[str] | None = None,
434
+ query_callback: QueryCallback[PGUpdateQuery] | None = None,
411
435
  ) -> Any | None: ...
412
436
 
413
437
 
@@ -423,6 +447,7 @@ async def update_returning(
423
447
  keys: list[str] | None = None,
424
448
  start_from: int | None = None,
425
449
  merge_keys: list[str] | None = None,
450
+ query_callback: QueryCallback[PGUpdateQuery] | None = None,
426
451
  ) -> asyncpg.Record | None: ...
427
452
 
428
453
 
@@ -438,6 +463,7 @@ async def update_returning(
438
463
  keys: list[str] | None = None,
439
464
  start_from: int | None = None,
440
465
  merge_keys: list[str] | None = None,
466
+ query_callback: QueryCallback[PGUpdateQuery] | None = None,
441
467
  ) -> asyncpg.Record | None: ...
442
468
 
443
469
 
@@ -452,6 +478,7 @@ async def update_returning(
452
478
  keys: list[str] | None = None,
453
479
  start_from: int | None = None,
454
480
  merge_keys: list[str] | None = None,
481
+ query_callback: QueryCallback[PGUpdateQuery] | None = None,
455
482
  ) -> Any | asyncpg.Record | None:
456
483
  if returning is not None:
457
484
  returning_values = [returning] if isinstance(returning, str) else returning
@@ -467,6 +494,8 @@ async def update_returning(
467
494
  returning=returning_values,
468
495
  merge_keys=merge_keys,
469
496
  )
497
+ if query_callback is not None:
498
+ query_callback(query)
470
499
  fn = conn.fetchval if len(returning_values or []) == 1 else conn.fetchrow
471
500
  return await fn(query.query, *args, *query.values)
472
501
 
@@ -479,8 +508,11 @@ async def update_many(
479
508
  start_from: int | None = None,
480
509
  where: str | None = None,
481
510
  merge_keys: list[str] | None = None,
511
+ query_callback: QueryCallback[PGUpdateQuery] | None = None,
482
512
  ):
483
513
  query = PGUpdateQuery(
484
514
  table=table, items=items, start_from=start_from, where_keys=keys, where=where, merge_keys=merge_keys
485
515
  )
516
+ if query_callback is not None:
517
+ query_callback(query)
486
518
  await conn.executemany(query.query, query.values)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tracktolib
3
- Version: 0.60.0
3
+ Version: 0.61.1
4
4
  Summary: Utility library for python
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -3,7 +3,7 @@ tracktolib/api.py,sha256=ZLMgjH3Y8r3MpXc8m3IuZbzTj3fgrZKZORtSVgbuP-M,10221
3
3
  tracktolib/http_utils.py,sha256=c10JGmHaBw3VSDMYhz2dvVw2lo4PUAq1xMub74I7xDc,2625
4
4
  tracktolib/logs.py,sha256=xgfRDnviZPr9qinSOgab8neIWPv9Rj2xzDHnIBvWQcU,2201
5
5
  tracktolib/pg/__init__.py,sha256=Ul_hgwvTXZvQBt7sHKi4ZI-0DDpnXmoFtmVkGRy-1J0,366
6
- tracktolib/pg/query.py,sha256=PQ-vMTwsdvGpM82oE6moHVfD6eta61yPgB7IYRU8CVU,14973
6
+ tracktolib/pg/query.py,sha256=Gfrv_XWS3HVjobh4rjNf4o5Pn5-0YP0AZa3vA-4GBsI,16178
7
7
  tracktolib/pg/utils.py,sha256=cL24KEt4SWJQ7LJPzaO3c8Xg0ZLmjhn22DtTWg86nwc,6324
8
8
  tracktolib/pg_sync.py,sha256=MKDaV7dYsRy59Y0EE5RGZL0DlZ-RUdBeaN9eSBwiQJg,6718
9
9
  tracktolib/pg_utils.py,sha256=ArYNdf9qsdYdzGEWmev8tZpyx8_1jaGGdkfYkauM7UM,2582
@@ -12,7 +12,7 @@ tracktolib/s3/minio.py,sha256=wMEjkSes9Fp39fD17IctALpD6zB2xwDRQEmO7Vzan3g,1387
12
12
  tracktolib/s3/s3.py,sha256=0HbSAPoaup5-W4LK54zRCjrQ5mr8OWR-N9WjW99Q4aw,5937
13
13
  tracktolib/tests.py,sha256=gKE--epQjgMZGXc5ydbl4zjOdmwztJS42UMV0p4hXEA,399
14
14
  tracktolib/utils.py,sha256=ysTBF9V35fVXQVBPk0kfE_84SGRxzrayqmg9RbtoJq4,5761
15
- tracktolib-0.60.0.dist-info/METADATA,sha256=1qNZSiff8zDxWsmA-lgHQ45EnBufiABtkMy6EK4KNbM,3777
16
- tracktolib-0.60.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
17
- tracktolib-0.60.0.dist-info/licenses/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
18
- tracktolib-0.60.0.dist-info/RECORD,,
15
+ tracktolib-0.61.1.dist-info/METADATA,sha256=do6v8-tZbQ1nYmofQiycwSbpDWeMw5DQUvwUFZShbj8,3777
16
+ tracktolib-0.61.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
17
+ tracktolib-0.61.1.dist-info/licenses/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
18
+ tracktolib-0.61.1.dist-info/RECORD,,