pam-python 0.1.18__tar.gz → 0.1.19__tar.gz
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.
- {pam_python-0.1.18/pam_python.egg-info → pam_python-0.1.19}/PKG-INFO +1 -1
- pam_python-0.1.19/pam/sqlite.py +75 -0
- {pam_python-0.1.18 → pam_python-0.1.19/pam_python.egg-info}/PKG-INFO +1 -1
- {pam_python-0.1.18 → pam_python-0.1.19}/pam_python.egg-info/SOURCES.txt +1 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/setup.py +1 -1
- {pam_python-0.1.18 → pam_python-0.1.19}/LICENSE.txt +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/README.md +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/__init__.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/api.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/cli.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/interface_task_manager.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/models/__init__.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/models/request_command.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/server.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/service.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/task_manager.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/temp_file_utils.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/buildcmd/pamb +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/buildcmd/pamb-base.sh +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/docker/Dockerfile +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/init/dockerignore.tmpl +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/init/gitignore.tmpl +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/init/main.tmpl +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/init/pylintrc.tmpl +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/init/run_test.sh +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/service/functions.tmpl +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/service/service.test.tmpl +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/service/service.yaml +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/templates/service/service_class.tmpl +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/tester_task.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam/utils.py +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam_python.egg-info/dependency_links.txt +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam_python.egg-info/entry_points.txt +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam_python.egg-info/requires.txt +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/pam_python.egg-info/top_level.txt +0 -0
- {pam_python-0.1.18 → pam_python-0.1.19}/setup.cfg +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import sqlite3
|
|
2
|
+
from pam.utils import log
|
|
3
|
+
from typing import Any, List, Optional, Tuple, Union
|
|
4
|
+
|
|
5
|
+
class SQLiteDB:
|
|
6
|
+
def __init__(self, db_path: str, row_as_dict: bool = False, timeout=30):
|
|
7
|
+
"""
|
|
8
|
+
Initialize the SQLiteDB wrapper.
|
|
9
|
+
|
|
10
|
+
:param db_path: Path to the SQLite database file.
|
|
11
|
+
:param row_as_dict: If True, fetches rows as dictionaries.
|
|
12
|
+
"""
|
|
13
|
+
self.db_path = db_path
|
|
14
|
+
self.row_as_dict = row_as_dict
|
|
15
|
+
self.timeout = timeout
|
|
16
|
+
self.conn = sqlite3.connect(db_path, timeout)
|
|
17
|
+
if row_as_dict:
|
|
18
|
+
self.conn.row_factory = sqlite3.Row
|
|
19
|
+
|
|
20
|
+
def __enter__(self):
|
|
21
|
+
return self
|
|
22
|
+
|
|
23
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
24
|
+
self.close()
|
|
25
|
+
|
|
26
|
+
def execute(self, query: str, params: Optional[Tuple[Any, ...]] = None) -> None:
|
|
27
|
+
"""Execute a write query (INSERT/UPDATE/DELETE)."""
|
|
28
|
+
try:
|
|
29
|
+
with self.conn:
|
|
30
|
+
self.conn.execute(query, params or ())
|
|
31
|
+
except sqlite3.Error as e:
|
|
32
|
+
log(f"SQLite execute error: {e}")
|
|
33
|
+
raise
|
|
34
|
+
|
|
35
|
+
def executemany(self, query: str, data: List[Tuple[Any, ...]]) -> None:
|
|
36
|
+
"""Execute a batch write query."""
|
|
37
|
+
try:
|
|
38
|
+
with self.conn:
|
|
39
|
+
self.conn.executemany(query, data)
|
|
40
|
+
except sqlite3.Error as e:
|
|
41
|
+
log(f"SQLite executemany error: {e}")
|
|
42
|
+
raise
|
|
43
|
+
|
|
44
|
+
def fetchall(self, query: str, params: Optional[Tuple[Any, ...]] = None) -> List[Union[Tuple, dict]]:
|
|
45
|
+
"""Fetch all results from a SELECT query."""
|
|
46
|
+
try:
|
|
47
|
+
cursor = self.conn.execute(query, params or ())
|
|
48
|
+
return cursor.fetchall()
|
|
49
|
+
except sqlite3.Error as e:
|
|
50
|
+
log(f"SQLite fetchall error: {e}")
|
|
51
|
+
raise
|
|
52
|
+
|
|
53
|
+
def fetchone(self, query: str, params: Optional[Tuple[Any, ...]] = None) -> Optional[Union[Tuple, dict]]:
|
|
54
|
+
"""Fetch the first result from a SELECT query."""
|
|
55
|
+
try:
|
|
56
|
+
cursor = self.conn.execute(query, params or ())
|
|
57
|
+
return cursor.fetchone()
|
|
58
|
+
except sqlite3.Error as e:
|
|
59
|
+
log(f"SQLite fetchone error: {e}")
|
|
60
|
+
raise
|
|
61
|
+
|
|
62
|
+
def create_table(self, create_sql: str) -> None:
|
|
63
|
+
"""Create a table from a SQL string."""
|
|
64
|
+
try:
|
|
65
|
+
with self.conn:
|
|
66
|
+
self.conn.execute(create_sql)
|
|
67
|
+
except sqlite3.Error as e:
|
|
68
|
+
log(f"SQLite create_table error: {e}")
|
|
69
|
+
raise
|
|
70
|
+
|
|
71
|
+
def close(self) -> None:
|
|
72
|
+
"""Close the connection."""
|
|
73
|
+
if self.conn:
|
|
74
|
+
self.conn.close()
|
|
75
|
+
log("SQLite connection closed.")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|