DE-Lib 0.0.35.4__py3-none-any.whl → 0.0.36__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,89 @@
1
+ import pandas as pd
2
+
3
+ class OracleDDL:
4
+ def __init__(self):
5
+ msg = result = None, None
6
+ try:
7
+ ...
8
+ except Exception as error:
9
+ msg = error
10
+ result = msg
11
+ finally:
12
+ print(result)
13
+
14
+
15
+ def map_dtype_to_oracle(self, dtype):
16
+ msg = result = None, None
17
+ try:
18
+ if pd.api.types.is_integer_dtype(dtype):
19
+ result = "NUMBER"
20
+ elif pd.api.types.is_float_dtype(dtype):
21
+ result = "FLOAT"
22
+ elif pd.api.types.is_bool_dtype(dtype):
23
+ result = "CHAR(1)" # True = 'Y', False = 'N'
24
+ elif pd.api.types.is_string_dtype(dtype):
25
+ result = "VARCHAR2(255)"
26
+ elif pd.api.types.is_datetime64_any_dtype(dtype):
27
+ result = "DATE"
28
+ else:
29
+ result = "VARCHAR2(4000)"
30
+ except Exception as error:
31
+ msg = error
32
+ result = msg
33
+ finally:
34
+ return result
35
+
36
+ def generate_create_table_sql(self, table_name, df):
37
+ msg = result = None, None
38
+ try:
39
+ columns = []
40
+ for col in df.columns:
41
+ colname = col.lower()
42
+ oracle_type = self.map_dtype_to_oracle(df[col].dtype)
43
+ columns.append(f"{colname} {oracle_type}")
44
+ columns_sql = ",\n ".join(columns)
45
+ result = f"CREATE TABLE {table_name} (\n {columns_sql}\n)"
46
+ except Exception as error:
47
+ msg = error
48
+ result = msg
49
+ finally:
50
+ return result
51
+
52
+ def prepare_data_for_insert(self, df):
53
+ msg = result = None, None
54
+ try:
55
+ def convert_row(row):
56
+ return tuple(
57
+ 'Y' if isinstance(val, bool) and val else 'N' if isinstance(val, bool) else val for val in row)
58
+ result = [convert_row(row) for row in df.itertuples(index=False, name=None)]
59
+ except Exception as error:
60
+ msg = error
61
+ result = msg
62
+ finally:
63
+ return result
64
+
65
+ def create_table_and_insert_data(self, df, table_name, conn):
66
+ msg = result = None, None
67
+ try:
68
+ cur = conn.cursor()
69
+ try:
70
+ cur.execute(f"DROP TABLE {table_name}")
71
+ except:
72
+ pass # Ignora se a tabela não existir
73
+
74
+ create_sql = self.generate_create_table_sql(table_name, df)
75
+ cur.execute(create_sql)
76
+
77
+ placeholders = ', '.join([f":{i+1}" for i in range(len(df.columns))])
78
+ insert_sql = f"INSERT INTO {table_name} VALUES({placeholders})"
79
+ data = self.prepare_data_for_insert(df)
80
+ cur.executemany(insert_sql, data)
81
+ conn.commit()
82
+ cur.close()
83
+ conn.close()
84
+
85
+ except Exception as error:
86
+ msg = error
87
+ result = msg
88
+ finally:
89
+ 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
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=-GyxHOVPBkHJI3mqEura1sG__bW1JdYMFQpw-2HEzWE,3046
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.dist-info/licenses/LICENCE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
46
+ de_lib-0.0.36.dist-info/METADATA,sha256=vkfoyshVo506OImbauRZ8ugi83zZwdoIpm3wOBZf-SA,2287
47
+ de_lib-0.0.36.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
48
+ de_lib-0.0.36.dist-info/top_level.txt,sha256=yI9fdM_jkhCz_sykPZQbfeUbQ1FRMt-xjv9fJ6YZVLE,7
49
+ de_lib-0.0.36.dist-info/RECORD,,