commons-metrics 0.0.5__py3-none-any.whl → 0.0.7__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.
- commons_metrics/__init__.py +3 -2
- commons_metrics/repositories.py +82 -0
- {commons_metrics-0.0.5.dist-info → commons_metrics-0.0.7.dist-info}/METADATA +1 -1
- commons_metrics-0.0.7.dist-info/RECORD +9 -0
- commons_metrics/data_base.py +0 -45
- commons_metrics-0.0.5.dist-info/RECORD +0 -9
- {commons_metrics-0.0.5.dist-info → commons_metrics-0.0.7.dist-info}/WHEEL +0 -0
- {commons_metrics-0.0.5.dist-info → commons_metrics-0.0.7.dist-info}/licenses/LICENSE +0 -0
- {commons_metrics-0.0.5.dist-info → commons_metrics-0.0.7.dist-info}/top_level.txt +0 -0
commons_metrics/__init__.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from .util import Util
|
|
2
2
|
from .database import DatabaseConnection
|
|
3
|
+
from .repositories import ComponentRepository
|
|
3
4
|
|
|
4
|
-
__all__ = ['Util', 'DatabaseConnection']
|
|
5
|
-
__version__ = '0.0.
|
|
5
|
+
__all__ = ['Util', 'DatabaseConnection', 'ComponentRepository']
|
|
6
|
+
__version__ = '0.0.7'
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
class ComponentRepository:
|
|
2
|
+
"""
|
|
3
|
+
Repository class for component-specific database operations
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
def __init__(self, db_connection):
|
|
7
|
+
"""
|
|
8
|
+
Initialize repository with database connection
|
|
9
|
+
"""
|
|
10
|
+
self.db = db_connection
|
|
11
|
+
|
|
12
|
+
def save_component(self, technical_name, id_type, status):
|
|
13
|
+
"""
|
|
14
|
+
Inserts a new component into schmesys.component table
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
technical_name (str): Technical name of the component
|
|
18
|
+
id_type (int): Component type ID
|
|
19
|
+
status (int): Component status
|
|
20
|
+
"""
|
|
21
|
+
cursor = None
|
|
22
|
+
try:
|
|
23
|
+
cursor = self.db.connection.cursor()
|
|
24
|
+
|
|
25
|
+
insert_query = """
|
|
26
|
+
INSERT INTO schmesys.component(technical_name, id_type, status)
|
|
27
|
+
VALUES (%s, %s, %s)
|
|
28
|
+
RETURNING id;
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
cursor.execute(insert_query, (technical_name, id_type, status))
|
|
32
|
+
component_id = cursor.fetchone()[0]
|
|
33
|
+
self.db.commit_transaction()
|
|
34
|
+
|
|
35
|
+
return component_id
|
|
36
|
+
|
|
37
|
+
except Exception as e:
|
|
38
|
+
self.db.rollback_transaction()
|
|
39
|
+
raise Exception(f"Error saving component '{technical_name}': {str(e)}")
|
|
40
|
+
finally:
|
|
41
|
+
if cursor:
|
|
42
|
+
cursor.close()
|
|
43
|
+
|
|
44
|
+
def query_components_by_type(self, id_type: int) -> list:
|
|
45
|
+
"""
|
|
46
|
+
Consulta componentes de un tipo específico en la base de datos
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
id_type (int): ID del tipo de componente a consultar
|
|
50
|
+
"""
|
|
51
|
+
cursor = None
|
|
52
|
+
try:
|
|
53
|
+
cursor = self.db.connection.cursor()
|
|
54
|
+
|
|
55
|
+
query = """
|
|
56
|
+
SELECT id, technical_name, id_type, status
|
|
57
|
+
FROM schmesys.component
|
|
58
|
+
WHERE id_type = %s
|
|
59
|
+
ORDER BY technical_name
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
cursor.execute(query, (id_type,))
|
|
63
|
+
results = cursor.fetchall()
|
|
64
|
+
|
|
65
|
+
components = []
|
|
66
|
+
for row in results:
|
|
67
|
+
component = {
|
|
68
|
+
'id': row[0],
|
|
69
|
+
'technical_name': row[1],
|
|
70
|
+
'id_type': row[2],
|
|
71
|
+
'status': row[3]
|
|
72
|
+
}
|
|
73
|
+
components.append(component)
|
|
74
|
+
|
|
75
|
+
return components
|
|
76
|
+
|
|
77
|
+
except Exception as e:
|
|
78
|
+
raise Exception(f"Error querying components by type {id_type}: {str(e)}")
|
|
79
|
+
finally:
|
|
80
|
+
if cursor:
|
|
81
|
+
cursor.close()
|
|
82
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
commons_metrics/__init__.py,sha256=elSwj8Oszh-JG6ZSZD0_GLgw0DJRjjBpsFUgsJNcLIM,196
|
|
2
|
+
commons_metrics/database.py,sha256=570TtLZ9psNzvIp75UFLYph34cKVEz6eGJgxXyRyjW4,1285
|
|
3
|
+
commons_metrics/repositories.py,sha256=GtAsVMbcfyftKQlMhyxLqxwVi3B7EwbopmHafZgxxJE,2559
|
|
4
|
+
commons_metrics/util.py,sha256=98zuynalXumQRh-BB0Bcjyoh6vS2BTOUM8tVgr7iS9Q,1225
|
|
5
|
+
commons_metrics-0.0.7.dist-info/licenses/LICENSE,sha256=jsHZ2Sh1wCL74HC25pDDGXCyQ0xgsTAy62FvEnehKIg,1067
|
|
6
|
+
commons_metrics-0.0.7.dist-info/METADATA,sha256=Vq78qEafWd7_XZUvuJEPV5OEq-e4dSrTPCu4u8nguMo,401
|
|
7
|
+
commons_metrics-0.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
commons_metrics-0.0.7.dist-info/top_level.txt,sha256=lheUN-3OKdU3A8Tg8Y-1IEB_9i_vVRA0g_FOiUsTQz8,16
|
|
9
|
+
commons_metrics-0.0.7.dist-info/RECORD,,
|
commons_metrics/data_base.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import psycopg2
|
|
2
|
-
|
|
3
|
-
class DataBase:
|
|
4
|
-
def __init__(self, db_name):
|
|
5
|
-
self.connection = None
|
|
6
|
-
|
|
7
|
-
def connect(self, host, port, dbname, user, password):
|
|
8
|
-
try:
|
|
9
|
-
self.connection = psycopg2.connect(
|
|
10
|
-
host=host,
|
|
11
|
-
port=port,
|
|
12
|
-
database=dbname,
|
|
13
|
-
user=user,
|
|
14
|
-
password=password,
|
|
15
|
-
connect_timeout=30
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
except Exception as e:
|
|
19
|
-
if self.connection:
|
|
20
|
-
self.connection.rollback()
|
|
21
|
-
msg = f"Database connection error: {str(e)}"
|
|
22
|
-
raise Exception(msg)
|
|
23
|
-
|
|
24
|
-
def disconnect(self):
|
|
25
|
-
if self.connectWWWion:
|
|
26
|
-
self.connection.close()
|
|
27
|
-
|
|
28
|
-
def save_component(technical_name, id_type):
|
|
29
|
-
try:
|
|
30
|
-
cursor = connection.cursor()
|
|
31
|
-
params_insert = (
|
|
32
|
-
technical_name,
|
|
33
|
-
id_type
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
#cursor.execute("select id_component into v_id_component from schmesys.component where technical_name = v_component_name;", params)
|
|
37
|
-
cursor.execute("INSERT INTO schmesys.component(technical_name,id_type) values (%s, %d);", params_insert)
|
|
38
|
-
except Exception as e:
|
|
39
|
-
if self.connection:
|
|
40
|
-
self.connection.rollback()
|
|
41
|
-
msg = f"Database connection error: {str(e)}"
|
|
42
|
-
raise Exception(msg)
|
|
43
|
-
finally:
|
|
44
|
-
if cursor:
|
|
45
|
-
cursor.close()
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
commons_metrics/__init__.py,sha256=vbEyX-oQv35rlSa0zSi-4CacNpyoCqxsedHAzDKQtwU,127
|
|
2
|
-
commons_metrics/data_base.py,sha256=7I9ywLqQMtTlK1uuubM8WrffwDsL9uyP3sygqanUQvQ,1439
|
|
3
|
-
commons_metrics/database.py,sha256=570TtLZ9psNzvIp75UFLYph34cKVEz6eGJgxXyRyjW4,1285
|
|
4
|
-
commons_metrics/util.py,sha256=98zuynalXumQRh-BB0Bcjyoh6vS2BTOUM8tVgr7iS9Q,1225
|
|
5
|
-
commons_metrics-0.0.5.dist-info/licenses/LICENSE,sha256=jsHZ2Sh1wCL74HC25pDDGXCyQ0xgsTAy62FvEnehKIg,1067
|
|
6
|
-
commons_metrics-0.0.5.dist-info/METADATA,sha256=6xfET92d3JXR9fRdIE5gGJZ2D2tRKxzYVo4CHcC-XvU,401
|
|
7
|
-
commons_metrics-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
commons_metrics-0.0.5.dist-info/top_level.txt,sha256=lheUN-3OKdU3A8Tg8Y-1IEB_9i_vVRA0g_FOiUsTQz8,16
|
|
9
|
-
commons_metrics-0.0.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|