mtsql 1.12.22__py3-none-any.whl → 1.12.25__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/psql.py CHANGED
@@ -636,24 +636,27 @@ def rename_table(
636
636
  new_table_name,
637
637
  engine,
638
638
  schema: tp.Optional[str] = None,
639
+ foreign: bool = False,
639
640
  nb_trials: int = 3,
640
641
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
641
642
  ):
642
- """Renames a table of a schema.
643
+ """Renames a (foreign) table of a schema.
643
644
 
644
645
  Parameters
645
646
  ----------
646
- old_table_name: str
647
+ old_table_name : str
647
648
  old table name
648
- new_table_name: str
649
+ new_table_name : str
649
650
  new table name
650
- engine: sqlalchemy.engine.Engine
651
+ engine : sqlalchemy.engine.Engine
651
652
  an sqlalchemy connection engine created by function `create_engine()`
652
- schema: str or None
653
+ schema : str or None
653
654
  a valid schema name returned from `list_schemas()`
654
- nb_trials: int
655
+ foreign : bool
656
+ whether the table to rename is a foreign table
657
+ nb_trials : int
655
658
  number of query trials
656
- logger: mt.logg.IndentedLoggerAdapter, optional
659
+ logger : mt.logg.IndentedLoggerAdapter, optional
657
660
  logger for debugging
658
661
 
659
662
  Returns
@@ -661,8 +664,12 @@ def rename_table(
661
664
  whatever exec_sql() returns
662
665
  """
663
666
  frame_sql_str = frame_sql(old_table_name, schema=schema)
667
+ if foreign:
668
+ query_str = f'ALTER FOREIGN TABLE {frame_sql_str} RENAME TO "{new_table_name}";'
669
+ else:
670
+ query_str = f'ALTER TABLE {frame_sql_str} RENAME TO "{new_table_name}";'
664
671
  return exec_sql(
665
- 'ALTER TABLE {} RENAME TO "{}";'.format(frame_sql_str, new_table_name),
672
+ query_str,
666
673
  engine,
667
674
  nb_trials=nb_trials,
668
675
  logger=logger,
@@ -710,21 +717,24 @@ def drop_table(
710
717
  table_name,
711
718
  engine,
712
719
  schema: tp.Optional[str] = None,
713
- restrict=True,
720
+ foreign: bool = False,
721
+ restrict: bool = True,
714
722
  nb_trials: int = 3,
715
723
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
716
724
  ):
717
- """Drops a table if it exists, with restrict or cascade options.
725
+ """Drops a (foreign) table if it exists, with restrict or cascade options.
718
726
 
719
727
  Parameters
720
728
  ----------
721
729
  table_name : str
722
730
  table name
723
- engine: sqlalchemy.engine.Engine
731
+ engine : sqlalchemy.engine.Engine
724
732
  an sqlalchemy connection engine created by function `create_engine()`
725
- schema: str or None
733
+ schema : str or None
726
734
  a valid schema name returned from `list_schemas()`
727
- restrict: bool
735
+ foreign : bool
736
+ whether the table to drop is a foreign table
737
+ restrict : bool
728
738
  If True, refuses to drop table if there is any object depending on it. Otherwise it is the
729
739
  'cascade' option which allows you to remove those dependent objects together with the table
730
740
  automatically.
@@ -738,9 +748,11 @@ def drop_table(
738
748
  whatever exec_sql() returns
739
749
  """
740
750
  frame_sql_str = frame_sql(table_name, schema=schema)
741
- query_str = "DROP TABLE IF EXISTS {} {};".format(
742
- frame_sql_str, "RESTRICT" if restrict else "CASCADE"
743
- )
751
+ if foreign:
752
+ query_str = "DROP FOREIGN TABLE "
753
+ else:
754
+ query_str = "DROP TABLE "
755
+ query_str += f'IF EXISTS {frame_sql_str} {"RESTRICT" if restrict else "CASCADE"};'
744
756
  return exec_sql(query_str, engine, nb_trials=nb_trials, logger=logger)
745
757
 
746
758
 
mt/sql/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 1
2
2
  MINOR_VERSION = 12
3
- PATCH_VERSION = 22
3
+ PATCH_VERSION = 25
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtsql
3
- Version: 1.12.22
3
+ Version: 1.12.25
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
6
  Author: ['Minh-Tri Pham']
@@ -12,8 +12,8 @@ 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.27
16
- Requires-Dist: mtpandas>=1.17.13
15
+ Requires-Dist: mtbase>=4.32.34
16
+ Requires-Dist: mtpandas>=1.17.16
17
17
  Dynamic: author
18
18
  Dynamic: home-page
19
19
  Dynamic: license-file
@@ -1,17 +1,17 @@
1
1
  mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
2
2
  mt/sql/base.py,sha256=j2fzeGUdh-TnvgotuWOmTM-A0pqBg31z2c19bH5E_xk,13504
3
3
  mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
4
- mt/sql/psql.py,sha256=w5klr_2lUZnAFee-Fzbn3G8jdYcf_iX4N_GfAGIdsMI,66670
4
+ mt/sql/psql.py,sha256=8gWsF6ZobwkAxHsfecF95Em_cAlMitHHdQzinZLCi6s,67110
5
5
  mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
6
- mt/sql/version.py,sha256=TMep9gRjrVIi_raEj5ssyAJSqu8WjBqWN-k1B6KZSgg,208
6
+ mt/sql/version.py,sha256=fESKN3a-51Gk518u42eRfS6jc2qynXacnonQdAruWec,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.22.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
- mtsql-1.12.22.dist-info/METADATA,sha256=3zityjnam0Lf_ihhR1UDvNhJJ6bxqOlM8QPA0flFU78,740
15
- mtsql-1.12.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- mtsql-1.12.22.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
- mtsql-1.12.22.dist-info/RECORD,,
13
+ mtsql-1.12.25.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
+ mtsql-1.12.25.dist-info/METADATA,sha256=nMGzCZOmjrDiBh9wWHes41XqZ2Q9nvDcsdzNI1ln8tk,740
15
+ mtsql-1.12.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ mtsql-1.12.25.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
+ mtsql-1.12.25.dist-info/RECORD,,