DE-Lib 0.0.35.4__py3-none-any.whl → 0.0.36.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.
@@ -0,0 +1,90 @@
1
+ from logging import exception
2
+
3
+ import pandas as pd
4
+
5
+ class OracleDDL:
6
+ def __init__(self):
7
+ msg = result = None, None
8
+ try:
9
+ ...
10
+ except Exception as error:
11
+ msg = error
12
+ result = msg
13
+ finally:
14
+ print(result)
15
+
16
+
17
+ def map_dtype_to_oracle(self, dtype):
18
+ msg = result = None, None
19
+ try:
20
+ if pd.api.types.is_integer_dtype(dtype):
21
+ result = "NUMBER"
22
+ elif pd.api.types.is_float_dtype(dtype):
23
+ result = "FLOAT"
24
+ elif pd.api.types.is_bool_dtype(dtype):
25
+ result = "CHAR(1)" # True = 'Y', False = 'N'
26
+ elif pd.api.types.is_string_dtype(dtype):
27
+ result = "VARCHAR2(255)"
28
+ elif pd.api.types.is_datetime64_any_dtype(dtype):
29
+ result = "DATE"
30
+ else:
31
+ result = "VARCHAR2(4000)"
32
+ result = "VARCHAR2(4000)"
33
+ except Exception as error:
34
+ msg = error
35
+ result = msg
36
+ finally:
37
+ return result
38
+
39
+ def generate_create_table_sql(self, table_name, df):
40
+ msg = result = None, None
41
+ try:
42
+ columns = []
43
+ for col in df.columns:
44
+ colname = col.lower()
45
+ oracle_type = self.map_dtype_to_oracle(df[col].dtype)
46
+ columns.append(f"{colname} {oracle_type}")
47
+ columns_sql = ",\n ".join(columns)
48
+ result = f"CREATE TABLE {table_name} (\n {columns_sql}\n)"
49
+ except Exception as error:
50
+ msg = error
51
+ result = msg
52
+ finally:
53
+ return result
54
+
55
+ def prepare_data_for_insert(self, df):
56
+ msg = result = None, None
57
+ try:
58
+ def convert_row(row):
59
+ return tuple(
60
+ 'Y' if isinstance(val, bool) and val else 'N' if isinstance(val, bool) else val for val in row)
61
+ result = [convert_row(row) for row in df.itertuples(index=False, name=None)]
62
+ except Exception as error:
63
+ msg = error
64
+ result = msg
65
+ finally:
66
+ return result
67
+
68
+ def create_table_and_insert_data(self, df, table_name, conn):
69
+ msg = result = None, None
70
+ try:
71
+ cur = conn.cursor()
72
+ try:
73
+ create_sql = self.generate_create_table_sql(table_name, df)
74
+ cur.execute(create_sql)
75
+ except:
76
+ pass #cur.execute(f"DROP TABLE {table_name}")
77
+
78
+ placeholders = ', '.join([f":{i+1}" for i in range(len(df.columns))])
79
+ insert_sql = f"INSERT INTO {table_name} VALUES({placeholders})"
80
+ data = self.prepare_data_for_insert(df)
81
+ cur.executemany(insert_sql, data)
82
+ conn.commit()
83
+ cur.close()
84
+ conn.close()
85
+
86
+ except Exception as error:
87
+ msg = error
88
+ result = msg
89
+ finally:
90
+ return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DE_Lib
3
- Version: 0.0.35.4
3
+ Version: 0.0.36.1
4
4
  Summary: Biblioteca de funcionalidades
5
5
  Home-page: https://github.com/DE-DATAx/DAX_DB.git
6
6
  Author: Almir J Gomes
@@ -8,6 +8,7 @@ DE_Lib/DataBase/Metadata.py,sha256=j0iJm26Sf0QvsYpN61hfwkllyW2EOA2XoFnSzEo9plE,3
8
8
  DE_Lib/DataBase/MsSql.py,sha256=tVx7fdFkw1ZNhfjqw-KuyHtT-hqJ9ZNCR2iU_ogSUVk,1640
9
9
  DE_Lib/DataBase/MySql.py,sha256=SWLJMaB30EBqaz32xwMBbc3lnemDPpF2kkkf5umlL3k,2534
10
10
  DE_Lib/DataBase/Oracle.py,sha256=n9ub6J6zNX4z62pUWjut3PGxXzLDZQ9jVhZ6eGzFPEw,9704
11
+ DE_Lib/DataBase/OracleDDL.py,sha256=5uGtaQ_r-GSfO6Vk9YRBs-7tq_myavxHm9ee7-tG1tY,3074
11
12
  DE_Lib/DataBase/Postgres.py,sha256=lMb6sFGvjjuuq4D4k7zzEo7-NtyrC79VITeKQfoDO6U,1667
12
13
  DE_Lib/DataBase/RedShift.py,sha256=ewPi8hxEhfuekBpMl-P1LWgSGfbqPKRpXfjtduCwOKc,1736
13
14
  DE_Lib/DataBase/SQCipher.py,sha256=Bw7nq4tQdhM7ux0INF9PUymsIIjBEwMKcA1Un8orCE8,1625
@@ -41,8 +42,8 @@ DE_Lib/Utils/Cipher/Gcm.py,sha256=fOuCVOyd4sGv389E91yqomujKTtFZu6CyhySrmQKVfY,23
41
42
  DE_Lib/Utils/Cipher/Pbkdf2.py,sha256=hRkgf0Fo5hV1gLbWlFGFzhYYUjPEqgpB2R-pPw7N2F8,1210
42
43
  DE_Lib/Utils/Cipher/Rsa.py,sha256=MYG1YsGuq-Q-MoF6pmeMD0TyxMTwt6tuUaLvXcmzQ2k,4126
43
44
  DE_Lib/Utils/Cipher/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
- de_lib-0.0.35.4.dist-info/licenses/LICENCE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
45
- de_lib-0.0.35.4.dist-info/METADATA,sha256=FXd5735n31A3fNNtKzJ3M_DimHs6Bt8VIfkxhatzs98,2289
46
- de_lib-0.0.35.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
47
- de_lib-0.0.35.4.dist-info/top_level.txt,sha256=yI9fdM_jkhCz_sykPZQbfeUbQ1FRMt-xjv9fJ6YZVLE,7
48
- de_lib-0.0.35.4.dist-info/RECORD,,
45
+ de_lib-0.0.36.1.dist-info/licenses/LICENCE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
46
+ de_lib-0.0.36.1.dist-info/METADATA,sha256=S0gd_5_jostVHyEYtv5aKlp0whjM9x9g8IApFXtBw9k,2289
47
+ de_lib-0.0.36.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
48
+ de_lib-0.0.36.1.dist-info/top_level.txt,sha256=yI9fdM_jkhCz_sykPZQbfeUbQ1FRMt-xjv9fJ6YZVLE,7
49
+ de_lib-0.0.36.1.dist-info/RECORD,,