mtsql 1.12.29__py3-none-any.whl → 1.12.31__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.
mt/sql/base.py CHANGED
@@ -30,6 +30,7 @@ __all__ = [
30
30
  "temp_table_drop",
31
31
  "to_temp_table",
32
32
  "find_common_ids",
33
+ "remove_records_by_id",
33
34
  ]
34
35
 
35
36
 
@@ -376,7 +377,7 @@ def table_exists(
376
377
  def create_temp_id_table(
377
378
  l_ids: list,
378
379
  conn: sa.engine.Connection,
379
- int_type="int",
380
+ int_type: str = "int",
380
381
  chunksize: int = 1000000,
381
382
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
382
383
  ) -> str:
@@ -503,6 +504,7 @@ def find_common_ids(
503
504
  engine: sa.engine.Engine,
504
505
  schema: tp.Optional[str] = None,
505
506
  id_col: str = "id",
507
+ int_type: str = "int",
506
508
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
507
509
  ) -> tp.List[int]:
508
510
  """Finds common ids between a list of ids and the ids in a given frame.
@@ -519,6 +521,8 @@ def find_common_ids(
519
521
  schema of the frame. If None, the default schema is used.
520
522
  id_col : str
521
523
  name of the id column in the frame
524
+ int_type : str
525
+ an SQL string representing the int type of the id column
522
526
  logger : mt.logg.IndentedLoggerAdapter, optional
523
527
  logger for debugging
524
528
 
@@ -529,7 +533,7 @@ def find_common_ids(
529
533
  """
530
534
 
531
535
  with conn_ctx(engine) as conn:
532
- temp_table = create_temp_id_table(l_ids, conn, logger=logger)
536
+ temp_table = create_temp_id_table(l_ids, conn, int_type=int_type, logger=logger)
533
537
 
534
538
  full_frame_name = frame_sql(frame_name, schema=schema)
535
539
 
@@ -544,3 +548,46 @@ def find_common_ids(
544
548
  l_commonIds = df_common["id"].tolist()
545
549
 
546
550
  return l_commonIds
551
+
552
+
553
+ def remove_records_by_id(
554
+ l_ids: tp.List[int],
555
+ frame_name: str,
556
+ engine: sa.engine.Engine,
557
+ schema: tp.Optional[str] = None,
558
+ id_col: str = "id",
559
+ int_type: str = "int",
560
+ logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
561
+ ):
562
+ """Removes records from a frame by a list of ids.
563
+
564
+ Parameters
565
+ ----------
566
+ l_ids : list of int
567
+ list of ids to be removed
568
+ frame_name : str
569
+ name of the frame to be modified
570
+ engine : sqlalchemy.engine.Engine
571
+ connection engine to the server
572
+ schema : str, optional
573
+ schema of the frame. If None, the default schema is used.
574
+ id_col : str
575
+ name of the id column in the frame
576
+ int_type : str
577
+ an SQL string representing the int type of the id column
578
+ logger : mt.logg.IndentedLoggerAdapter, optional
579
+ logger for debugging
580
+ """
581
+
582
+ with conn_ctx(engine) as conn:
583
+ temp_table = create_temp_id_table(l_ids, conn, int_type=int_type, logger=logger)
584
+
585
+ full_frame_name = frame_sql(frame_name, schema=schema)
586
+
587
+ sql = f"""
588
+ DELETE FROM {full_frame_name}
589
+ USING {temp_table} AS t
590
+ WHERE {full_frame_name}.{id_col} = t.id;
591
+ """
592
+
593
+ exec_sql(sql, conn, logger=logger)
mt/sql/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 1
2
2
  MINOR_VERSION = 12
3
- PATCH_VERSION = 29
3
+ PATCH_VERSION = 31
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtsql
3
- Version: 1.12.29
3
+ Version: 1.12.31
4
4
  Summary: Extra Python modules to deal with the interaction between pandas dataframes and remote SQL servers, for Minh-Tri Pham
5
5
  Home-page: https://github.com/inteplus/mtsql
6
- Author: ['Minh-Tri Pham']
6
+ Author: Minh-Tri Pham
7
7
  Project-URL: Documentation, https://mtdoc.readthedocs.io/en/latest/mt.sql/mt.sql.html
8
8
  Project-URL: Source Code, https://github.com/inteplus/mtsql
9
9
  License-File: LICENSE
@@ -12,7 +12,7 @@ Requires-Dist: tzlocal
12
12
  Requires-Dist: tqdm
13
13
  Requires-Dist: psycopg[binary]
14
14
  Requires-Dist: redshift_connector>=2.1.5
15
- Requires-Dist: mtbase>=4.32.34
15
+ Requires-Dist: mtbase>=4.3.2
16
16
  Requires-Dist: mtpandas>=1.17.16
17
17
  Dynamic: author
18
18
  Dynamic: home-page
@@ -1,17 +1,17 @@
1
1
  mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
2
- mt/sql/base.py,sha256=YM7BnNf1e3WizzH5Amg5xK-L5s0w9Cnl9-90htUqJlg,15096
2
+ mt/sql/base.py,sha256=CLFKd-rJtIUGLm37WtxeFLzhX48LgGpEoz6noR4qfXo,16510
3
3
  mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
4
4
  mt/sql/psql.py,sha256=U8XEyg4rQYr5gm8KohRWrpCNJKl5WC1yxJMBkkm1k_A,68125
5
5
  mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
6
- mt/sql/version.py,sha256=I7DJlgmw1b2vkxA_AWJYjd0FWS4W3BxvUIL3cHr587E,208
6
+ mt/sql/version.py,sha256=e7OodvUPDd0qLszM8zWrGxkmyhHFVodAR8B3CnSzs7g,208
7
7
  mt/sql/redshift/__init__.py,sha256=S-eRxJWcrvncF7LZXuulCdPV-UERu9eiw6uyDb5aGsM,443
8
8
  mt/sql/redshift/commands.py,sha256=xhGUBf3bL66EYdZI5HCUtOx-XqPCnXT_P-LnhPgtzrY,40193
9
9
  mt/sql/redshift/ddl.py,sha256=eUcZj9oIajiE1wKKBAP-V64gYJ7cVnSAt8dLFfluOJA,9777
10
10
  mt/sql/redshift/dialect.py,sha256=-0JjJubZZHRw0abhl6H6rKWaUE9pKtGwAuX-62T0e_c,53399
11
11
  mt/sql/redshift/main.py,sha256=H8_5sjtJ7dzWoCMXzPNjYhrMQ18eLUQ9xg-aYl5QeTc,17104
12
12
  mt/sql/redshift/redshift-ca-bundle.crt,sha256=532qYkOpQOstFE0mdXE1GVtL3v00XDKgZNTr6gK5-KE,8621
13
- mtsql-1.12.29.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
- mtsql-1.12.29.dist-info/METADATA,sha256=dsOJv6kpa6gxLeky_Hsw939aE8bK3F8EMel1g4S1Xyo,740
15
- mtsql-1.12.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- mtsql-1.12.29.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
- mtsql-1.12.29.dist-info/RECORD,,
13
+ mtsql-1.12.31.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
+ mtsql-1.12.31.dist-info/METADATA,sha256=bJET1fnqtrkAZ1Qz8UzM7c2E0PL1X65I5AN1h6wlY1Q,734
15
+ mtsql-1.12.31.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ mtsql-1.12.31.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
+ mtsql-1.12.31.dist-info/RECORD,,